Example #1
0
    /**
     * 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;
    }
 protected function getColorsListCacheId($id_product)
 {
     return Product::getColorsListCacheId($id_product);
 }
Example #3
0
 public static function clearColorListCache($id_product = false)
 {
     // Change template dir if called from the BackOffice
     $current_template_dir = Context::getContext()->smarty->getTemplateDir();
     Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_);
     Tools::clearCache(null, _PS_THEME_DIR_ . 'product-list-colors.tpl', Product::getColorsListCacheId((int) $id_product, false));
     Context::getContext()->smarty->setTemplateDir($current_template_dir);
 }