Announcement

Collapse
No announcement yet.

Math with variables

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

    #31
    Update for Menswear Online

    Hi all,

    Following on from this, thought some of you might like to see our current, slightly more advanced implimentation of this...

    if you look at our "New Products" seciton at the bottom of the home page http://www.menswearonline.co.uk
    I've edited this so that items with a saving below £24 show up with the saving as a percentage, where as items where you save over £24 show up as an amount for the saving.

    Code below...
    Enjoy

    Code:
    <actinic:block php="true">
    $rrp = <actinic:variable name="ProductRRP" selectable="false" />;
    $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
    $amountsaved = round($rrp - $rawprice);
    $savepercent = round((($rrp - $rawprice) / $rrp) * 100);
    
    // only display is we have an RRP and there's a saving to show
    if ( ($rrp != 0) && ($rrp > $rawprice) && ($amountsaved > 24))
      {
      echo "Save: £$amountsaved";
      }
      
    if ($amountsaved < 24)
    {
    echo " Save: $savepercent%";
    } 
    </actinic:block>

    EDIT - in case the saving IS £24

    Code:
    <actinic:block php="true">
    $rrp = <actinic:variable name="ProductRRP" selectable="false" />;
    $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
    $amountsaved = round($rrp - $rawprice);
    $savepercent = round((($rrp - $rawprice) / $rrp) * 100);
    
    // only display is we have an RRP and there's a saving to show
    if ( ($rrp != 0) && ($rrp > $rawprice) && ($amountsaved > 24))
      {
      echo "Save: £$amountsaved";
      }
      
    if ($amountsaved <= 24)
    {
    echo " Save: $savepercent%";
    } 
    </actinic:block>
    im certainly not much of a php guy, im sure there are cleaner ways to do this, like some kind of OR function, but at least this works!

    feel free to post clean ups. Thanks!
    http://www.itwiz.co.uk

    http://www.AntiV.net - The Discount Antivirus Store

    Comment


      #32
      another thought, if you're doing a lot of amount based stuff like this, it would make sense to do a
      Code:
      $cutoff = 24;
      and use that so you only have to change one thing
      http://www.itwiz.co.uk

      http://www.AntiV.net - The Discount Antivirus Store

      Comment


        #33
        i have a question.. if u implement this coding.. would it show up if a signed in customer viewed the page?

        from what i have experienced, i dont think it does right?

        Comment


          #34
          To my surprise, you are correct sir!

          We don't use accounts so isn't too much of a problem for us.

          I'm pretty sure this is to do with layouts... some where there is probably a box where you select the layout for guests and registered users. I imagine you just select the layout you configured to use this code??
          http://www.itwiz.co.uk

          http://www.AntiV.net - The Discount Antivirus Store

          Comment


            #35
            the problem i encountered was that for registered users, the layout uses a <Actinic:TaxExclusivePrice /> and i can;t read that into a php code, it has intrigued me, hahaha. just dunno how to solve.

            Comment


              #36
              if ($amountsaved = 24)
              Is wrong. You're setting $amountsaved to 24, not comparing it with 24.

              Use

              if ($amountsaved >= 24)

              or

              if ($amountsaved == 24)

              depending on what you want to achieve.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #37
                doesn't
                Code:
                $price = <actinic:variable name="TaxExclusivePrice" selectable="false" />;
                work?
                http://www.itwiz.co.uk

                http://www.AntiV.net - The Discount Antivirus Store

                Comment


                  #38
                  thank-you, had meant to amend that! will change post above accordingly
                  http://www.itwiz.co.uk

                  http://www.AntiV.net - The Discount Antivirus Store

                  Comment


                    #39
                    Originally posted by mattc
                    doesn't
                    Code:
                    $price = <actinic:variable name="TaxExclusivePrice" selectable="false" />;
                    work?

                    No, it doesn;t cause well there is a difference between
                    Code:
                    <Actinic:TaxExclusivePrice />
                    &
                    Code:
                    $price = <actinic:variable name="TaxExclusivePrice" selectable="false" />;
                    ...

                    when you use them, the first is displayed in RED font color, and the latter is normal variable.

                    haha.

                    Comment


                      #40
                      what about $price = <Actinic:TaxExclusivePrice />
                      http://www.itwiz.co.uk

                      http://www.AntiV.net - The Discount Antivirus Store

                      Comment


                        #41
                        Ok i have been looking at this today, is there a way to show the % to 1 decimal place, the rounding makes it quite a bit different on small value items (in relative terms)

                        so instead of showing 8% it would show something like 7.6%

                        thanks in advance

                        D

                        Comment


                          #42
                          PHP round examples

                          <?php
                          echo round(3.4); // 3
                          echo round(3.5); // 4
                          echo round(3.6); // 4
                          echo round(3.6, 0); // 4
                          echo round(1.95583, 2); // 1.96
                          echo round(1241757, -3); // 1242000
                          echo round(5.045, 2); // 5.05
                          echo round(5.055, 2); // 5.06
                          ?>
                          First Value is the variable/value to be rounded,
                          Second value is the precision. For one decimal place use ", 1".


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

                          First Tackle - Fly Fishing and Game Angling

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

                          Comment


                            #43
                            thanks mike, i did take a look at the website but was not sure how i worked this into the code above, i have tried the number format but just get parse errors

                            being that the my knowledge on this sort of thing is ermmm limited is probably an over statement

                            Comment


                              #44
                              OK sorted it, im not sure what i have done is techically correct but it works

                              Code:
                              {
                              $amountsaved = ($rrp - $rawprice);
                              $savepercent = ((($rrp - $rawprice) / $rrp) * 100);
                              echo "RRP £$rrp - you save £$amountsaved";
                              echo " (".number_format($savepercent,1);
                              echo "%)";
                              }
                              i have it working here http://www.kitesrus.co.uk/acatalog/H...er_III_2M.html

                              Comment


                                #45
                                Calculate 'Our Price' from RRP from Product Group Discount

                                Sorry if this should be in a new thread...

                                I work in a very price sensitive market and need to be able to change my selling price fairly often.

                                Is there a way of grouping products, allocation a variable discount by Product Group? e.g. Brand ABC Cookers, we currently sell at 10% off RRP with delivery included. Brand XYZCookers, we sell at 20% off RRP but charge delivery.

                                Then I want to show RRP & 'Our Price' but with 'Our Price' automatically calculated as RRP-Product Group Discount.

                                That way, I only need change the RRPs when manufacturers change theirs (once or twice a year) and manage the Product Group Discounts as and when the market dictates.

                                I would have thought this was fairly a standard approach. No?

                                Thanks in anticipation!
                                Ian Henley

                                Comment

                                Working...
                                X