当前位置: 首页>>代码示例>>PHP>>正文


PHP StockAvailable::update方法代码示例

本文整理汇总了PHP中StockAvailable::update方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::update方法的具体用法?PHP StockAvailable::update怎么用?PHP StockAvailable::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StockAvailable的用法示例。


在下文中一共展示了StockAvailable::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updatePackQuantity

 /**
  * This will update a Pack quantity and will decrease the quantity of containing Products if needed.
  *
  * @param Product $product A product pack object to update its quantity
  * @param StockAvailable $stock_available the stock of the product to fix with correct quantity
  * @param integer $delta_quantity The movement of the stock (negative for a decrease)
  * @param integer|null $id_shop Opional shop ID
  */
 public function updatePackQuantity($product, $stock_available, $delta_quantity, $id_shop = null)
 {
     $configuration = Adapter_ServiceLocator::get('Core_Business_ConfigurationInterface');
     if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && $configuration->get('PS_PACK_STOCK_TYPE') > 0) {
         $packItemsManager = Adapter_ServiceLocator::get('Adapter_PackItemsManager');
         $products_pack = $packItemsManager->getPackItems($product);
         $stockAvailable = new Core_Business_Stock_StockManager();
         $stockManager = Adapter_ServiceLocator::get('Adapter_StockManager');
         $cacheManager = Adapter_ServiceLocator::get('Adapter_CacheManager');
         foreach ($products_pack as $product_pack) {
             $productStockAvailable = $stockManager->getStockAvailableByProduct($product_pack, $product_pack->id_pack_product_attribute, $id_shop);
             $productStockAvailable->quantity = $productStockAvailable->quantity + $delta_quantity * $product_pack->pack_quantity;
             $productStockAvailable->update();
             $cacheManager->clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $product_pack->id . '*');
         }
     }
     $stock_available->quantity = $stock_available->quantity + $delta_quantity;
     if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && ($configuration->get('PS_PACK_STOCK_TYPE') == 0 || $configuration->get('PS_PACK_STOCK_TYPE') == 2)) {
         $stock_available->update();
     }
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:29,代码来源:Core_Business_Stock_StockManager.php

示例2: setQuantity

 /**
  * For a given id_product and id_product_attribute sets the quantity available
  *
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $delta_quantity The delta quantity to update
  * @param int $id_shop Optional
  */
 public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     $context = Context::getContext();
     // if there is no $id_shop, gets the context one
     if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) {
         $id_shop = (int) $context->shop->id;
     }
     $depends_on_stock = StockAvailable::dependsOnStock($id_product);
     //Try to set available quantity if product does not depend on physical stock
     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);
             $stock_available->quantity = (int) $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;
             $stock_available->quantity = (int) $quantity;
             $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
             // if quantities are shared between shops of the group
             if ($shop_group->share_stock) {
                 $stock_available->id_shop = 0;
                 $stock_available->id_shop_group = (int) $shop_group->id;
             } else {
                 $stock_available->id_shop = $id_shop;
                 $stock_available->id_shop_group = Shop::getGroupFromShop($id_shop);
             }
             $stock_available->add();
         }
         Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity));
     }
 }
开发者ID:jicheng17,项目名称:vipinsg,代码行数:47,代码来源:StockAvailable.php

示例3: _saveProtectionItems

    /**
     * Save in special database each buyer protection product for a certificate,
     * Each Trusted Shops particular characteristics is saved.
     * Create a product in Prestashop database to allow added each of them in cart.
     *
     * @param array|stdClass $protection_items
     * @param string $ts_id
     */
    private function _saveProtectionItems($protection_items, $ts_id)
    {
        $query = 'DELETE ts, p, pl ' . 'FROM `' . _DB_PREFIX_ . TSBuyerProtection::DB_ITEMS . '` AS ts ' . 'LEFT JOIN `' . _DB_PREFIX_ . 'product` AS p ON ts.`id_product` = p.`id_product` ' . 'LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` AS pl ON ts.`id_product` = pl.`id_product` ' . 'WHERE ts.`ts_id`="' . pSQL($ts_id) . '"';
        Db::getInstance()->Execute($query);
        foreach ($protection_items as $item) {
            //add hidden product
            $product = new Product();
            foreach ($this->available_languages as $iso => $lang) {
                $language = Language::getIdByIso(strtolower($iso));
                if ((int) $language !== 0) {
                    $product->name[$language] = 'TrustedShops guarantee';
                    $product->link_rewrite[$language] = 'trustedshops_guarantee';
                }
            }
            // If the default lang is different than available languages :
            // (Bug occurred otherwise)
            if (!array_key_exists(Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')), $this->available_languages)) {
                $product->name[(int) Configuration::get('PS_LANG_DEFAULT')] = 'Trustedshops';
                $product->link_rewrite[(int) Configuration::get('PS_LANG_DEFAULT')] = 'trustedshops';
            }
            // Add specifics translations
            $id_lang = Language::getIdByIso('de');
            if ((int) $id_lang > 0) {
                $product->name[$id_lang] = 'Trusted Shops Käuferschutz';
            }
            $id_lang = Language::getIdByIso('en');
            if ((int) $id_lang > 0) {
                $product->name[$id_lang] = 'Trusted Shops buyer protection';
            }
            $id_lang = Language::getIdByIso('fr');
            if ((int) $id_lang > 0) {
                $product->name[$id_lang] = 'Trusted Shops protection acheteur';
            }
            $product->quantity = 1000;
            $product->price = Tools::convertPrice($item->grossFee, Currency::getIdByIsoCode($item->currency));
            $product->id_category_default = TSBuyerProtection::$CAT_ID;
            $product->active = true;
            $product->visibility = 'none';
            $product->id_tax = 0;
            $product->add();
            if ($product->id) {
                $query = 'INSERT INTO `' . _DB_PREFIX_ . TSBuyerProtection::DB_ITEMS . '` ' . '(`creation_date`, `id_product`, `ts_id`, `id`, `currency`, `gross_fee`, `net_fee`, ' . '`protected_amount_decimal`, `protection_duration_int`, `ts_product_id`) ' . 'VALUES ("' . pSQL($item->creationDate) . '", "' . pSQL($product->id) . '", "' . pSQL($ts_id) . '", ' . '"' . (int) $item->id . '", "' . pSQL($item->currency) . '", "' . pSQL($item->grossFee) . '", ' . '"' . pSQL($item->netFee) . '", "' . pSQL($item->protectedAmountDecimal) . '", ' . '"' . pSQL($item->protectionDurationInt) . '", "' . pSQL($item->tsProductID) . '")';
                Db::getInstance()->Execute($query);
                if (class_exists('StockAvailable')) {
                    $id_stock_available = Db::getInstance()->getValue('
						SELECT s.`id_stock_available` FROM `' . _DB_PREFIX_ . 'stock_available` s
						WHERE s.`id_product` = ' . (int) $product->id);
                    $stock = new StockAvailable($id_stock_available);
                    $stock->id_product = $product->id;
                    $stock->out_of_stock = 1;
                    $stock->id_product_attribute = 0;
                    $stock->quantity = 1000000;
                    $stock->id_shop = Context::getContext()->shop->id;
                    if ($stock->id) {
                        $stock->update();
                    } else {
                        $stock->add();
                    }
                }
            } else {
                $this->errors['products'] = $this->l('Product wasn\'t saved.');
            }
        }
    }
开发者ID:rtajmahal,项目名称:PrestaShop-modules,代码行数:72,代码来源:TSBuyerProtection.php


注:本文中的StockAvailable::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。