Announcement

Collapse
No announcement yet.

RRP Show Saving %

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

    RRP Show Saving %

    I'm using the below code to display RRP and show the saving % if there is one:

    Code:
    <actinic:block php="true" >
    		$rrp = number_format(<actinic:variable name="RRP" selectable="false" />,2);
    		$rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
    		// display if there's a saving to show
    		if ( ($rrp != 0) && ($rrp > $rawprice) )
    			{
    			$savepercent = round((($rrp - $rawprice) / $rrp) * 100);
    			echo "<h3 class=\"rrp_price\">";
    			echo "RRP: £$rrp <span class=\"percent\">(SAVING YOU $savepercent%)</span>";
    			echo "</h3>";
    			}
    </actinic:block>
    My RRP variable is empty unless i add something into it. On products where i have not added a value, the above code fails. I understand why because of this condition:

    Code:
    if ( ($rrp != 0) && ($rrp > $rawprice) )
    My RRP has no value in it and is not equal to 0. I cannot retrospectively change the variable to have 0 as the default value as it's a long standing variable with over 900 entries across products. So i need to get the code to also evaluate when the variable is empty. This is where i have been going round in circles, nothing seems to work.

    My logic has so far been:

    if ($rrp == '') then $rrp = 0 - to assign 0 value if it is empty. This did not work.

    i also tried adding in a third option into this, like so:

    Code:
    if ( ($rrp != 0) &&  ($rrp == '') && ($rrp > $rawprice) )
    That didn't work either, i then tried what was seemingly every other version of those ideas, to no avail.

    I SUCK AT PHP!

    #2
    Norman may be along with some php wizardry but I'd do a C&P in the database or a query.

    Comment


      #3
      I like Lee's initial logic:

      My logic has so far been:

      if ($rrp == '') then $rrp = 0 - to assign 0 value if it is empty. This did not work.
      There is no 'then' though, I think it should just be:

      if ($rrp == '') {$rrp = 0;}
      Mike
      -----------------------------------------

      First Tackle - Fly Fishing and Game Angling

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

      Comment


        #4
        Sorry Mike, I did do that when i tried it, i just wrote out the logic as i couldn't quite recall how i wrote it at the time, it was just as you have though. It didn't stop the error message though which really confused me. Just tried it again and the error comes up:

        Parse error: parse error, expecting '')" in main on line 2

        Code i am using is:
        Code:
        <actinic:block php="true" >
        		$rrp = number_format(<actinic:variable name="RRP" selectable="false" />,2);
        		if ($rrp == '') {$rrp = 0;}
        		$rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
        		// display if there's a saving to show
        		if ( ($rrp != 0) && ($rrp > $rawprice) )
        			{
        			$savepercent = round((($rrp - $rawprice) / $rrp) * 100);
        			echo "<h3 class=\"rrp_price\">";
        			echo "RRP: £$rrp <span class=\"percent\">(SAVING YOU $savepercent%)</span>";
        			echo "</h3>";
        			}
        		</actinic:block>

        Comment


          #5
          It should work. Try using "" rather than ''.

          Mike

          PS. Just looked at my code and I use this at the start of the block to achieve the same thing

          // only display if we have an RRP and there's a saving to show
          if ($rrp != "" )
          {
          PPS. You might have a problem because you're setting and formatting the variable at the same time. i.e. I haven't a clue what $rrp will be in the case where it's blank. What is a blank value formatted to two decimal places?
          -----------------------------------------

          First Tackle - Fly Fishing and Game Angling

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

          Comment


            #6
            How about using the "Empty" function that seems to cover lots of options - extract from PHP.NET

            Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

            The following things are considered to be empty:

            ■"" (an empty string)
            ■0 (0 as an integer)
            ■0.0 (0 as a float)
            ■"0" (0 as a string)
            ■NULL
            ■FALSE
            ■array() (an empty array)
            ■$var; (a variable declared, but without a value)

            // Evaluates to true because $var is empty
            if (empty($var)) {
            echo '$var is either 0, empty, or not set at all';
            }

            Comment


              #7
              Originally posted by Mike Hughes View Post
              It should work. Try using "" rather than ''.

              Mike

              PS. Just looked at my code and I use this at the start of the block to achieve the same thing



              PPS. You might have a problem because you're setting and formatting the variable at the same time. i.e. I haven't a clue what $rrp will be in the case where it's blank. What is a blank value formatted to two decimal places?
              It will not work with ' or ".

              I have the other condition in place so that if normal price is not cheaper than rrp, it will not show, more of a sanity check that is.

              I also though about a null value being formatted somehow, but i tried taking out the formatting altogether and still the error exists. With a number or a 0, it all works fine, when blank it does not.

              Comment


                #8
                Originally posted by miketait View Post
                How about using the "Empty" function that seems to cover lots of options - extract from PHP.NET

                Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

                The following things are considered to be empty:

                ■"" (an empty string)
                ■0 (0 as an integer)
                ■0.0 (0 as a float)
                ■"0" (0 as a string)
                ■NULL
                ■FALSE
                ■array() (an empty array)
                ■$var; (a variable declared, but without a value)

                // Evaluates to true because $var is empty
                if (empty($var)) {
                echo '$var is either 0, empty, or not set at all';
                }
                Tried that too.

                Code:
                if (empty($rrp)) {$rrp = 0;}
                Fails also, thanks for suggestion though.

                Comment


                  #9
                  All looks a bit dirty for you Lee

                  echo your $rrp and see what that returns first


                  Bikster
                  SellerDeck Designs and Responsive Themes

                  Comment


                    #10
                    This code (note using ProductPriceRaw as it's available on the site I'm tinkering with) works fine:
                    Code:
                    <actinic:block php="true">
                    	$ppr= '<actinic:variable name="ProductPriceRaw" selectable="false" />';
                    	if (empty($ppr)) echo 'EMPTY';
                    </actinic:block>
                    Note that the simpler code below does not work as empty needs a variable to work on, not a quoted string:
                    Code:
                    <actinic:block php="true">
                    	if (empty('<actinic:variable name="ProductPriceRaw" selectable="false" />')) echo 'EMPTY';
                    </actinic:block>
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Thanks Norman, not making a difference my end for some reason, this still gives an error message on empty values:

                      Code:
                      <actinic:block php="true" >
                      		$rrp = number_format(<actinic:variable name="RRP" selectable="false" />,2);
                      		if (empty($rrp)) {$rrp = 0;}
                      		$rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
                      		// display if there's a saving to show
                      		if ( ($rrp != 0) && ($rrp > $rawprice) )
                      			{
                      			$savepercent = round((($rrp - $rawprice) / $rrp) * 100);
                      			echo "<h3 class=\"rrp_price\">";
                      			echo "RRP: £$rrp <span class=\"percent\">(SAVING YOU $savepercent%)</span>";
                      			echo "</h3>";
                      			}
                      		</actinic:block>

                      Comment


                        #12
                        The code looks very similar to that which we have used without problems - so I tried it on our site and got the PHP error on line 2 as above.
                        Now the strange bit - if I replace the actinic variable name "RRP" in that line with the variable name we have been using the code works OK - even though the 2 variables had identical setup and content.
                        Also tried wth a new variable names and the PHP error problem returns - but out of interest I tried "ProductPriceRaw" variable as per Normans example there's no error ??

                        And now I can't delete RRP variable from library as it thinks it's in use in a layout despite me removing the code !!

                        Comment


                          #13
                          OK - so I setup new site - tried Lee's code above and got the PHP error

                          Changed line 2 to:

                          $rrp = number_format('<actinic:variable name="RRP" selectable="false" />',2);

                          and it works fine - note the extra single quotes before/after <> , which I had spotted in Norman's reply and tried in my earlier attempts but without success ???

                          Comment


                            #14
                            YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY, WOOOOOOOOOHHHHHHHHHOOOOOOO. Cheers Mike, it works! Much appreciated as is the time spent by others helping. Chuffed!

                            Comment


                              #15
                              NOOOOOOOOOOOOOOOOOOOOOOOO!!!

                              Baffled again, stands to reason, it's php after all.

                              When i put a 4 figure RRP in, say £1494.00, the message will not show, yet if i put £999.99 in, it does. It fails when the price i insert is £1000 or above, i simply cannot get how that can be with what is simply a maths calculation?

                              Any ideas please?

                              Comment

                              Working...
                              X