コード例 #1
0
 protected function addAttribute($attributes, $price = 0, $weight = 0)
 {
     foreach ($attributes as $attribute) {
         $price += (double) preg_replace('/[^0-9.-]/', '', str_replace(',', '.', Tools::getValue('price_impact_' . (int) $attribute)));
         $weight += (double) preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact_' . (int) $attribute)));
     }
     if ($this->product->id) {
         $result = array('id_product' => (int) $this->product->id, 'price' => (double) $price, 'weight' => (double) $weight, 'ecotax' => 0, 'reference' => pSQL(Tools::getValue('reference')), 'default_on' => 0, 'available_date' => '0000-00-00');
         PP::setQty($result, str_replace(',', '.', Tools::getValue('quantity')));
         return $result;
     }
     return array();
 }
コード例 #2
0
 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 . '*');
 }