Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / force add items to create new item in shopping cart and not update the current qty.

force add items to create new item in shopping cart and not update the current qty.

Started by nazca on 14 Jan 2014, 12:24 AM · Views: 1,517

Results 1 to 5 of 5
14 Jan 2014, 12:24 AM
#1
nazca avatar

nazca

New Zenner

Join Date:
Aug 2013
Location:
California
Posts:
22
Plugin Contributions:
0

Post #1 by nazca

Can any one point me in the correct direction?
The default way the shopping cart works is when you add an item to your shopping cart it just adds it. If you go back into the store and select the same item again it just updates the quantity in the shopping cart. This behavior is undesirable in my store as I have custom code that allows users to customize their items.

When a user customizes their items it counts as a "new" item as far as pricing goes.  But because this is the same item in the shopping cart - zen cart just updates the quantity.  Therefor giving them a discount that the customer no longers should receive.
 
I have tried editing the following.
in includes/classes/shopping_cart.php
changing
```

if ($this->in_cart($products_id)) {

  	to ```
if (1 === 2) {       
This was an attempt to force this if statement to be false - theoretically forcing a new item in the cart.  However, this just failed to add a new item and failed to update the quantity.
I have also tried changing the line below it from
```
$this->update_quantity($products_id, $qty, $attributes);
  	 
  	to ```
 add_cart($products_id, $qty, $attributes, $notify);
But, this just fails as it causes a weird loop and wasn't very smart of me.
 
I tried adding
```
$this->contents[] = array($products_id);
      $this->contents[$products_id] = array('qty' => (float)$qty);
      // insert into database
      if (isset($_SESSION['customer_id'])) {
        $sql = "insert into " . TABLE_CUSTOMERS_BASKET . "
                              (customers_id, products_id, customers_basket_quantity,
                              customers_basket_date_added)
                              values ('" . (int)$_SESSION['customer_id'] . "', '" . zen_db_input($products_id) . "', '" .
        $qty . "', '" . date('Ymd') . "')";

        $db->Execute($sql);
  	 
  	in the "true" side of ```
if ($this->in_cart($products_id)) {   
But it just caused a white screen.
 
Not really sure where to go =[
14 Jan 2014, 3:53 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #2 by gjh42

custom code that allows users to customize their items. Does this mean that you are not using attributes to do the customization? If you add a product with one set of attribute selection to the cart and then add it with a different set of attributes (even different text in one attribute), you will get two items in the cart. If you add the product again with the same attributes, you will get qty 2 of that item.

Apparently your custom code does not tie into the attribute system.

Seeing your setup and understanding how it operates will probably be necessary before we can help you.

14 Jan 2014, 5:34 PM
#3
nazca avatar

nazca

New Zenner

Join Date:
Aug 2013
Location:
California
Posts:
22
Plugin Contributions:
0

Post #3 by nazca

Correct, it does not tie into the attributes system.

15 Jan 2014, 3:17 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #5 by gjh42

You refer to quantity discounts in a way that suggests that it is possible to have multiples of one item (and be treated specially), so it could not work to just force all items added to cart to create new entries. You have to distinguish between duplicates and customized versions of a product, the same way as attributes do. So how does your code do that?