public function processGenerate() { if (!is_array(Tools::getValue('options'))) { $this->errors[] = Tools::displayError('Please select at least one attribute.'); } else { $tab = array_values(Tools::getValue('options')); if (count($tab) && Validate::isLoadedObject($this->product)) { AdminAttributeGeneratorController::setAttributesImpacts($this->product->id, $tab); $this->combinations = array_values(AdminAttributeGeneratorController::createCombinations($tab)); $values = array_values(array_map(array($this, 'addAttribute'), $this->combinations)); // @since 1.5.0 if ($this->product->depends_on_stock == 0) { $attributes = Product::getProductAttributesIds($this->product->id, true); foreach ($attributes as $attribute) { StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], Context::getContext()->shop); } } SpecificPriceRule::disableAnyApplication(); $this->product->deleteProductAttributes(); $this->product->generateMultipleCombinations($values, $this->combinations); // Reset cached default attribute for the product and get a new one Product::getDefaultAttribute($this->product->id, 0, true); Product::updateDefaultAttribute($this->product->id); // @since 1.5.0 if ($this->product->depends_on_stock == 0) { $attributes = Product::getProductAttributesIds($this->product->id, true); $quantity = (int) Tools::getValue('quantity'); foreach ($attributes as $attribute) { if (Shop::getContext() == Shop::CONTEXT_ALL) { $shops_list = Shop::getShops(); if (is_array($shops_list)) { foreach ($shops_list as $current_shop) { if (isset($current_shop['id_shop']) && (int) $current_shop['id_shop'] > 0) { StockAvailable::setQuantity($this->product->id, (int) $attribute['id_product_attribute'], $quantity, (int) $current_shop['id_shop']); } } } } else { StockAvailable::setQuantity($this->product->id, (int) $attribute['id_product_attribute'], $quantity); } } } else { StockAvailable::synchronize($this->product->id); } SpecificPriceRule::enableAnyApplication(); SpecificPriceRule::applyAllRules(array((int) $this->product->id)); Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&key_tab=Combinations&conf=4'); } else { $this->errors[] = Tools::displayError('Unable to initialize these parameters. A combination is missing or an object cannot be loaded.'); } } }
public function initContent() { if (!Combination::isFeatureActive()) { $this->displayWarning($this->l('This feature has been disabled, you can activate it at:') . ' <a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->l('Performance') . '</a>'); return; } // Init toolbar $this->initToolbarTitle(); $this->initToolbar(); $this->initGroupTable(); $js_attributes = AdminAttributeGeneratorController::displayAndReturnAttributeJs(); $attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id); $this->product = new Product((int) Tools::getValue('id_product')); $this->context->smarty->assign(array('tax_rates' => $this->product->getTaxesRate(), 'generate' => isset($_POST['generate']) && !count($this->errors), 'combinations_size' => count($this->combinations), 'product_name' => $this->product->name[$this->context->language->id], 'product_reference' => $this->product->reference, 'url_generator' => self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&attributegenerator&token=' . Tools::getValue('token'), 'attribute_groups' => $attribute_groups, 'attribute_js' => $js_attributes, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => true, 'title' => $this->toolbar_title)); }
public function initGroupTable() { $combinations_groups = $this->product->getAttributesGroups($this->context->language->id); $attributes = array(); $impacts = AdminAttributeGeneratorController::getAttributesImpacts($this->product->id); foreach ($combinations_groups as &$combination) { $target =& $attributes[$combination['id_attribute_group']][$combination['id_attribute']]; $target = $combination; if (isset($impacts[$combination['id_attribute']])) { $target['price'] = $impacts[$combination['id_attribute']]['price']; $target['weight'] = $impacts[$combination['id_attribute']]['weight']; } } $this->context->smarty->assign(array('currency_sign' => $this->context->currency->sign, 'weight_unit' => Configuration::get('PS_WEIGHT_UNIT'), 'attributes' => $attributes)); }