简体   繁体   中英

prestashop: How to add a product from a custom module to shopping cart

Is there any public function to add a product in to the shopping cart from a custom module? Or do I need to do some hard coding to achieve that? All the product info comes from a query, however im not able to figure out how to add it to the shopping cart.

Any ideas are welcome.

Okay I figured it out.

Here is the code for future generations who are going to need similar help.

    $Cart = $this->context->cart; // can be achieved through cookies aswell, a matter of opinion
    $Cart->updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM