本文整理汇总了PHP中StockAvailable::getStockAvailableIdByProductId方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::getStockAvailableIdByProductId方法的具体用法?PHP StockAvailable::getStockAvailableIdByProductId怎么用?PHP StockAvailable::getStockAvailableIdByProductId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StockAvailable
的用法示例。
在下文中一共展示了StockAvailable::getStockAvailableIdByProductId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStockAvailableByProduct
public function getStockAvailableByProduct($product, $id_product_attribute = null, $id_shop = null)
{
return new StockAvailable(StockAvailable::getStockAvailableIdByProductId($product->id, $id_product_attribute, $id_shop));
}
示例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));
}
}
示例3: setQuantity
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 . '*');
}