Announcement

Collapse
No announcement yet.

Math with variables

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

    #46
    Actinic needs a value entered for the price as it's used elsewhere than just on the web page.

    The usual approach to do what you want is use a spreadsheet to calculate the product prices, discounts, etc. Then you 'import' these into Actinic.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #47
      I Used the below code

      <actinic:block php="true">
      $rrp = <actinic:variable name="ProductRRP" selectable="false" />;
      $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
      $amountsaved = round($rrp - $rawprice);
      $savepercent = round((($rrp - $rawprice) / $rrp) * 100);

      // only display is we have an RRP and there's a saving to show
      if ( ($rrp != 0) && ($rrp > $rawprice) && ($amountsaved > 24))
      {
      echo "Save: £$amountsaved";
      }

      if ($amountsaved <= 24)
      {
      echo " Save: $savepercent%";
      }
      </actinic:block>

      and I got over 3k coding errors, I have removed it now and the errors have gone.

      Any idea's???????????



      Neil

      Comment


        #48
        Where did you put it? 3000 errors is good sign, that's just telling you that you have 3000 instances (products) of it that are failing.

        Comment


          #49
          Neil, did you create a Variable "ProductRRP" and make it of type Number?

          Also you'll get divide by zero errors if ProductRRP is zero.

          Try changing to:
          Code:
          <actinic:block php="true">
          	$rrp = '<actinic:variable name="ProductRRP" selectable="false" />';
          	if ( $rrp )	// only display if we have an RRP
          		{
          		$rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
          		if ($rrp > $rawprice)	// only if there's a saving to show
          			{
          			$amountsaved = round($rrp - $rawprice);
          			$savepercent = round((($rrp - $rawprice) / $rrp) * 100);
          
          			if ($amountsaved > 24)
          				{
          				echo "Save: £$amountsaved";
          				}
          
          			if ($amountsaved <= 24)
          				{
          				echo " Save: $savepercent%";
          				}
          			}	
          		}
          </actinic:block>
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #50
            Also, if you use Duplicates, then you'd better read http://community.actinic.com/showthread.php?t=48156 as ProductPriceRaw in Duplicates doesn't update when you change the main product price. Post #11 there shows a workaround.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #51
              The strange thing is that the coding works on my site!?
              www.gparts.co.uk

              RRP is set as text because if I change it to number it rounds up to the nearest pound.

              Comment


                #52
                The code you originally posted will require you to have a valid, non-zero ProductRRP set on every product.

                As for variables of type Number, there is an option "Whole Numbers Only" that needs to be unchecked if you wish to use real numbers.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment

                Working...
                X