Forums / General Questions / Preventing 2 products to be bought together shopping cart

Preventing 2 products to be bought together shopping cart

Started by alexthibo on 12 Nov 2013, 2:42 AM · Views: 968

Results 1 to 6 of 6
12 Nov 2013, 2:42 AM
#1
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Preventing 2 products to be bought together shopping cart

How can I prevent a customer from adding a specific product to their shopping cart if they already have another specific product in their cart.

Products are member cards with different privileges. if one is already in their cart they should be blocked from adding another member card in it.

I searched on the forum but can't find any discussion discussions on this.

12 Nov 2013, 4:09 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Preventing 2 products to be bought together shopping cart

AlexThibo:

How can I prevent a customer from adding a specific product to their shopping cart if they already have another specific product in their cart.

Products are member cards with different privileges. if one is already in their cart they should be blocked from adding another member card in it.

I searched on the forum but can't find any discussion discussions on this.

If not mistaken this is along the lines of I think the FAQ talking about buy one get one free, or similar. The thing is that in contrast of adding an item if there is an item, you are wanting to dump/disallow an item if there is already something present.

Couple of questions related to this, do you require users to be logged in before they are able to add things to a cart? If not, how do you plan on handling the case of someone adds to their cart before login, they go to pay/login and find out that the same or a "competitive" product is already in the cart or has already been purchased (assuming the later is an option)?

I would think that something related to cart processing should review the shopper's history/cart, identify the contents of the cart/purchase history and if there is a conflict to dump/prevent adding the most recently added item and notifier the user about the action with some sort of useful/meaningful info.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Nov 2013, 9:28 AM
#3
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: Preventing 2 products to be bought together shopping cart

Easier that this, a verification is already done when you add a product to the cart. There's a maximum of 1 member card that can currently be bought. Preventing the customer to add a second card if they continue shopping after having add one then want to come back to their shopping cart, but click on the product in the shopping cart instead of clicking on the "Shopping cart" header of the side block and add the cart again thinking it'sthe way to restart the checkout process. Some test customers did it so by placing "1" as a maximum quantity of the product it prevent that mistake.

So i suspect that there's a condition in the code that compare what's in the shopping cart with the product you're adding. I think asking for a second verification should be around this.

And when you log in it already add your products in your pending shopping cart and give you an error message if you already have the card in your cart. Same process there.

But how to implement this only for this product?

12 Nov 2013, 1:12 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Preventing 2 products to be bought together shopping cart

AlexThibo:

Easier that this, a verification is already done when you add a product to the cart. There's a maximum of 1 member card that can currently be bought. Preventing the customer to add a second card if they continue shopping after having add one then want to come back to their shopping cart, but click on the product in the shopping cart instead of clicking on the "Shopping cart" header of the side block and add the cart again thinking it'sthe way to restart the checkout process. Some test customers did it so by placing "1" as a maximum quantity of the product it prevent that mistake.

So i suspect that there's a condition in the code that compare what's in the shopping cart with the product you're adding. I think asking for a second verification should be around this.

And when you log in it already add your products in your pending shopping cart and give you an error message if you already have the card in your cart. Same process there.

But how to implement this only for this product?

Sounds like a reasonable location to add such a check. Well, unfortunately at the moment I can't hunt that down for you, but might be able to provide some tools on how to track down areas of interest. First of all, I'm thinking that there are parts that get put together to perform the test. You may need to approach the search from two directions if someone doesn't tell you in which file(s) the applicable data is as part of the add-to-cart process.

I will say, that it seems if you hang on the maximum number of a product for these "cards" with the expectation that these cards can only be included 1 time (and not multiple and no foreseeable need to program for the possibility of multiple count but a strict maximum of combined or individual quantity of a product), that the complexity of your comparison increases. At the moment the real concern appears to be if this product is in the cart, and this product is added, then bounce out the added product. Which really could be written in a simpler fashion than maintaining a maximum quantity like comparison, though the maximum may still be necessary. Not sure if when selecting multiple quantity of a product if there is an add loop that is gone through or if the new quantity is just pushed onto the cart assuming it meets all other add criteria. The point there was that if the cart contains product_id (x,y, or z) and add to cart variable contains product_id (x,y, or z) then don't add to cart when the add-to-cart button is pressed.

But, if you are hung on the maximum quantity comparison, then you will need to in this comaritor area check not only if the added new product exceeds it's maximum quantity, but that if the sum of this product and a specific second product exceed some yet undisclosed quantity or, allow both products to be added until the one product is at it's maximum and then can not add any more of the one, but can still add the other because it is not yet at it's maximum, or, or, or... If coding on the maximum, please remember to consider all variations of meeting, attempting to exceed, and not yet at the maximum value for each product and combination of products. Otherwise, one day you may try to use a max of 2 of something and it could all fall apart.

But if you wish to continue down the original path, some things of import, you will be looking for comparison made to the database field that identifies the maximum number of products allowed, you will more than likely be looking for the variable $cart I think it is (or a reassignment of that variable to something "shorter") a field that I think is like 'product_max_quantity' though would have to look through the various mysql table's or view the code of the product page which when add to cart is pressed kicks off into the various modules and template files to process the request. (See the form action associated with the add-to-cart button when on the product page. This will/should lead to the next file to be loaded/reference the next thing to happen and then down into the rabbit hole you go.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

13 Nov 2013, 1:21 AM
#5
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: Preventing 2 products to be bought together shopping cart

And why not simply put a maximum of 1 product of the same category on the cart since all the cards are in the Member Cards category?

When you put a maximum of x product_id in the cart, I suppose it's doing a loop counting x time for each product_id in the cart. Why not make the same loop looking for x product of this category_id in the cart? Then replace X by 1?

13 Nov 2013, 1:37 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Preventing 2 products to be bought together shopping cart

AlexThibo:

Easier that this, a verification is already done when you add a product to the cart. There's a maximum of 1 member card that can currently be bought. Preventing the customer to add a second card if they continue shopping after having add one then want to come back to their shopping cart, but click on the product in the shopping cart instead of clicking on the "Shopping cart" header of the side block and add the cart again thinking it'sthe way to restart the checkout process. Some test customers did it so by placing "1" as a maximum quantity of the product it prevent that mistake.

So i suspect that there's a condition in the code that compare what's in the shopping cart with the product you're adding. I think asking for a second verification should be around this.

And when you log in it already add your products in your pending shopping cart and give you an error message if you already have the card in your cart. Same process there.

But how to implement this only for this product?

So I believe the area of work would be in the following file:
**includes/classes/shopping_cart.php
**
It seems to contain the product variable 'products_quantity_order_max' which is the variable that you had said was set to 1 and worked at least for the single card. You would be working in that source code; however, I am not sure which function(s) would need to be adjusted to ensure capturing the desired actions, but there ya go, it at least narrows down the files to one instead of 3000+ :)

You might be able to use: $_POST['products_id']) == X (Where X is one of your cards) or could assign an array $X that is equal to all of your cards, and that as part of the comparison/data collection, and I forget the actual command, but if the post is in the array and an item in the array is already in the cart, to bypass adding the item(s) to the cart. Now I'm not sure what handles which of the many functions inside of that file so that you can make the adjustment(s) desired/needed. Again, I might reference the help file about BOGO or similar actions because I thought it addresses at least which function(s) to modify. But I could be wrong.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...