/** * Upgrades total_quantity_available after having saved * @see StockAvailableCore::update() * @see StockAvailableCore::add() */ public function postSave() { if ($this->id_product_attribute == 0) { return true; } $id_shop = Shop::getContext() != Shop::CONTEXT_GROUP ? $this->id_shop : null; if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) { $combination = new Combination((int) $this->id_product_attribute); if ($colors = $combination->getColorsAttributes()) { $product = new Product((int) $this->id_product); foreach ($colors as $color) { if ($product->isColorUnavailable((int) $color['id_attribute'], (int) $this->id_shop)) { Tools::clearColorListCache($product->id); break; } } } } $total_quantity = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(quantity) as quantity FROM ' . _DB_PREFIX_ . 'stock_available WHERE id_product = ' . (int) $this->id_product . ' AND id_product_attribute <> 0 ' . StockAvailable::addSqlShopRestriction(null, $id_shop)); $this->setQuantity($this->id_product, 0, $total_quantity, $id_shop); return true; }
/** * @param \Product $product * * @return string * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getProductColors(\Product &$product) { $colorList = \Product::getAttributesColorList(array($product->id)); if (!$colorList || empty($colorList) || !isset($colorList[$product->id]) || empty($colorList[$product->id])) { return ''; } $colors = array(); foreach ($colorList[$product->id] as $k => $color) { if ((int) $product->isColorUnavailable($color['id_attribute'], \Context::getContext()->shop->id) === $color['id_product_attribute'] && !$this->backOrdersAllowed($product)) { continue; } array_push($colors, $color['name']); } return implode(', ', $colors); }
/** * Upgrades total_quantity_available after having saved * @see StockAvailableCore::update() * @see StockAvailableCore::add() */ public function postSave() { if ($this->id_product_attribute == 0) { return true; } $id_shop = Shop::getContext() != Shop::CONTEXT_GROUP ? $this->id_shop : null; if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) { $combination = new Combination((int) $this->id_product_attribute); if ($colors = $combination->getColorsAttributes()) { $product = new Product((int) $this->id_product); foreach ($colors as $color) { if ($product->isColorUnavailable((int) $color['id_attribute'], (int) $this->id_shop)) { // Change template dir if called from the BackOffice $current_template_dir = Context::getContext()->smarty->getTemplateDir(); Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_ . 'tpl'); Tools::clearCache(null, 'product-list-colors.tpl', Product::getColorsListCacheId((int) $product->id)); Context::getContext()->smarty->setTemplateDir($current_template_dir); break; } } } } $total_quantity = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(quantity) as quantity FROM ' . _DB_PREFIX_ . 'stock_available WHERE id_product = ' . (int) $this->id_product . ' AND id_product_attribute <> 0 ' . StockAvailable::addSqlShopRestriction(null, $id_shop)); $this->setQuantity($this->id_product, 0, $total_quantity, $id_shop); return true; }