Announcement

Collapse
No announcement yet.

Weight Conversion

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

    Weight Conversion

    Hi All,

    Hopefully quite a simple question here:

    Are there any mathematical functions available in Actinic (Business V8)?

    I'm trying to display the shipping weight in the product description, but would like values under 1kg to display as xx g rather than 0.xx kg, so I need to multiply the value by 1000.

    I have the following code done already:

    Code:
    						
    
    <actinic:block if="%3cactinic%3avariable%20name%3d%22ShippingWeight%22%20%2f%3e%20%20%3c%201">
    							
     g
    </actinic:block>
    						
    <actinic:block if="%3cactinic%3avariable%20name%3d%22ShippingWeight%22%20%2f%3e%20%20%3e%3d%201">					
    <actinic:variable name="ShippingWeight" /> kg
    </actinic:block>
    Basically testing for >=1 or <1 and adding the correct suffix. But I need to return ShippingWeight*1000 before the 'g'. Will I need a wee javascript code to do this?

    This may seem like a tiny detail, but thinking longer term I'd like to develop a similar routine to convert back to imperial measurements as quite a lot of customers still ask for this.

    Thanks in advance,

    Murray
    Murray MacPherson
    www.wellhungandtender.com

    #2
    Actinic V8 has the entire PHP (version 4.3.10) built-in. You can start and end lumps of PHP code like this (untested)

    Code:
    <actinic:block php="true">
    $weight = '<actinic:variable name="ShippingWeight" encoding="perl" selectable="false" />';
    if ($weight == '') $weight = 0;
    if ($weight < 1)
      {
      echo ($weight * 1000) . 'gm';
      }
    else
      {
      echo $weight . 'Kg';
      }
    </actinic:block>
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Norman, you're a legend - just opened up a whole new world of possibilities!

      Many thanks,

      Murray
      Murray MacPherson
      www.wellhungandtender.com

      Comment


        #4
        Sorry to resurrect an old thread, but I can't get Norman's solution in post 2 to work in V9.

        Does it need changing for V9 or am I doing something wrong.

        I am trying to insert on a single product per page product layout.

        I have copied and pasted the code from Post 2 but get the following error:
        parse error: parse error in main on line 2
        Everything from the ' < 1) ' onwards is red (see attached image), does this give a clue as to the problem.
        Attached Files
        Darren Guppy
        Golf Tee Warehouse
        Golf Tees and Golf Accessories.

        Comment


          #5
          Please ignore above post, I have found the solution, I just needed to change the type from "Standard" to "ProductList", so the new code I have used is:

          Code:
          <actinic:block php="true" type="ProductList" >
          $weight = '<actinic:variable name="ShippingWeight" encoding="perl" />';
          if ($weight == '') $weight = 0;
          if ($weight < 1)
            {
            echo ($weight * 1000) . 'gm';
            }
          else
            {
            echo $weight . 'Kg';
            }
          </actinic:block>
          I have not used PHP before, so a bit of light reading might be in order.
          Darren Guppy
          Golf Tee Warehouse
          Golf Tees and Golf Accessories.

          Comment


            #6
            Darren,

            What you have coded in #5 will work through every product on a page and repeatedly do the calculation.

            This may be fine for your SPP site (only one product to loop through) but would be erroneous for anyone who adds it into a Product Layout (which is where it's intended to be used).

            I guess you were trying to use it outside of a Product Layout.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              It is being used inside a product layout.

              I am using a customised version of "Standard Product Layout using CSS"

              Any idea why the code in post 2 gives me an error.
              Darren Guppy
              Golf Tee Warehouse
              Golf Tees and Golf Accessories.

              Comment


                #8
                No idea why you get the error. Try Previewing a page and look in the generated source to see if there's an error message embedded.

                BTW, the red coloured text isn't an error. Just the Actinic parser getting confused by the < sign and thinking that everything that follows is within an HTML tag. Purely a cosmetic quirk.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  The preview inside Actinic shows the parse error, but when uploaded and viewed the weight is displayed correctly and no embedded error messages.

                  As setting the Type to 'ProductList' doesn't cause me a problem, I will use that and can be seen working here:http://www.golfteewarehouse.co.uk/ac...HeadCover.html
                  The weight is shown as the bottom of the description, although the error occurs wherever I place the code in the product layout.

                  Thanks for helping Norman.
                  Darren Guppy
                  Golf Tee Warehouse
                  Golf Tees and Golf Accessories.

                  Comment


                    #10
                    Try using
                    Code:
                    $weight = '<actinic:variable name="ShippingWeight" encoding="perl" selectable="false" />';
                    Actinic may be adding extra code when in the Design pane that's causing your error. Adding selectable="false" to a variable inhibits that.
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Thanks Norman,
                      That has eliminated the errors.

                      Five gold stars to Norman.

                      To clarify the working code is:
                      Code:
                      <actinic:block php="true">
                      $weight = '<actinic:variable name="ShippingWeight" encoding="perl" selectable="false" />';
                      if ($weight == '') $weight = 0;
                      if ($weight < 1)
                        {
                        echo ($weight * 1000) . 'g';
                        }
                      else
                        {
                        echo $weight . 'Kg';
                        }
                      </actinic:block>
                      Darren Guppy
                      Golf Tee Warehouse
                      Golf Tees and Golf Accessories.

                      Comment


                        #12
                        Super. I've updated my post #2 above to include this.
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment

                        Working...
                        X