Jump to content

Where is the code that is triggered when adding to cart?


Allon

Recommended Posts

I have been searching everywhere for documentation that explains what happens in the code when I click on the add to cart button.

 

The reason I need this is as we made a change to the order process, the default product info and customizable info is on the same page. Once the visitor fills in that form and clicks on add to cart the cart is is displayed and only shows the default info. Same in the backend, its as if the additional info is not processed.

 

I am new to prestashop and would like to learn what happens here behind the scenes in order to troubleshoot this.

 

Any assistance and a push in the right direction would be appreciated.

 

Thanks!

Link to comment
Share on other sites

take a look how the url add to cart looks like:

index.php?controller=cart&add=1&id_product=2&token=XXXXX

it mean that add to cart button uses: CartController: /controllers/front/CartController.php

this is file where the whole add to cart code is

Link to comment
Share on other sites

Ok, I followed the code and found myself in CartRule.php where the db queries are happening. (Really wish there was or I knew where there was documentation on this)

 

So I am trying to figure out why customized fields are not being added to the cart. 

 

If anyone knows of documentation for the whole add to cart code logic and related then please let me know. Would save me a ton of time.

Also, any assistance on the process of adding products to cart that are customized, specifically if anything different happens in the backend for these fields, that would be appreciated.

 

I am digging into the code and will probably figure it out eventually but some documentation or assistance may save me more than just a few hours :)

 

Thanks!

Link to comment
Share on other sites

there is no documentation related to detailed description about PrestaShop classes.

usually, above each function you've got short class description + variables infromations. And that's all.

 

CartRule class is a class for voucher codes and quantity reduction prices. Is not related to "add to cart" action.

Add to cart action is a part of Cart.php class.

 

The main file for you is CartController.php (controllers/front/CartController.php)

 

you've got there postProcess function

if (Tools::getIsset('add') || Tools::getIsset('update'))
				$this->processChangeProductInCart();
			elseif (Tools::getIsset('delete'))
				$this->processDeleteProductInCart();
			elseif (Tools::getIsset('changeAddressDelivery'))
				$this->processChangeProductAddressDelivery();
			elseif (Tools::getIsset('allowSeperatedPackage'))
				$this->processAllowSeperatedPackage();
			elseif (Tools::getIsset('duplicate'))
				$this->processDuplicateProduct();

all of functions above (processDuplocateProduct, ProcessChangeInCart, ...) are located in Cart.php class (classes/Cart.php) and these functions are functions that you're looking for.

 

/**
* This process add or update a product in the cart
*/

check especially function processChangeProductInCart()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...