prestashop创建购物车并以编程方式添加产品[重复]

This question already has an answer here:

I am trying to create a simple task as follows:
1. Write a custom controller
2. create a cart if it is not created
3. add a product to the cart

came accross this code that is similar.

I need to know a few things:
1. In which folder should i place my custom controller?
2. Which parent controller class should my controller extend?
3. what will be the url for the controller?

</div>

It depends on when you want this action to happen. Like always with prestashop, you have 2 possibilities :

Override an existing controller

For example if you want to add a product to the cart everytime its created, you might want to override CartController. In that case here is the answers to your questions :

  1. In the override/controllers folder.
  2. The parent controller you chose, for example CartControllerCore
  3. The same as the parent controller. Check the official doc about the dispatcher, it's pretty usefull

Create you own module

I think this is the best choice if you want to have a real control over when you trigger this action.

  1. In the modules/you_module/controllers folder. The official doc is also a great place to start.
  2. ModuleFrontController
  3. Refer to the page about the dispatcher I gave you above, but the best way to trigger your action is to use the hook system.