We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24007
    • 38 Posts
    Hi there,

    I have a site sitting on ModX Evolution 1.04 - Apache/Linux Server.

    My question relates to help on how to implement a snippet that will change a TV entry due to a sales tax rate change.

    I have a chunk called {{priceLink}}

    Here is the code in {{priceLink}}
    <div class="pricelink">
    <p>[*quantity*]</p>
    <p>£ [*price*] inc VAT</p>
    <p><a title="[*linktitle*]" href="http://some-site.com/index.php?=blahblahblah/itemCode=[*productcode*]">Buy This</a></p>
    </div>
    


    The TV that I want to manipulate here is of course [*price*]

    I have a snippet that may need some alteration but here’s what I have anyways - the snippet is called [[taxRate]]

    <?php
    $output = '';
    $newVat = 120;
    $oldVat = 117.5;
    
    if (!empty($input) && is_numeric($input) && !empty($options) && is_numeric($options)) { 
    	/* Uses is_numeric function to avoid integer, float issue. Multiply & round the Float to 2 Digits */
    
            $output = $input / $oldVat;
            $output = $output * $newVat;
    	$output = round($output * $options, 2);
    }
    else
    	$output = $input;
    
    return $output;
    ?>
    


    In the page resource where I want my chunk to appear I naturally use {{priceLink}}

    I have tried to edit the chunk see below
    // code as previous
    <p>£ [[*price:taxRate=`1`]] inc VAT</p>
    // code as previous
    </div>
    
    


    Can’t get this to work, need some help someone.

    Many thanks

      • 4310
      • 2,310 Posts
      You seem to be using Revolution tags for
      [[*price:taxRate=`1`]] 

      Wouldn’t it be better to change the values in the database rather than manipulating them every time they are loaded front/back end?
        • 4310
        • 2,310 Posts
        I need to stop getting sidetracked on interesting problems wink
        Just tried this from PHPMyAdmin :
        UPDATE `modx_site_tmplvar_contentvalues` SET value = CAST(((value / 1.175) * 1.20) AS  DECIMAL(15,2)) WHERE `tmplvarid` = 6 
        

        You’d need to identify the id of your ’price’ TV and set it where I have tmplvarid` = 6
        Tested on a few entries and it converted 117.50 to 120.00 okay.
        Backup the DB or that DB table first though.
          • 24007
          • 38 Posts
          Yes this is a better way of achieving the desired result as it is done at the database level, rather than a script having to process each time a new page loads.

          Definitely the most logical method.

          Many thanks for your well cased assistance

          Psypha cool