Announcement

Collapse
No announcement yet.

php calculation with qty dependant pricing

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

    php calculation with qty dependant pricing

    We have a little bit of php which calculation the cost per 100g for each sweet that we sell, mostly with a little help from Norman I might add.

    here id the originasl code


    (<actinic:block php="true" >
    $units = '<actinic:variable encoding="perl" name="CUST_UNITS_PER_OUTER" selectable="false" />'; // load as string in case variable empty
    if ( $units != '' )
    {
    $cost = '<actinic:variable encoding="perl" name="ProductPriceRaw" selectable="false" />'; // load as string in case variable empty
    $cost = preg_replace('/£|,/', '', $cost); // remove any £ and ,
    $costinc = $cost * 1.175 ;
    $unitcost = ($cost / $units) * 100; // do the arithmetic
    printf(' %.1fp', $unitcost);
    }
    </actinic:block> per <actinic:variable name="Per_unit" /> )
    This works perfectly but now we want to offer discounts when you buy over a certain number of each item, but I want to now show the cost per 100g for each price point.

    I put the code into standard tax exclusive price and the code works but always brings up the price for the non discounted price band.

    I tried replaceing

    <actinic:variable encoding="perl" name="ProductPriceRaw" selectable="false" />

    with

    <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" />

    but all I get is coding errors
    David Mawson
    Phoenix Trading

    http://www.sweetswholesale.co.uk - Wholesale confectionery suppliers

    #2
    This has had me going round the bend all afternoon! Not least because the results don't show up correctly in the design preview - you have to generate the pages to view! Only found out by accident,

    Code:
    <actinic:block if="%3cactinic%3avariable%20name%3d%22ContentCategory%22%20%2f%3e%20%3d%3d%20%22RRP%22%20AND%20%28%3cactinic%3avariable%20name%3d%22RRPrice%22%20%2f%3e%20%3e0%29" >
    		&nbsp;&nbsp;RRP: £<actinic:variable name="RRPrice" />
    			
    <actinic:block php="true" > 
    $rrp = <actinic:variable name="RRPrice" selectable="false" />;
    if ($rrp=="") $rrp = 0;
    $qprice = "<actinic:variable name="TaxExclusivePrice" />";
    $qprice = preg_replace('/£|,|/','',"<actinic:variable name="TaxExclusivePrice" />");
    $qprice = $qprice + 0 ;
    $save = $rrp - $qprice;
    echo "&nbsp;You Save: £$save";
    			
    </actinic:block>
    </actinic:block>
    Next up, test for qty pricing in operation or not and use TaxExclusivePrice/ ProductPriceRaw as appropriate..

    <later>
    Code:
    			
    <actinic:block php="true" > 
    $rrp = <actinic:variable name="RRPrice" selectable="false" />;
    if ($rrp=="") $rrp = 0;
    $qprice = "<actinic:variable name="ProductPriceRaw" />";
    if ("<actinic:variable name="QuantityDescMax" />" != 0) 
    	{$qprice = "<actinic:variable name="TaxExclusivePrice" />";
    	$qprice = preg_replace('/£|,|/','',$qprice);
    	}
    $qprice = $qprice + 0 ;
    $save = $rrp - $qprice;
    if ($save > 0) echo "&nbsp;You Save: £$save";
    			
    </actinic:block>
    that seems to work...

    Comment

    Working...
    X