Announcement

Collapse
No announcement yet.

Running a calculation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Running a calculation

    Hi All,

    On a site we are doing we have added a new variable called RecommendedRetailPrice to a Products details.

    What we would like to do is run a calculation based on this variable and the Price of the product.

    So, we could show the RRP, then a "Save £xxx" then "Our Price £xxx".

    So, we have put in a block if asking if the RecommendedRetailPrice is >0
    If it is then display the RRP followed by the RRP minus the Price

    Question is, can I build the calculation using blocks? Or should I be using php, along the lines of...

    Code:
    <p>RRP: £<actinic:variable name="RecommendedRetailPrice" /></p>
    			<p>SAVE £<actinic:block php="true">
    			$rrp = intval(<actinic:variable name="RecommendedRetailPrice" selectable="false" />);
    			$price = intval(<actinic:variable name="Price" selectable="false" />);
    			$saving = $rrp-$price;
    	  echo $saving;
    	</actinic:block>		
    </p>
    The code above gives a parse error in the preview window, but this is probably because it is not running on a server to run the php. I can upload it at the moment to test, as uploading another site at the moment.

    What would be your thoughts? The php should run OK - or better to do thi9s with a calculation in a block or condition etc?

    #2
    Actinic PHP blocks should work in Preview. They run on your PC when the page is being built.

    Variable Price will cause 2 problems.

    1) It's only for use in the Cart.

    2) It returns a string like £1,234.56 so isn't a number you can do maths with.

    Use:
    Code:
    	$price = intval( <actinic:variable name="ProductPriceRaw" selectable="false" /> );
    There are also many prior posts on displaying an RRP and Saving. It may be worth checking these as your existing logic could display negative savings if RRP is non zero but is less than the product price.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thank you Norman - worked a treat , and apologies for yet another RRP Saving thread to add to the mix.

      Comment


        #4
        Updated my post to point out some logic tweaks that you might need to do.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Basically, put everything inside the PHP block and only echo out the entire

          <p>RRP: £<actinic:variable name="RecommendedRetailPrice" /></p><p>SAVE £

          stuff if the RRP is set and there is a saving.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Or use a BlockIf like (pseudo code):
            Code:
            ( intval(RRP) > 0) AND (intval(RRP) > intval(ProductPriceRaw) )
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment

            Working...
            X