public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array()) { $combination = new Combination($id_product_attribute); if (!$update_all_fields) { $combination->setFieldsToUpdate(array('price' => !is_null($price), 'wholesale_price' => !is_null($wholesale_price), 'ecotax' => !is_null($ecotax), 'weight' => !is_null($weight), 'unit_price_impact' => !is_null($unit), 'default_on' => !is_null($default), 'minimal_quantity' => !is_null($minimal_quantity), 'minimal_quantity_fractional' => !is_null($minimal_quantity), 'available_date' => !is_null($available_date))); } $price = str_replace(',', '.', $price); $weight = str_replace(',', '.', $weight); $combination->price = (double) $price; $combination->wholesale_price = (double) $wholesale_price; $combination->ecotax = (double) $ecotax; $combination->weight = (double) $weight; $combination->unit_price_impact = (double) $unit; $combination->reference = pSQL($reference); $combination->location = pSQL($location); $combination->ean13 = pSQL($ean13); $combination->upc = pSQL($upc); $combination->default_on = (int) $default; if ($combination->update_fields['minimal_quantity']) { $minimal_quantity = str_replace(',', '.', $minimal_quantity); $this->setMinQty($minimal_quantity, $combination); } $combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00'; if (count($id_shop_list)) { $combination->id_shop_list = $id_shop_list; } $combination->save(); if (is_array($id_images) && count($id_images)) { $combination->setImages($id_images); } $id_default_attribute = (int) Product::updateDefaultAttribute($this->id); if ($id_default_attribute) { $this->cache_default_attribute = $id_default_attribute; } Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => (int) $id_product_attribute)); Tools::clearColorListCache($this->id); return true; }
/** * Update a product attribute * * @param int $id_product_attribute Product attribute id * @param float $wholesale_price Wholesale price * @param float $price Additional price * @param float $weight Additional weight * @param float $unit * @param float $ecotax Additional ecotax * @param int $id_image Image id * @param string $reference Reference * @param string $ean13 Ean-13 barcode * @param int $default Default On * @param string $upc Upc barcode * @param string $minimal_quantity Minimal quantity * @return array Update result */ public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array()) { $combination = new Combination($id_product_attribute); if (!$update_all_fields) { $combination->setFieldsToUpdate(array('price' => !is_null($price), 'wholesale_price' => !is_null($wholesale_price), 'ecotax' => !is_null($ecotax), 'weight' => !is_null($weight), 'unit_price_impact' => !is_null($unit), 'default_on' => !is_null($default), 'minimal_quantity' => !is_null($minimal_quantity), 'available_date' => !is_null($available_date))); } $price = str_replace(',', '.', $price); $weight = str_replace(',', '.', $weight); $combination->price = (double) $price; $combination->wholesale_price = (double) $wholesale_price; $combination->ecotax = (double) $ecotax; $combination->weight = (double) $weight; $combination->unit_price_impact = (double) $unit; $combination->reference = pSQL($reference); $combination->location = pSQL($location); $combination->ean13 = pSQL($ean13); $combination->upc = pSQL($upc); $combination->default_on = (int) $default; $combination->minimal_quantity = (int) $minimal_quantity; $combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00'; if (count($id_shop_list)) { $combination->id_shop_list = $id_shop_list; } $combination->save(); if (is_array($id_images) && count($id_images)) { $combination->setImages($id_images); } $id_default_attribute = (int) Product::updateDefaultAttribute($this->id); if ($id_default_attribute) { $this->cache_default_attribute = $id_default_attribute; } // Sync stock Reference, EAN13 and UPC for this attribute if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && StockAvailable::dependsOnStock($this->id, Context::getContext()->shop->id)) { Db::getInstance()->update('stock', array('reference' => pSQL($reference), 'ean13' => pSQL($ean13), 'upc' => pSQL($upc)), 'id_product = ' . $this->id . ' AND id_product_attribute = ' . (int) $id_product_attribute); } Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => (int) $id_product_attribute)); Tools::clearColorListCache($this->id); return true; }