king2 Posted June 13, 2013 Share Posted June 13, 2013 Hello to all and developers! First, thank you for perfect product made using brains I have to make a shop with bundle items, and I need to create about 1000 products in a 160 bundles, so I decided to use REST API, added all simple products, everything was OK. But when I started to adding bundle (pack) items, I've met a problem. It tells me no error while I trying to add bundled products inside associations->product_bundle, but created product have 'simple' type and no references was created in ps_pack table. I have tried to set cache_is_pack=1 (what this?), with no success (it just ignores it). It cannot get type=pack|simple, because of read-only property (it has no setter for this). I have looked into code and as I can understand, it has no code inside to make pack product via WebService. So, question is: May be I missed something and I can create bundle product with WS? May be there is a workaround for this? Thank you in advance! Link to comment Share on other sites More sharing options...
king2 Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) I have read documentation about overrides, and made a little workaround for saving bundles (save file as /override/classes/Product.php): <?php class Product extends ProductCore { public function setWsProductBundle($product_bundle) { Pack::deleteItems($this->id); if (count($product_bundle) > 0) { $this->setDefaultAttribute(0);//reset cache_default_attribute foreach ($product_bundle as $item) { if (!$item['id'] || !$item['quantity']) return false; if (!Pack::addItem((int)$this->id, (int)$item['id'], (int)$item['quantity'])) return false; } } return true; } } ?> At least, it works It creates pack items for a product if 'bundle_product' is set (cache_is_pack maintained inside Pack object automatically). With empty 'bundle_product' it turn product back to simple. Have I missed something important or does something wrong way (I'm newbie and have met Prestashop only two days ago)? Can you include this code to next versions of Prestashop if everything is OK with it? Thanks! p.s. something strange happens with formatting text in this forum.. Edited June 13, 2013 by king2 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts