Zen Cart Logo
Forums / General Questions / Updating the Shopping Cart

Updating the Shopping Cart

Views: 704

Results 1 to 4 of 4
4 Mar 2011, 1:52 AM
#1
ekon79 avatar

ekon79

New Zenner

Join Date:
Jan 2011
Posts:
29
Plugin Contributions:
0

Updating the Shopping Cart

Hi Everyone,

Hoping someone can shed some light. I have made one modification to the display of the shopping cart and I need to know which one is the file that gets executed when the user clicks on "Update Shopping cart" button. I know there is the shopping_cart.php file under the class directory, but I see that file has mainly a bunch of functions that get executed depending on who's calling them. I am interested to know the file that calls the update_quantity or add_cart method, specifically, for example, given the following scenario, a user updates the cart to reflect that he/she wants to buy 5 quantities of a product, how does the shopping_cart.php file know that any of these two methods need to be executed (I am assuming is one of those two methods that will get executed) with a value of 5 for the quantity, what file is saying "the shopping cart needs to be updated with a new quantity of 5".

Many thanks.

4 Mar 2011, 5:26 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Updating the Shopping Cart

What issue are you trying to alter effect?
Explain what it is you are attempting to change

4 Mar 2011, 6:53 PM
#3
ekon79 avatar

ekon79

New Zenner

Join Date:
Jan 2011
Posts:
29
Plugin Contributions:
0

Re: Updating the Shopping Cart

OK, so I have added an extra column to the shopping cart, a "size" column. With this size column, I have also added a drop-down menu that by default will show the size of the clothing the customer has chosen. So, everytime the customer adds a new item to the shopping cart, the column will show a drop down menu with the size that was chosen visible by default. If the customer changes his/her mind about the size he/she selected, I want them to just pull the drop-down menu and select another size right there on the shopping cart page. Right now, I am able to get the value of the new size by doing a $new_size = _$POST['size_chosen], however, I am struggling with what to do after I have gotten that value.
I see there is a file, main_cart_actions.php that executes an "actionUpdateProduct" if the customer clicks updates the product quantity, so I am guessing this is the method I would need to look at within the shopping_cart.php.

I see where the quantity is getting updated

$new_qty = $this->adjust_quantity($new_qty, $_POST['products_id'][$i], 'shopping_cart');

and then a little further underneath that, I see that something is being done with the attributes, but I am unable to decipher this to see how would I be able to put my new attribute size in there...

$attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';

Ideally I was hoping that I could just update a specific table or something like that and be done with it, so, I was looking at the customer_basket table, but I noticed something peculiar, I noticed that even though I had just placed a pair of pants in the shopping cart, this customer basket table was empty, so this led me to believe something else is going on in the background.

As it is, if I pull the drop-down menu and choose another different size that the one it's currently there, and select another quantity and click on the update button, zencart will update the shopping cart to reflect the new total, and the size column will be refreshed with the old_size, so this value is being held somewhere, that's what I haven't figured out yet...

In the tpl_shopping_cart_default.php, I place as the default value for the size pull down menu whatever I get from $product['attributes'] as $option => $value, then check if the option is "size" and then doing a $value['products_options_values_name'].

Then again, I could be completely off track with the way I'm going about this. I know I also need to worry about whether or not the new attribute was indeed commited by zencart if the customer simply chooses to checkout, without clicking the "update" button below the shopping cart table.

I am still investigating but any little help will be really appreciated. I've looked at the Edit Cart mod to see if I could see any pointers from the mod's files on how things could be done, but unfortunately I haven't gotten anywhere with it.

Another idea I was thinking about was just to use the same code that zen cart uses to populate the drop down menu in the product page for the size attribute of the product, but I haven't really explored yet how zen cart goes about it to begin with.

Thanks for reading.

4 Mar 2011, 8:57 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Updating the Shopping Cart

Look at the files that control the product info page and the attributes associated with them
Then you will want to add the attribute function to a copy of
tpl_shopping_cart_default.php

Try to use existing code blocks from other pages that already exist to perform these functions

The cart table saves a customer cart if they logout before completing a purchase - otherwise this info is stored in the customers session variable