Newls Posted September 26, 2013 Share Posted September 26, 2013 (edited) Hi People, I have a questions to you experienced prestashop developers ! How do I create a new Product Pack using the ObjectModel ? (I don't see any Method in ProductCore class) ? Thanks for reading ! Newls Edited September 26, 2013 by Newls (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted September 26, 2013 Share Posted September 26, 2013 Hi Newls, Probably using classes/Pack.php... pascal Link to comment Share on other sites More sharing options...
Newls Posted September 26, 2013 Author Share Posted September 26, 2013 Hi PascalVG, More specifically, When I instanciate a new Product Object, I'd like to know how to set it as a Pack ! I already looked around the Pack class but it looks like an extension (in usage i mean) of Product class Link to comment Share on other sites More sharing options...
PascalVG Posted September 26, 2013 Share Posted September 26, 2013 It's an attribute of Product: 'type' => array( 'getter' => 'getWsType', 'setter' => 'setWsType', ), Which can have three values: const PTYPE_SIMPLE = 0; const PTYPE_PACK = 1; const PTYPE_VIRTUAL = 2; You can check what type is is with this function: public function getType() { if (!$this->id) return Product::PTYPE_SIMPLE; if (Pack::isPack($this->id)) return Product::PTYPE_PACK; if ($this->is_virtual) return Product::PTYPE_VIRTUAL; return Product::PTYPE_SIMPLE; } If it's a pack, the product is registered in the table ps_pack as well, so you can also use this function to check if a product is a pack in Pack.php: public static function isPack($id_product) { if (!Pack::isFeatureActive()) return false; if (!$id_product) return false; if (!array_key_exists($id_product, self::$cacheIsPack)) { $result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)$id_product); self::$cacheIsPack[$id_product] = ($result > 0); } return self::$cacheIsPack[$id_product]; } Hope this helps, pascal 1 Link to comment Share on other sites More sharing options...
Newls Posted September 26, 2013 Author Share Posted September 26, 2013 (edited) Thanks PascalVG ! This helped in fact ! Finally, I just create a new Product and ->save() it, then I call Pack::AddItem() giving the new product's (the pack freshly created) ID as first argument, and then what I want to add in it. It automatically set the product as a pack because of the way Pack::isPack() is coded ! I set this topic on solved. Thanks again ! Edited September 26, 2013 by Newls (see edit history) 1 Link to comment Share on other sites More sharing options...
PascalVG Posted September 26, 2013 Share Posted September 26, 2013 Glad you made it work! Happy selling, pascal Link to comment Share on other sites More sharing options...
dolec Posted March 24, 2020 Share Posted March 24, 2020 I want to show image of main product pack in all pack items which are in pack how can i check the main pack item id or get the image url of main pack product in "child" pack products in tpl? 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