protected function getCurrentShopInfoMsg() { $shop_info = null; if (Shop::getContext() == Shop::CONTEXT_SHOP) { $shop_info = sprintf($this->l('The modifications will be applied to shop: %s'), $this->context->shop->name); } else { if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_info = sprintf($this->l('The modifications will be applied to this group: %s'), Shop::getContextShopGroup()->name); } else { $shop_info = $this->l('The modifications will be applied to all shops'); } } return '<div class="alert alert-info">' . $shop_info . '</div>'; }
/** * For a given {product, product attribute} gets warehouse list * * @param int $id_product ID of the product * @param int $id_product_attribute Optional, uses 0 if this product does not have attributes * @param int $id_shop Optional, ID of the shop. Uses the context shop id (@see Context::shop) * @return array Warehouses (ID, reference/name concatenated) */ public static function getProductWarehouseList($id_product, $id_product_attribute = 0, $id_shop = null) { // if it's a pack, returns warehouses if and only if some products use the advanced stock management if (Pack::isPack($id_product)) { $warehouses = Warehouse::getPackWarehouses($id_product); $res = array(); foreach ($warehouses as $warehouse) { $res[]['id_warehouse'] = $warehouse; } return $res; } $share_stock = false; if ($id_shop === null) { if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_group = Shop::getContextShopGroup(); } else { $shop_group = Context::getContext()->shop->getGroup(); $id_shop = (int) Context::getContext()->shop->id; } $share_stock = $shop_group->share_stock; } else { $shop_group = Shop::getGroupFromShop($id_shop); $share_stock = $shop_group['share_stock']; } if ($share_stock) { $ids_shop = Shop::getShops(true, (int) $shop_group->id, true); } else { $ids_shop = array((int) $id_shop); } $query = new DbQuery(); $query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name'); $query->from('warehouse_product_location', 'wpl'); $query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop IN (' . implode(',', array_map('intval', $ids_shop)) . ')'); $query->innerJoin('warehouse', 'w', 'ws.id_warehouse = w.id_warehouse'); $query->where('id_product = ' . (int) $id_product); $query->where('id_product_attribute = ' . (int) $id_product_attribute); $query->where('w.deleted = 0'); $query->groupBy('wpl.id_warehouse'); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); }
/** * Add sql params for shops fields - specific to StockAvailable * * @param array $params Reference to the params array * @param int $id_shop Optional : The shop ID * */ public static function addSqlShopParams(&$params, $id_shop = null) { $context = Context::getContext(); $group_ok = false; // if there is no $id_shop, gets the context one // get shop group too if ($id_shop === null) { if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_group = Shop::getContextShopGroup(); } else { $shop_group = $context->shop->getGroup(); $id_shop = $context->shop->id; } } else { $shop = new Shop($id_shop); $shop_group = $shop->getGroup(); } // if quantities are shared between shops of the group if ($shop_group->share_stock) { $params['id_shop_group'] = (int) $shop_group->id; $params['id_shop'] = 0; $group_ok = true; } else { $params['id_shop_group'] = 0; } // if no group specific restriction, set simple shop restriction if (!$group_ok) { $params['id_shop'] = (int) $id_shop; } }
public function initFormAttributes($product) { $data = $this->createTemplate($this->tpl_form); if (!Combination::isFeatureActive()) { $this->displayWarning($this->l('This feature has been disabled. ') . ' <a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->l('Performances') . '</a>'); } else { if (Validate::isLoadedObject($product)) { if ($this->product_exists_in_shop) { if ($product->is_virtual) { $data->assign('product', $product); $this->displayWarning($this->l('A virtual product cannot have combinations.')); } else { $attribute_js = array(); $attributes = Attribute::getAttributes($this->context->language->id, true); foreach ($attributes as $k => $attribute) { $attribute_js[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name']; } $currency = $this->context->currency; $data->assign('attributeJs', $attribute_js); $data->assign('attributes_groups', AttributeGroup::getAttributesGroups($this->context->language->id)); $data->assign('currency', $currency); $images = Image::getImages($this->context->language->id, $product->id); $data->assign('tax_exclude_option', Tax::excludeTaxeOption()); $data->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT')); $data->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX')); $data->assign('field_value_unity', $this->getFieldValue($product, 'unity')); $data->assign('reasons', $reasons = StockMvtReason::getStockMvtReasons($this->context->language->id)); $data->assign('ps_stock_mvt_reason_default', $ps_stock_mvt_reason_default = Configuration::get('PS_STOCK_MVT_REASON_DEFAULT')); $data->assign('minimal_quantity', $this->getFieldValue($product, 'minimal_quantity') ? $this->getFieldValue($product, 'minimal_quantity') : 1); $data->assign('available_date', $this->getFieldValue($product, 'available_date') != 0 ? stripslashes(htmlentities($this->getFieldValue($product, 'available_date'), $this->context->language->id)) : '0000-00-00'); $i = 0; $type = ImageType::getByNameNType('%', 'products', 'height'); if (isset($type['name'])) { $data->assign('imageType', $type['name']); } else { $data->assign('imageType', 'small_default'); } $data->assign('imageWidth', (isset($image_type['width']) ? (int) $image_type['width'] : 64) + 25); foreach ($images as $k => $image) { $images[$k]['obj'] = new Image($image['id_image']); ++$i; } $data->assign('images', $images); $data->assign($this->tpl_form_vars); $data->assign(array('list' => $this->renderListAttributes($product, $currency), 'product' => $product, 'id_category' => $product->getDefaultCategory(), 'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator'), 'combination_exists' => Shop::isFeatureActive() && Shop::getContextShopGroup()->share_stock && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0 && $product->hasAttributes())); } } else { $this->displayWarning($this->l('You must save the product in this shop before adding combinations.')); } } else { $data->assign('product', $product); $this->displayWarning($this->l('You must save this product before adding combinations.')); } } $this->tpl_form_vars['custom_form'] = $data->fetch(); }
public function initContentForCombinations() { ${${"GLOBALS"}["vmqqtmkyw"]} = $this->object; if (!Combination::isFeatureActive()) { $this->displayWarning($this->getMessage("This feature has been disabled, you can activate this feature at this page:") . $this->getMessage("link to Performances")); return; } ${"GLOBALS"}["weevwwkl"] = "product"; if (Validate::isLoadedObject(${${"GLOBALS"}["weevwwkl"]})) { self::$smarty->assign("country_display_tax_label", $this->context->country->display_tax_label); $zsahvowoo = "lang"; self::$smarty->assign("tax_exclude_taxe_option", Tax::excludeTaxeOption()); self::$smarty->assign("id_tax_rules_group", $product->id_tax_rules_group); self::$smarty->assign("tax_rules_groups", TaxRulesGroup::getTaxRulesGroups(true)); ${$zsahvowoo} = new Language($this->id_language); self::$smarty->assign("iso_code", $lang->iso_code); self::$smarty->assign("combinationImagesJs", $this->getCombinationImagesJs()); if ($product->is_virtual) { $tpkpvyor = "product"; self::$smarty->assign("product", ${$tpkpvyor}); $this->displayWarning($this->getMessage("A virtual product cannot have combinations.")); } else { ${"GLOBALS"}["qqjbnscylsi"] = "attribute_js"; ${"GLOBALS"}["nqxaoftbn"] = "attribute"; $bcesaxqdqqq = "images"; ${"GLOBALS"}["zcxmuajd"] = "ps_stock_mvt_reason_default"; $vmytjghdfi = "attribute_js"; $nrkrfhirkx = "attributes"; ${${"GLOBALS"}["qqjbnscylsi"]} = array(); $cappytc = "k"; ${"GLOBALS"}["jyaoxpe"] = "attribute"; ${$nrkrfhirkx} = Attribute::getAttributes($this->context->language->id, true); foreach (${${"GLOBALS"}["ecblflvypvt"]} as ${$cappytc} => ${${"GLOBALS"}["jyaoxpe"]}) { ${$vmytjghdfi}[${${"GLOBALS"}["iixdipeiyldv"]}["id_attribute_group"]][${${"GLOBALS"}["iixdipeiyldv"]}["id_attribute"]] = ${${"GLOBALS"}["nqxaoftbn"]}["name"]; } ${"GLOBALS"}["higiwiyuxd"] = "k"; ${${"GLOBALS"}["sxexnhlq"]} = new Currency((int) Configuration::get("PS_CURRENCY_DEFAULT")); self::$smarty->assign("attributeJs", ${${"GLOBALS"}["xenfvrjowsy"]}); self::$smarty->assign("attributes_groups", AttributeGroup::getAttributesGroups($this->context->language->id)); self::$smarty->assign("currency", ${${"GLOBALS"}["sxexnhlq"]}); ${"GLOBALS"}["xzqtsdnlkv"] = "images"; ${$bcesaxqdqqq} = Image::getImages($this->context->language->id, $product->id); self::$smarty->assign("tax_exclude_option", Tax::excludeTaxeOption()); $rbxbrbxg = "product"; self::$smarty->assign("ps_weight_unit", Configuration::get("PS_WEIGHT_UNIT")); self::$smarty->assign("ps_use_ecotax", Configuration::get("PS_USE_ECOTAX")); self::$smarty->assign("field_value_unity", $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "unity")); ${"GLOBALS"}["vpcuib"] = "image_type"; self::$smarty->assign("reasons", ${${"GLOBALS"}["nqegxbae"]} = StockMvtReason::getStockMvtReasons($this->context->language->id)); self::$smarty->assign("ps_stock_mvt_reason_default", ${${"GLOBALS"}["zcxmuajd"]} = Configuration::get("PS_STOCK_MVT_REASON_DEFAULT")); self::$smarty->assign("minimal_quantity", $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "minimal_quantity") ? $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "minimal_quantity") : 1); self::$smarty->assign("available_date", $this->getFieldValue(${$rbxbrbxg}, "available_date") != 0 ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "available_date"), version_compare(_PS_VERSION_, "1.5.5", ">=") ? null : $this->context->language->id))) : "0000-00-00"); ${${"GLOBALS"}["tqkkuicfgax"]} = 0; ${"GLOBALS"}["ucamhp"] = "product"; self::$smarty->assign("imageType", ImageType::getByNameNType("small_default", "products")); self::$smarty->assign("imageWidth", (isset(${${"GLOBALS"}["rvkjjxqs"]}["width"]) ? (int) ${${"GLOBALS"}["vpcuib"]}["width"] : 64) + 25); foreach (${${"GLOBALS"}["xzqtsdnlkv"]} as ${${"GLOBALS"}["higiwiyuxd"]} => ${${"GLOBALS"}["inpuwydsyk"]}) { $cshrlmyryz = "image"; ${${"GLOBALS"}["dhvuermstcbs"]}[${${"GLOBALS"}["qtxqhylrbsm"]}]["obj"] = new Image(${$cshrlmyryz}["id_image"]); $kcvbkys = "i"; ++${$kcvbkys}; } self::$smarty->assign("images", ${${"GLOBALS"}["dhvuermstcbs"]}); self::$smarty->assign(array("combinationArray" => $this->getCombinations(${${"GLOBALS"}["ucamhp"]}, ${${"GLOBALS"}["sxexnhlq"]}), "product" => ${${"GLOBALS"}["vmqqtmkyw"]}, "id_category" => $product->getDefaultCategory(), "token_generator" => "tokengenerator", "combination_exists" => Shop::isFeatureActive() && Shop::getContextShopGroup()->share_stock && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0)); } } else { self::$smarty->assign("product", ${${"GLOBALS"}["vmqqtmkyw"]}); $this->displayWarning($this->getMessage("You must save this product before adding combinations.")); } }
private function getCurrentShopInfoMsg() { $shop_info = null; if (Shop::isFeatureActive()) { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $shop_info = $this->l(sprintf('The modifications will be applied to shop: %s', $this->context->shop->name)); } else { if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_info = $this->l(sprintf('The modifications will be applied to this group: %s', Shop::getContextShopGroup()->name)); } else { $shop_info = $this->l('The modifications will be applied to all shops and shop groups'); } } return '<div class="alert alert-info">' . $shop_info . '</div>'; } else { return ''; } }
protected function getCurrentShopInfoMsg() { $shop_info = null; if (Shop::isFeatureActive()) { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $shop_info = sprintf($this->getTranslator()->trans('The modifications will be applied to shop: %s', array(), 'Modules.ImageSlider'), $this->context->shop->name); } else { if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_info = sprintf($this->getTranslator()->trans('The modifications will be applied to this group: %s', array(), 'Modules.ImageSlider'), Shop::getContextShopGroup()->name); } else { $shop_info = $this->getTranslator()->trans('The modifications will be applied to all shops and shop groups', array(), 'Modules.ImageSlider'); } } return '<div class="alert alert-info">' . $shop_info . '</div>'; } else { return ''; } }
public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } $context = Context::getContext(); if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) { $id_shop = (int) $context->shop->id; } $depends_on_stock = StockAvailable::dependsOnStock($id_product); if (!$depends_on_stock) { $id_stock_available = (int) StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if ($id_stock_available) { $stock_available = new StockAvailable($id_stock_available); PP::setQty($stock_available, $quantity); $stock_available->update(); } else { $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop); $stock_available = new StockAvailable(); $stock_available->out_of_stock = (int) $out_of_stock; $stock_available->id_product = (int) $id_product; $stock_available->id_product_attribute = (int) $id_product_attribute; PP::setQty($stock_available, $quantity); if ($id_shop === null) { $shop_group = Shop::getContextShopGroup(); } else { $shop_group = new ShopGroup((int) Shop::getGroupFromShop((int) $id_shop)); } if ($shop_group->share_stock) { $stock_available->id_shop = 0; $stock_available->id_shop_group = (int) $shop_group->id; } else { $stock_available->id_shop = (int) $id_shop; $stock_available->id_shop_group = 0; } $stock_available->add(); } Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity + $stock_available->quantity_remainder)); } Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*'); }