Announcement

Collapse
No announcement yet.

Php - Performing A Calculation In Actinic

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

    Php - Performing A Calculation In Actinic

    I know that in v8 you can now use php when generating a page

    IS it possible to use php to do a calculation with a custom variable that I have created ?

    For example

    I have created a custom variable
    <actinic:variable name="CUST_UNITS_PER_OUTER" />
    Which is the number of units per product

    For each product I want actinic (when generating the site) to divide the retail price by the number of units in the product.

    i.e

    sales price = £10
    Number units = 5

    Cost per unit = £2
    David Mawson
    Phoenix Trading

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

    #2
    Something like
    Code:
    <actinic:block php="true">
    $units = '<actinic:variable name="CUST_UNITS_PER_OUTER" encoding="perl" selectable="false" />';	// load as string in case variable empty
    if ( $units != '' ) 
      {
      $cost = '<actinic:variable name="TaxInclusivePrice" encoding="perl" selectable="false" />';	// load as string in case variable empty
      $cost = preg_replace('/£|,/', '', $cost);					// remove any £ and ,
      $unitcost = $cost / $units;							// do the arithmetic
      printf(' Unit Cost £%.2f', $unitcost);
     }
    </actinic:block>
    You may need to change TaxInclusivePrice to TaxExclusivePrice, depending on your setup.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thanks for the quick reply Norman

      Your solution just returns a value of £0.00

      tried changing to tax inc & tax ex but same result.

      I am using no tax in my pricing if this helps

      I also tried just to diplay the values of

      <Actinic:Variable Name="TaxExclusivePrice"/>
      <actinic:variable name="TaxExclusivePriceAlt" />
      <actinic:variable name="TaxExclusivePrice" />

      But they all display nothing .... where am I going wrong
      David Mawson
      Phoenix Trading

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

      Comment


        #4
        update:

        I changed the variable to

        actinic:variable name="ProductPriceRaw"

        and it works great - thanks

        Am I right in thinking that I would not be able to do the same function but instead of the standard retail price I want to use customer specific pricing

        I only use 1 pricing group for the trade account holders called "trade"
        David Mawson
        Phoenix Trading

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

        Comment


          #5
          It works for me. You have to put it in the correct place. I tested my code within the Layout: Product Price Including Tax.

          You can add echo statements to the code to output some diagnostic info.

          E.g.

          echo 'XXX' . $cost . 'XXX';

          then search the source of the generated page for XXX to see what was generated.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            If you use ProductPriceRaw you won't need the line

            $cost = preg_replace('/£|,/', '', $cost); // remove any £ and ,

            As to trade pricing. This is generated at run-time by Perl scripts. You won't have access to these at page generation time with PHP. You'd need to use a client-side JavaScript system in that case.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Originally posted by NormanRouxel
              As to trade pricing. This is generated at run-time by Perl scripts. You won't have access to these at page generation time with PHP. You'd need to use a client-side JavaScript system in that case.
              Thanks for the info norman

              How do I use a client-side JavaScript system ???
              David Mawson
              Phoenix Trading

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

              Comment

              Working...
              X