/** * delete all items in pack, then check if type_product value is 2. * if yes, add the pack items from input "inputPackItems" * * @param Product $product * @return boolean */ public function updatePackItems($product) { Pack::deleteItems($product->id); // lines format: QTY x ID-QTY x ID if (Tools::getValue('type_product') == Product::PTYPE_PACK) { $product->setDefaultAttribute(0); //reset cache_default_attribute $items = Tools::getValue('inputPackItems'); $lines = array_unique(explode('-', $items)); // lines is an array of string with format : QTYxID if (count($lines)) { foreach ($lines as $line) { if (!empty($line)) { list($qty, $item_id) = explode('x', $line); if ($qty > 0 && isset($item_id)) { if (Pack::isPack((int) $item_id)) { $this->errors[] = Tools::displayError('You can\'t add product packs into a pack'); } elseif (!Pack::addItem((int) $product->id, (int) $item_id, (int) $qty)) { $this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.'); } } } } } } }
public function updatePackItems($product) { Pack::deleteItems($product->id); // lines format: QTY x ID-QTY x ID if (Tools::getValue('ppack') and $items = Tools::getValue('inputPackItems') and sizeof($lines = array_unique(explode('-', $items)))) { foreach ($lines as $line) { // line format QTY x ID list($qty, $item_id) = explode('x', $line); if ($qty > 0 && isset($item_id)) { if (!Pack::addItem((int) $product->id, (int) $item_id, (int) $qty)) { return false; } } } } return true; }
/** * delete all items in pack, then check if type_product value is 2. * if yes, add the pack items from input "inputPackItems" * * @param Product $product * @return boolean */ public function updatePackItems($product) { Pack::deleteItems($product->id); // lines format: QTY x ID-QTY x ID if (Tools::getValue('type_product') == Product::PTYPE_PACK) { $items = Tools::getValue('inputPackItems'); $lines = array_unique(explode('-', $items)); // lines is an array of string with format : QTYxID if (count($lines)) { foreach ($lines as $line) { if (!empty($line)) { list($qty, $item_id) = explode('x', $line); if ($qty > 0 && isset($item_id)) { if (!Pack::addItem((int) $product->id, (int) $item_id, (int) $qty)) { $this->errors[] = Tools::displayError('An error occurred while adding products to the pack.'); } } } } } } }
public function setWsProductBundle($items) { if ($this->is_virtual) { return false; } Pack::deleteItems($this->id); foreach ($items as $item) { if ((int) $item['id'] > 0) { Pack::addItem($this->id, (int) $item['id'], (int) $item['quantity']); } } return true; }
protected function importProductsPacks() { $this->truncateTables(array('pack')); $handle = $this->openCsvFile('product_packs.csv'); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) { Pack::addItem($line[0], $line[1], $line[3], $line[2]); } $this->closeCsvFile($handle); return true; }