vmiloykov Posted January 17, 2014 Share Posted January 17, 2014 Hello, I am new in using PrestaShop and I have one question: I want to set maximum allow products. Example: I sete somewhere in code maximum allow products to be 2 and when I try to upload 3-th product system need to give me a sometype of error. How this can be did? Link to comment Share on other sites More sharing options...
vmiloykov Posted January 18, 2014 Author Share Posted January 18, 2014 Could somebody help me? Link to comment Share on other sites More sharing options...
limon994 Posted January 19, 2014 Share Posted January 19, 2014 Hello, If I am not wrong you mean "upload" = "add to cart". If that is the case then you have to hack the prestashop code. There is no maximum limit for a product purchased but have option minimum. Thanks, Link to comment Share on other sites More sharing options...
vmiloykov Posted January 19, 2014 Author Share Posted January 19, 2014 Hello, If I am not wrong you mean "upload" = "add to cart". If that is the case then you have to hack the prestashop code. There is no maximum limit for a product purchased but have option minimum. Thanks, Hello, No, I do not mean upload = add to cart. I mean limited on products in my shop. I want to set limited of product which can be in my shop. Link to comment Share on other sites More sharing options...
limon994 Posted January 19, 2014 Share Posted January 19, 2014 Oh, Yes in that case you can do that by a module which will take information from you about the number of product to be uploaded/added to your store and when you add a product it will check the total number of products in your shop and if it exceeds your limit then will show a warning. You need to implement a module which will have to have the hook 'addProduct' registered. PM me. Thanks, Link to comment Share on other sites More sharing options...
vmiloykov Posted January 19, 2014 Author Share Posted January 19, 2014 Oh, Yes in that case you can do that by a module which will take information from you about the number of product to be uploaded/added to your store and when you add a product it will check the total number of products in your shop and if it exceeds your limit then will show a warning. You need to implement a module which will have to have the hook 'addProduct' registered. PM me. Thanks, I wrote you. Link to comment Share on other sites More sharing options...
vekia Posted January 19, 2014 Share Posted January 19, 2014 you don't have to use module for that. you can use simple modification of core - Product class. it's necessary to modify the public function add() there. public function add($autodate = true, $null_values = false) { if (!parent::add($autodate, $null_values)) return false; if ($this->getType() == Product::PTYPE_VIRTUAL) StockAvailable::setProductOutOfStock((int)$this->id, 1); else StockAvailable::setProductOutOfStock((int)$this->id, 2); $this->setGroupReduction(); Hook::exec('actionProductSave', array('id_product' => $this->id)); return true; } add there simple product counter, then add if condition. i f ($counter >=3){ return false; } else { if (!parent::add($autodate, $null_values)) return false; if ($this->getType() == Product::PTYPE_VIRTUAL) StockAvailable::setProductOutOfStock((int)$this->id, 1); else StockAvailable::setProductOutOfStock((int)$this->id, 2); $this->setGroupReduction(); Hook::exec('actionProductSave', array('id_product' => $this->id)); return true; [spam-filter] 1 Link to comment Share on other sites More sharing options...
vmiloykov Posted January 19, 2014 Author Share Posted January 19, 2014 you don't have to use module for that. you can use simple modification of core - Product class. it's necessary to modify the public function add() there. public function add($autodate = true, $null_values = false) { if (!parent::add($autodate, $null_values)) return false; if ($this->getType() == Product::PTYPE_VIRTUAL) StockAvailable::setProductOutOfStock((int)$this->id, 1); else StockAvailable::setProductOutOfStock((int)$this->id, 2); $this->setGroupReduction(); Hook::exec('actionProductSave', array('id_product' => $this->id)); return true; } add there simple product counter, then add if condition. i f ($counter >=3){ return false; } else { if (!parent::add($autodate, $null_values)) return false; if ($this->getType() == Product::PTYPE_VIRTUAL) StockAvailable::setProductOutOfStock((int)$this->id, 1); else StockAvailable::setProductOutOfStock((int)$this->id, 2); $this->setGroupReduction(); Hook::exec('actionProductSave', array('id_product' => $this->id)); return true; [spam-filter] When I add your code and open in web page with products give me blank page, when I remove it - its ok. Could you tell me why and how to fixed it? Link to comment Share on other sites More sharing options...
limon994 Posted January 20, 2014 Share Posted January 20, 2014 Hello, Thanks @Vekia for your comment. I actually think about module so that the shop owner in future can update his prestashop version with the latest release. I know prestashop has the override Classes and Controllers facilities but a module would be more handy if he want to change the amount of product in later. For example Initially the shop owner want to allow 20 products. So he have to write in the code according to 20. After a few days he want to change his business policy and want to allow 50 products. In that time he has to again edit that file. But If he use a module which has configure facility in the back office then he can do that easily with out knowing about the programming. Thanks, Link to comment Share on other sites More sharing options...
vekia Posted January 20, 2014 Share Posted January 20, 2014 i don't know what code you used exactly. i just show you how to achieve what you want to expect. Link to comment Share on other sites More sharing options...
vmiloykov Posted January 20, 2014 Author Share Posted January 20, 2014 i don't know what code you used exactly. i just show you how to achieve what you want to expect. This is code from presta about function add from Product class: public function add($autodate = true, $null_values = false) { if (!parent::add($autodate, $null_values)) return false; if ($this->getType() == Product::PTYPE_VIRTUAL) StockAvailable::setProductOutOfStock((int)$this->id, 1); else StockAvailable::setProductOutOfStock((int)$this->id, 2); $this->setGroupReduction(); Hook::exec('actionProductSave', array('id_product' => $this->id)); return true; } Link to comment Share on other sites More sharing options...
3dreams Posted March 8, 2015 Share Posted March 8, 2015 (edited) hi , does anyone know how to be this code in version 1.6 , as it works up to version 1.5? Edited March 8, 2015 by 3dreams (see edit history) 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