Announcement

Collapse
No announcement yet.

Item must be ordered alone, need to display message

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

    Item must be ordered alone, need to display message

    I can't find anywhere the code I need to display a simple message if an item is in the cart with any other item. I've tried every possible combination and searched the forums. I wish there was a simple list somewhere of everything I can do with an if expression. All the Developer Docs are very limited in the information they give. I'd appreciate some direction.

    Code:
    <mvt:if expr="'State of Grace' IN l.settings:item:product:name AND l.settings:item:product:price NE 24.95">
    STOP: PLEASE REMOVE ALL OTHER ITEMS FROM CART.  THE STATE OF GRACE: DAILY MEDITATIONS BOOK MUST BE ORDERED SEPARATELY.<br /><br /></mvt:if>
    Code:
    <mvt:if expr="'State of Grace' IN l.settings:item:product:name AND 'State of Grace' NE l.settings:item:product:name">
    STOP: PLEASE REMOVE ALL OTHER ITEMS FROM CART.  THE STATE OF GRACE: DAILY MEDITATIONS BOOK MUST BE ORDERED SEPARATELY.<br /><br /></mvt:if>
    Isn't there some kind of NOT IN or DOES NOT CONTAIN operator? What can I do here?

    I need to display a message if our book pre-order is in the cart with any other item.

    #2
    This should work

    Code:
    <mvt:if expr="('State_of_Grace' IN l.settings:item:product:name) AND (l.settings:basket:items GT 1)">
    STOP: PLEASE REMOVE ALL OTHER ITEMS FROM CART.  THE STATE OF GRACE: DAILY MEDITATIONS BOOK MUST BE ORDERED SEPARATELY.<br /><br />
    </mvt:if>
    Note: Generally, one doesn't use 'names' in conditionals as these are much more likely to change verses 'code'.

    As for a 'does not contain' operator, you could use

    NOT('this' IN l.settings:that)

    Basic SMT usage is here:

    https://docs.miva.com/template-language/


    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Thanks for helping me. Our pre-order can be ordered at 1-10 books, so items in cart could be any combination of 1 through 10 books plus other stuff. Could I say if State of Grace is in the product name and the product code is not BO-005? I think that might be a circular statement though because the book would both meet and not meet the criteria.

      btw, the template language link seems to be dead.

      Comment


        #4
        Wait, is basket items different than basket quantity? This would work if that's the case. There would just be one item in the basket, with a quantity of 1-10.

        Comment


          #5
          yea, sorry, that link is

          https://docs.miva.com/template-language/mvtassign


          on second thought, probably better to use

          l.settings:group:quantity

          This should return the total number of items in the basket (based on individual item count). So if you had 3 of one item and 6 of the other, that variable would eval to 9.

          (also, typo. that should be l.settings:product:code if you use the product code has the variable match.)
          Bruce Golub
          Phosphor Media - "Your Success is our Business"

          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
          phosphormedia.com

          Comment


            #6
            Correct, there is only one of each item in the basket record, but the quantity can be anything above zero.

            Just for kicks, if you wanted to get slick about this you could load the list of basket items and then loop through them looking for products that meet your criteria.

            First I'd set up a list of the product codes that you are looking for. Note that this is basically a quick and dirty way of doing it. If you have a ton of products like this you'd want to use custom fields and then load those fields for each product in the loop below and check if it meets your criteria. But for this example, this works:

            Code:
            <mvt:assign name="l.product_codes" value=" '|book1code|book2code|book3code|' " />
            Then load the basket items into an array:

            Code:
            <mvt:do file="g.Module_Library_DB" name="l.success" value="BasketItemList_Load_Basket(g.basket:basket_ id, l.settings:basketitems)" />
            Then loop through the array and see if any of the codes match:

            Code:
            <mvt:foreach iterator="basket_item" array="basketitems">
               <mvt:if expr=" ( '|' $ l.settings:basket_item:code $ '|') CIN l.product_codes ">
                  Hey, this is a message because the product code matches.
               </mvt:if>
            </mvt:foreach>
            M.A.D.* since 1997

            http://www.scotsscripts.com

            *miva application developers

            Comment


              #7
              well, if you really wanted to be slick, you'd include a "remove" function in the message so they can remove all the offending items OR remove the item that can only be purchase alone. :)
              Bruce Golub
              Phosphor Media - "Your Success is our Business"

              Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
              phosphormedia.com

              Comment


                #8
                One more way I thought of for doing this, if the pre-order is ordered with other items, the fallback shipping method will trigger. Would this work? (not sure of the exact code) I appreciate the slick foreach code, but that's a bit to advanced for me.

                Code:
                  
                 <mvt:if expr="('State of Grace' IN l.settings:item:product:name) AND (l.settings:shipping:method:name EQ 'Fallback')">
                STOP: PLEASE REMOVE ALL OTHER ITEMS FROM CART.  THE STATE OF GRACE: DAILY MEDITATIONS
                BOOK MUST BE ORDERED SEPARATELY.<br /><br /> </mvt:if>
                Last edited by bshaf; 10-22-19, 11:55 AM.

                Comment


                  #9
                  If you are doing this because the reference item is a pre-order...then I think you've got the wrong approach. (This is what happens when you ask "how do I fix this" verses "how do I accomplish this".)

                  However, the solution would depend on the parameters of the 'pre-order'. For example, why did you feel that the 'pre-order' item needed to be shipped separately in the first place?
                  Bruce Golub
                  Phosphor Media - "Your Success is our Business"

                  Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                  phosphormedia.com

                  Comment


                    #10
                    It’s a pre-order because the book has not been printed yet. It’s being shipped early next year. We aren’t about to keep track of half filled orders. Plus it screws up shipping. They need to be separate.

                    I have a notice that just appears if the book is in the cart. That’s good enough, I’m not fussing with it anymore. We will just refund the people who can’t follow simple instructions and make them reorder.
                    Last edited by bshaf; 10-22-19, 01:50 PM.

                    Comment


                      #11
                      Understand your position. But at least for prosperity, this wouldn't be very hard to 'track' in that, once the book come in, you can simply use 'Advanced' search in Order Processing to pull up all those orders.
                      Bruce Golub
                      Phosphor Media - "Your Success is our Business"

                      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                      phosphormedia.com

                      Comment


                        #12
                        The problem is that Miva Merchant does not have the ability to calculate the correct shipping for everything when it isn't all shipping at once. The book won't ship until probably early next year, in a separate box, up to 10 books. If I set the book to ship in separate packaging, which I've tested, it assumes each single item ships in its own box, so it calculates 10 boxes for 10 books.

                        Further, Miva can't tell the difference between the pre-order and a few small items. The few small items would need to be calculated separately to ship now, while the pre-order needs its own future second box. Instead, the combined order would be calculated all in one box, which will undercharge shipping every time, and short us even worse for international orders. Without major custom coding, Miva can't do all this out of the box.

                        It was decided rather than trying to force our store to do what it isn't designed to do, we would simply require that the pre-order be purchased separately. This will be our first pre-order, so I'm sure there will be things we can improve on for the future.

                        Thanks again for your help.

                        Comment


                          #13
                          One more question, why is my store not displaying my message every time this item is in the cart? It's randomly not showing up. I wish there was an easy way to just say if BO-005 appears anywhere at all on this page, always display the message. The tokens don't seem to be reliable.

                          Comment


                            #14
                            I'm trying your loop suggestion and I can't get it to work, what am I doing wrong? There is only one code, BO-005 that I need to trigger this message.

                            Code:
                            <mvt:assign name="l.product_codes" value=" '|BO-005|' " />
                            <mvt:do file="g.Module_Library_DB" name="l.success" value="BasketItemList_Load_Basket(g.basket:basket_ id, l.settings:basketitems)" />
                            <mvt:foreach iterator="basket_item" array="basketitems">
                               <mvt:if expr=" ( '|' $ l.settings:basket_item:code $ '|') IN l.product_codes ">
                                  <b style="font-size: 24px; color: red;">ATTENTION: JUST A REMINDER:</b> (this is not an error)<br />
                            THE STATE OF GRACE: DAILY
                            MEDITATIONS PRE-ORDER MUST
                            BE ORDERED SEPARATELY.  IF THERE
                            ARE OTHER ITEMS IN YOUR CART,
                            <a href="https://store.slaafws.org/shopping-cart.html" style="color: red;">REMOVE THEM NOW</a>.<br /><br />
                               </mvt:if>
                            </mvt:foreach>

                            Comment


                              #15
                              I got this to work finally! There was one space that needed removing in line 2.

                              g.basket:basket_ id should be basket_id

                              The code below works perfectly for me. My old code only looks at the first item in the cart and doesn't loop through all the items looking for the code. I understand now that you need that to look through each item in the cart for a match, hence the need for a foreach loop. Learned a lot from this, thank you Bruce!

                              Code:
                              <mvt:assign name="l.product_codes" value=" '|BO-005|' " />
                              <mvt:do file="g.Module_Library_DB" name="l.success" value="BasketItemList_Load_Basket(g.basket:basket_id, l.settings:basketitems)" />
                              <mvt:foreach iterator="basket_item" array="basketitems">
                                 <mvt:if expr=" ( '|' $ l.settings:basket_item:code $ '|') CIN l.product_codes AND (ISNULL l.settings:shippingmethods) ">
                                    <img src="/images/stop.png" style="width: 100px;">
                              YOUR MESSAGE WILL GO HERE
                                 </mvt:if>
                              </mvt:foreach>
                              The code above will display a message if item BO-005 is anywhere in the cart and if there are no shipping methods displayed (i.e. Fallback Method). If you don't need the shipping part, remove " AND (ISNULL l.settings:shippingmethods)".

                              I put this in my OSEL Checkout: Shipping/Payment Selection page.

                              If you want to use this for yourself, either substitute BO-005 for your single product code above, or for multiple products, use the following, as in Bruce's example:

                              Code:
                              <mvt:assign name="l.product_codes" value=" '|CODE1|CODE2|CODE3|' " />
                              <mvt:do file="g.Module_Library_DB" name="l.success" value="BasketItemList_Load_Basket(g.basket:basket_id, l.settings:basketitems)" />
                              <mvt:foreach iterator="basket_item" array="basketitems">
                                 <mvt:if expr=" ( '|' $ l.settings:basket_item:code $ '|') CIN l.product_codes ">
                              YOUR MESSAGE WILL GO HERE
                                 </mvt:if>
                              </mvt:foreach>

                              Comment

                              Working...
                              X