dwdsaq2 Posted June 30 Share Posted June 30 <?php use Symfony\Component\HttpFoundation\JsonResponse; class ReaddToCartModuleFrontController extends ModuleFrontController { public $ajax = true; public function initContent() { parent::initContent(); $productId = Tools::getValue('id_product'); $quantity = Tools::getValue('qty', 1); // Debugging output error_log("Product ID: " . $productId); error_log("Quantity: " . $quantity); if (!$productId || !Validate::isUnsignedId($productId)) { error_log("Invalid product ID: " . $productId); $this->ajaxDie(json_encode(['success' => false, 'message' => 'Invalid product ID'])); } $cart = $this->context->cart; if (!$cart->id) { $cart->add(); $this->context->cookie->id_cart = $cart->id; } $updateQuantity = $cart->updateQty($quantity, $productId); if ($updateQuantity) { error_log("Product added to cart successfully"); $this->ajaxDie(json_encode(['success' => true, 'message' => 'Product added to cart'])); } else { error_log("Failed to add product to cart"); $this->ajaxDie(json_encode(['success' => false, 'message' => 'Failed to add product to cart'])); } } } Link to comment Share on other sites More sharing options...
Prestashop Addict Posted July 1 Share Posted July 1 It can depend on theme and/or cart module. Can you specify theme, PS version, PHP version and cart module used and its configuration. Link to comment Share on other sites More sharing options...
dwdsaq2 Posted July 2 Author Share Posted July 2 16 hours ago, Prestashop Addict said: It can depend on theme and/or cart module. Can you specify theme, PS version, PHP version and cart module used and its configuration. I'm not using any cart module but the original version PS 1.7, PHP 7.2 . Also is it possible to refresh just the cart and not the whole page? If possible what are the ways we can do that in prestashop? Link to comment Share on other sites More sharing options...
Prestashop Addict Posted July 2 Share Posted July 2 Il y a 1 heure, dwdsaq2 a dit : I'm not using any cart module but the original version PS 1.7, PHP 7.2 . Also is it possible to refresh just the cart and not the whole page? If possible what are the ways we can do that in prestashop? If you are using the Prestashop base and classic theme, the cart is managed by the module ps_shoppingcart. And you can set it to ajax mode or not. Link to comment Share on other sites More sharing options...
ps8modules Posted July 2 Share Posted July 2 (edited) @Prestashop Addict Add In the title of the topic, it is clearly specified that he wants to use his own module and update the cart. @dwdsaq2 Find jQuery prestashop.on('updateCart ... or prestashop.emit('updatedCart .... https://devdocs.prestashop-project.org/8/themes/reference/javascript-events/ Edited July 2 by ps8modules.com (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now