Announcement

Collapse
No announcement yet.

discount & string to integer casting

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

    discount & string to integer casting

    Hello,

    So here's the deal. Discounts are setup for product groups. To capture the discount in a variable I go to the discount configuration and enable the option to print the discount msg against each product. The discount is just a figure (ie for the 25% off discount group, I put 25). Then I go to the standard discount layout, comment out the part where it ouputs the discount message. I instead assign it to a variable (in a php block).

    $discount= "<Actinic:Variable Name="DiscountInfo"/>";

    The aim here is to display the price minus the discount next to the normal price. Straightfoward enuff.
    However, the aforementioned variable is a string. To perform my little calculations, in the price layout, I need an int. And every attempt to convert that data to an int is failing (always giving me a zero).

    I don't get it.

    $d = (int)$discount;
    $d = 0 + $discount;

    just don't do it.

    #2
    have you tried echoing $discount to see what the contents are?

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

    First Tackle - Fly Fishing and Game Angling

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

    Comment


      #3
      well, of course, the value is echoed.

      So, what I aim to display is something like:

      -40% : 17.34 € au lieu de 28.91 €

      Comment


        #4
        Originally posted by lazyeye View Post
        well, of course, the value is echoed.

        So, what I aim to display is something like:

        -40% : 17.34 € au lieu de 28.91 €
        Have you tried using intval(string) to convert the string?

        Malcolm

        SellerDeck Accredited Partner,
        SellerDeck 2016 Extensions, and
        Custom Packages

        Comment


          #5
          I have.

          Next time I boot on windows I'll try again with a combination. Is actinic's handling of php flawed?

          Comment


            #6
            ok, now it works. The trick is to edit the appearence of DiscountInfo and set "selectable" to false.

            Comment


              #7
              The trick is to edit the appearence of DiscountInfo and set "selectable" to false
              You've found the solution. The reason for this is that while in the Design Tab, some extra code is added to variables and layout selectors that detects you clicking on them. That code contains quotes, which either breaks the PHP syntax or messes with the returned value.

              If you'd switched to the Content Tab, everything would have worked fine as the extra code isn't embedded then.

              Another thing that's worth knowing if you intend to pass variables to PHP is to use single quotes and set encoding="perl". E.g.
              Code:
              $discount= '<Actinic:Variable Name="DiscountInfo" encoding="perl" selectable="false" />';
              Is safest (if DiscountInfo contained a single quote it would now be encoded as \').
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                Yes. Found that out in the knowledge base. Encoding as perl had no effect so I left it as it initially was.

                Comment


                  #9
                  Encoding as perl had no effect
                  You're probably safe but it can sometimes bite people in the future. E.g. if you had a variable Supplier and you use it like this:

                  $mysupplier = '<actinic variable name="Supplier" />';

                  Then the site will appear to work fine until some day someone enters a supplier like O'Neill.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    yes, you're right. but in this case, I know where the value comes from (I set it up in the discount options) and know that it will always be what I expect it to be (ie a string representation of an integer).

                    Comment


                      #11
                      I know you're safe. It's just that others who read this thread later may be using less controlled values.

                      Another thing to watch out when using Actinic generated prices is that they may contain commas. E.g. 1,000.00. Again code that works for small prices may break if you add an expensive item.
                      Norman - www.drillpine.biz
                      Edinburgh, U K / Bitez, Turkey

                      Comment

                      Working...
                      X