Today we will learn about how Opencart adds product to the cart when we click on the “Add To Cart” button. In Opencart there is two process one runs at Search, Category, Manufacturer etc pages and another runs at the particular product page.
In the Search page Opencart calls a function name “add” to add product to the cart. This “add” function is written in the common.js file. “cart” is a object of having add, update, remove functions.
After that Opencart makes a Ajax call to the “checkout/cart/add” controller to checks whether the product has required option, if presents then Opencart redirect to that particular product page to choose the required option.
If not then simply adds that product to the cart.
In particular product page Opencart makes the same Ajax call to check the required function so main difference is that Opencart does not call the “add” function instead of direct calls the “checkout/cart/add” controller. If there product has required option the product does not added to the cart until the required option is chosen.