Announcement

Collapse
No announcement yet.

Calculate the Total Price of Only Specific Items in the Shopping Cart?

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

    Calculate the Total Price of Only Specific Items in the Shopping Cart?

    On my Basket page, I would like to perform 2 calculations. The first will be the total of all items in the shopping cart (like normal). The second will be the total of only specific items who's product code begins with a specific string of letters.

    For instance, let's say I've added the following product codes to my shopping cart:
    ABC-product1 ($10.00)
    ABC-product2 ($10.00)
    XYZ-product1 ($10.00)
    ABC-product3 ($10.00)

    I would like to display a total for all of those items combined ($40.00).... as well as a total for ONLY the items beginning with ABC ($30.00).

    I should point out that i don't need a second checkout button. The checkout button, on the page, will still calculate the full total, like normal. I just need that second calculation so that I have a running tally of how much the customer has spent on the 'ABC' product line, so that I can display other information on the page if they've reached a certain amount.

    Is this possible?

    Any help would be appreciated!
    Thanks!
    Last edited by allclear; 12-05-12, 03:52 AM.

    #2
    Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

    You could do that with the Emporium Plus Tool Kit math functions http://www.emporiumplus.com/1AA00223.html
    Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
    Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
    Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
    Facebook http://www.facebook.com/EmporiumPlus
    Twitter http://twitter.com/emporiumplus

    Comment


      #3
      Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

      I had a feeling that toolkit would be able to offer a solution here.

      So, I was able to isolate the products using:
      Code:
      <mvt:if expr="('ABC-' CIN l.settings:item:code) EQ 1">

      But, because the total is calculated by all of the products in the basket (&mvt:basket:formatted_total;), I still get the total of all the products.

      Is the solution to create an array of just the items beginning with 'ABC'?
      Or should I be trying to create variables from the prices of the these products?

      Logically, that's what I'm guessing I need to do, but I haven't had any luck doing either.

      Comment


        #4
        Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

        Something like this right above the product name in the items foreach loop.
        Code:
        <mvt:if expr="('ABC-' CIN l.settings:item:code) EQ 1">
        <mvt:item name="toolkit" param="bask_getsum" />
        <mvt:item name="toolkit" param="math_add|basketprice|basketprice|l.all_settings:subtotal_sum" />
        </mvt:if>
        Then after the foreach loop at the location you want to display the value, put
        &mvte:global:basketprice;

        If you want that to be formatted with the $ character and rounded two place, you would use the currencyformat function in the tool kit.
        Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
        Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
        Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
        Facebook http://www.facebook.com/EmporiumPlus
        Twitter http://twitter.com/emporiumplus

        Comment


          #5
          Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

          Thanks for the reply... it's very appreciated.

          I tried what you had suggested, and was getting "0" as the result. So I started to pick apart the code to try to find where it was failing. I'm pretty sure that it's the "bask_getsum" that's tripping up my code.

          So I went to the Toolkit manual and read about the "bask_getsum" function:

          139. Use bask_getsum to create a price sum variable in the basket. It sums the base price + the attribute prices to create a formatted_price_sum. To use this function, just before the price display in the basket contents of the BASK page, insert this line.
          <mvt:item name="toolkit" param="bask_getsum" />
          Then change &mvt:item:formatted_price; to &mvt:item:formatted_price_sum; and also the &mvt:item:formatted_subtotal; to &mvt:item:formatted_subtotal_sum; Then you will remove the display of attribute option prices. You can also use this feature in the checkout screens as they use the basket contents display. You will use the same token as the basket screen.
          I then created a very simple basket:

          Code:
          <table border="1" cellpadding="2" cellspacing="0" width="100%">
          <mvt:item name="toolkit" param="bask_getsum" />
          <mvt:foreach iterator="item" array="basket:items">
           <tr>
            <td>&mvt:item:code;</td>
            <td>&mvt:item:quantity;</td>
            <td>&mvt:item:formatted_price_sum;</td>
            <td>&mvt:item:formatted_subtotal_sum;</td>
           </tr>
          </mvt:foreach>
           <tr>
            <td colspan="4" align="right">
             <strong>Total: &mvt:basket:formatted_total;</strong>
            </td>
           </tr>
          </table>
          The result is that the Product Code and Quantity are being populated, but the the Price_Sum and Subtotal_Sum fields are blank. So, I'm obviously doing something wrong that is causing the "bask_getsum" functionality to fail on my page.

          Any ideas as to why this is happening?
          Thanks in advance

          Comment


            #6
            Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

            Maybe your version of the tool kit is older than the online manual. Hence, look in the tool kit admin screen and see if the bask_getsum function is there. It would be a different number than the online manual. But it should be there. If it is not, your version needs updating.
            Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
            Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
            Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
            Facebook http://www.facebook.com/EmporiumPlus
            Twitter http://twitter.com/emporiumplus

            Comment


              #7
              Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

              That was it! So I've updated to the latest ToolKit and used your code:

              Code:
              <mvt:foreach iterator="item" array="basket:items">
              <mvt:if expr="('ABC-' CIN l.settings:item:code) EQ 1">
              <mvt:item name="toolkit" param="bask_getsum" />
              <mvt:item name="toolkit" param="math_add|basketprice|basketprice|l.all_settings:item:subtotal_sum" />
              </mvt:if>
              I now have both the complete order total AND the ABC-Product subtotal displayed, side by side, on the page.

              The next step of this is to determine whether the ABC-Product subtotal has reached a certain amount, and if so, display a message on the page.

              Something like:
              Code:
              <mvt:if expr="l.settings:toolkit:baskettotal LT '1000'">
              You have spent less than $1,000 on ABC equipment
              </mvt:if>
              Only now, instead of checking if the baskettotal is less than $1000, I want to check the new basketprice variable. Can this be done?
              Last edited by allclear; 12-05-12, 12:30 PM.

              Comment


                #8
                Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

                Code:
                <mvt:if expr="g.basketprice LT 1000">
                You have spent less than $1,000 on ABC equipment
                </mvt:if>

                Comment


                  #9
                  Re: Calculate the Total Price of Only Specific Items in the Shopping Cart?

                  That was it. Thanks to both of you for your help.

                  Comment

                  Working...
                  X