PawelTR Posted February 11, 2020 Share Posted February 11, 2020 (edited) Hello, I try write module which limit cart. I mean limit: - max 10 pieces of single product in one order - max 1 pieces of single product which in database have flag "deficit" This things i have check when user adding product to cart. When user adding product with quantity >= 10 or deficyt product >1 then i need show message with information. I have code: public function hookActionBeforeCartUpdateQty($params) { $product = $params['product']; $quantity = $params['quantity']; echo '<pre>'; echo 'Product name: ' . $product->name . '<br />'; echo 'Product id: ' . $product->id . '<br />'; echo 'Quantity' .$quantity; echo '</pre>'; if($quantity >=10) { return false; } } but not working, when i add product with qunantity >=10, product is added successfully, this is my first problem. My second problem is that I want to write a module that will develop a product that will have flags: - 1 item per day for 1 user - 1 item per week for 1 user - 1 item per month for 1 user And I would like to check it when adding it to the cart, but it can't be done because I can't check if a person who has not logged in has already bought the product, he must be logged in, so I am looking for ideas on how to solve it. Edited February 15, 2020 by PawelTR (see edit history) Link to comment Share on other sites More sharing options...
PawelTR Posted February 12, 2020 Author Share Posted February 12, 2020 No idea? Link to comment Share on other sites More sharing options...
PawelTR Posted February 12, 2020 Author Share Posted February 12, 2020 Hi @ndiaga thank for answer :) I'm trying to write my own basket module, but I have no idea where to start and what it should look like :( Link to comment Share on other sites More sharing options...
PawelTR Posted February 12, 2020 Author Share Posted February 12, 2020 In my case it will probably be ps_shoppingcart Link to comment Share on other sites More sharing options...
PawelTR Posted February 13, 2020 Author Share Posted February 13, 2020 @ndiaga How can i override CartController in my custom module? Link to comment Share on other sites More sharing options...
PawelTR Posted February 13, 2020 Author Share Posted February 13, 2020 (edited) @ndiaga I copy CartController to override/controllers/front in my module and add this code for him: <?php use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter; class CartController extends CartControllerCore { public $php_self = 'cart'; public function init() { parent::init(); $this->qty = abs(Tools::getValue('qty', 1)); var_dump(1); if ($this->qty >= 2) { #How can i show notification? } } } all works fine, but how i can show for example js message when $this->qty is > = 2 ?? Edited February 13, 2020 by PawelTR (see edit history) Link to comment Share on other sites More sharing options...
ventura Posted February 14, 2020 Share Posted February 14, 2020 /controllers/front/CartController.php In function processChangeProductInCart() Add this if ($qty_to_check >= 10) { $this->errors[] = $this->trans( 'The maximun purchase for the product %product% may not exceed %quantity%.', array('%product%' => $product->name, '%quantity%' => 9), 'Shop.Notifications.Error' ); return; } Result Link to comment Share on other sites More sharing options...
PawelTR Posted February 14, 2020 Author Share Posted February 14, 2020 @ventura I added. and on network shows me the error but not at the front. 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