Announcement

Collapse
No announcement yet.

PHP to show Price or From with price breaks

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

    PHP to show Price or From with price breaks

    Can someone see what is wrong here, i think i am going mad. Trying to show:

    Price: (insert price)

    or

    From: (insert lowest price)

    on a section link layout using the following code:

    Code:
     <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" >
    $pricecount="<actinic:variable name="ListCount" />";
    $priceindex="<actinic:variable name="ListIndex" />";
    if (($priceindex == 1) && ($pricecount == $priceindex))
    echo "Price: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)";
    elseif (($priceindex > 1) && ($pricecount == $priceindex))
    echo "From: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)";
    </actinic:block></actinic:block></actinic:block>
    What am i doing wrong, save me from php hell please.

    All it keeps doing is showing the Price: condition, even on price break products.

    #2
    Try adding encoding="perl" selectable="false" into the Actinic variables used in the php

    Comment


      #3
      Thanks for the idea Duncan, not made any difference though.

      Comment


        #4
        I havent got time to check but

        if (($priceindex == 1) && ($pricecount == $priceindex))
        I think it should be

        if ($priceindex == 1 && $pricecount == $priceindex)
        Do the same for your elseif

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

        First Tackle - Fly Fishing and Game Angling

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

        Comment


          #5
          Thanks Mike, i have since tried that but to no avail, appreciate your time though.

          Comment


            #6
            I have since gone round the long way and done it like this now, can't believe there is not an easier way, but it seems to defy all mathematical logic. But in fairness I am truly useless at php. Here it is anyway:


            Code:
            <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" if="%3cactinic%3avariable%20name%3d%22IsPriceBreak%22%20%2f%3e%20%3d%3d%20false" >echo "Price: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" />";</actinic:block></actinic:block></actinic:block>
            <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" if="%28%3cactinic%3avariable%20name%3d%22IsPriceBreak%22%20%2f%3e%20%3d%3d%20true%29%20AND%20%28%3cactinic%3avariable%20name%3d%22ListIndex%22%20%2f%3e%20%3e%201%29" >echo "Prices from: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" />";</actinic:block></actinic:block></actinic:block>
            In simple terms, i have created a condition from the existing price break conditions, to see if there is at least one price break on the product (just merge all standard existing price break conditions in a new one), i then add a condition to the Block of php which decides whether it should run or not. It only ever meets one of the conditions in the above code and thus only ever outputs one line.

            Comment


              #7
              I don't think you will be able to place a layout directly into the php code as you have here:
              Code:
              echo "Price: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)";
              because the layout itself has blocks inside itself etc. So I think you will have to build your php around the layout in two parts.

              All I see you are trying to do is change 'Price' to 'From' based on the ListIndex and ListCount so build the php around just those two parts separately.

              Edit - see you have already split it out in two. Also see it seems that the layout works in the echo which I wouldn't have expected.

              Comment


                #8
                Been out all day so only saw this now. See http://community.actinic.com/showthread.php?t=30435 post #45 which may help.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Thanks Norman, i gotta go with code i understand myself as for a client, still somewhat baffled why it did not work. But then yours is even more baffling with the END OF CODE mallarky. Either Actinic can't add up or i am very bad at maths and even worse at php. Wise money is on me being the dunce.

                  Comment


                    #10
                    Hi Lee,

                    This has been bugging me so I've been taking a look into it.

                    The trouble appears to be that ListCount never seems to be going above 1. This doesn't seem right but you can check it with this code.

                    <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" >
                    $pricecount="<actinic:variable name="ListCount" />";
                    $priceindex="<actinic:variable name="ListIndex" />";
                    echo "Count: $pricecount ";
                    echo "List: $priceindex <br>";
                    if ($pricecount ==1)
                    echo "Price: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)<br>";
                    if ($pricecount > 1 && $priceindex == $pricecount)
                    echo "From: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)<br>";
                    </actinic:block></actinic:block></actinic:block>
                    It shows that ListCount is always 1, even though ListIndex goes up to the number of price breaks you enable.

                    At first I thought maybe this was the ListCount cacheing problem but it does the same online. Very odd.

                    I'm still looking at this as I'd like to see it work, but at the moment I'm stumped.

                    Mike

                    PS. Your second version of code is only going to work with a single price break as it produces multiple "From: " outputs if there are more than one.

                    PPS. I'm testing on V9.

                    PPPS. It seems the bug might still have been around on 9.0.5? Is it still there on V10 / V11? http://community.actinic.com/showthread.php?p=215752
                    -----------------------------------------

                    First Tackle - Fly Fishing and Game Angling

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

                    Comment


                      #11
                      I got list count going above 1 as i had 2/2 showing on some prices, problem being it was also showing 1/2. It couldn't seemingly show a single result dependent on basic maths (as i saw it).

                      The code i used does only work on 2 price breaks, the site where it is installed only has that and only ever will, but if multiple breaks are in operation, listindex = listcount within the condition should satisfy that. When the index of the product is effectively the same as the number in the list, then it must be the last one etc.

                      Hmm perhaps that Norman post points to the issue and there is indeed a mathematical issue with how things are numbered, i'm sure i recall Norman mentioning about the way prices are created is a bit convaluted or breaks actinic's own rule - don't quote me on that, sure there is something weird that occurs in that area.

                      The list variables are very powerful, but only if they can do basic maths, i have even more doubts whether they can now.

                      PS - the list count is definitely working, because on a 2 price break setup i can choose which price to show against the 'from' text, so something is occurring for sure.

                      Comment


                        #12
                        It must be V9 that's messing with my results then as I only ever see 1s for listcount. I've tested with 3 price breaks and while ListIndex goes up ListCount is always staying at 1.

                        In which case I'll have to leave it for the moment.

                        Mike

                        PS. If ListCount works for you then all you should need is this. i.e. just show the results when ListIndex = ListCount:

                        <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" >
                        $pricecount="<actinic:variable name="ListCount" />";
                        $priceindex="<actinic:variable name="ListIndex" />";
                        if ($priceindex == $pricecount)
                        echo "From: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)<br>";
                        </actinic:block></actinic:block></actinic:block>
                        Ok. Forget that. Mathematically it works but I forgot about the Price / From selection.
                        -----------------------------------------

                        First Tackle - Fly Fishing and Game Angling

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

                        Comment


                          #13
                          Something very weird going on here.

                          In V9 I can't get this to work at all. ListCount always seems to be 1 for me.

                          In V10. Lee's code doesn't work either... unless you force it by adding a simple echo line in front. Even just an echo " "; works as follows:

                          <actinic:block type="ProductList" ><actinic:block type="PriceList" ><actinic:block php="true" >
                          $pricecount="<actinic:variable name="ListCount" />";
                          $priceindex="<actinic:variable name="ListIndex" />";
                          echo " ";
                          if (($priceindex == 1) && ($pricecount == $priceindex))
                          echo "Price: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)";
                          elseif (($priceindex > 1) && ($pricecount == $priceindex))
                          echo "From: <actinic:variable name="PreFormattedPrice" value="Product Price Excluding Tax" /> (<actinic:variable name="ListIndex" />/<actinic:variable name="ListCount" />)";
                          </actinic:block></actinic:block></actinic:block>
                          Note the third line of php with the echo.

                          Comment out the echo and it breaks, re-introduce it and it works.



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

                          First Tackle - Fly Fishing and Game Angling

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

                          Comment


                            #14
                            LisctCount is very erratic.

                            See Bug: ListCount variable is erratic within Product Lists. Note: Old post, but not sure if this has ever been fixed.

                            And the horror story continues at Bug: Lists processed in unusual sequence. Again probably never fixed - it's a feature!

                            I tend to use this horrible (as it's slow) hack to get ListCount into PHP. E.g.
                            Code:
                            <actinic:block php="true">
                              <actinic:block type="ProductList>$listcount = <actinic:variable name="ListIndex" />;</actinic:block>
                              echo "At last a valid ListCount: $listcount";
                            </actinic:block>
                            And I don't put any initialising PHP into Start of List or End of List. Instead I put initialising code in the List body with a BlockIf ListIndex == 1 around it.
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              Thanks Norman,

                              It's still all very strange. Even with V10 your alternative listcount code doesn't work. The comparisons fail and I end up with multiple outputs even though the variables don't match.

                              Why it works with an echo statement is very odd. Maybe it's something to do with the veriable types, though I can't see that myself.

                              The annoying thing is that I use echos to debug the code and see what's happening to the variables. So I get it working in debug mode then strip out the debug echos and it stops working again. Annoying as hell.

                              I think I've spent enough time on this. I'll just need to be very careful when using ListCount and make sure any code works properly. A useful learning experience.

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

                              First Tackle - Fly Fishing and Game Angling

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

                              Comment

                              Working...
                              X