本文整理汇总了PHP中StockAvailable::addSqlShopParams方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::addSqlShopParams方法的具体用法?PHP StockAvailable::addSqlShopParams怎么用?PHP StockAvailable::addSqlShopParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StockAvailable
的用法示例。
在下文中一共展示了StockAvailable::addSqlShopParams方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setProductOutOfStock
/**
* For a given id_product, sets if product is available out of stocks
*
* @param int $id_product
* @param int $out_of_stock Optional false by default
* @param int $id_shop Optional gets context by default
*/
public static function setProductOutOfStock($id_product, $out_of_stock = false, $id_shop = null, $id_product_attribute = 0)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
if ($id_shop === null) {
$id_shop = Context::getContext()->shop->id;
}
$existing_id = StockAvailable::getStockAvailableIdByProductId((int) $id_product, (int) $id_product_attribute, (int) $id_shop);
if ($existing_id > 0) {
Db::getInstance()->update('stock_available', array('out_of_stock' => (int) $out_of_stock), 'id_product = ' . (int) $id_product . ($id_product_attribute ? ' AND id_product_attribute = ' . (int) $id_product_attribute : '') . StockAvailable::addSqlShopRestriction(null, $id_shop));
} else {
$params = array('out_of_stock' => (int) $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute);
StockAvailable::addSqlShopParams($params, $id_shop);
Db::getInstance()->insert('stock_available', $params);
}
}
示例2: synchronize
/**
* For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity
*
* @param int $product_id
* @param int $order_shop_id
* @return bool
*/
public static function synchronize($product_id, $order_shop_id = null)
{
if (!JeproshopTools::isUnsignedInt($product_id)) {
return false;
}
$db = JFactory::getDBO();
// gets warehouse ids grouped by shops
$warehouse_ids = JeproshopWarehouseModelWarehouse::getWarehousesGroupedByShops();
if ($order_shop_id !== null) {
$order_warehouses = array();
$warehouses = JeproshopWarehouseModelWarehouse::getWarehouses(false, (int) $order_shop_id);
foreach ($warehouses as $warehouse) {
$order_warehouses[] = $warehouse->warehouse_id;
}
}
// gets all product attributes ids
$product_attribute_ids = array();
foreach (JeproshopProductModelProduct::getProductAttributesIds($product_id) as $product_attribute_id) {
$product_attribute_ids[] = $product_attribute_id->product_attribute_id;
}
// Allow to order the product when out of stock?
$out_of_stock = JeproshopStockAvailableModelStockAvailable::outOfStock($product_id);
$manager = JeproshopStockManagerFactory::getManager();
// loops on $ids_warehouse to synchronize quantities
foreach ($warehouse_ids as $shop_id => $warehouses) {
// first, checks if the product depends on stock for the given shop $id_shop
if (JeproshopStockAvailableModelStockAvailable::dependsOnStock($product_id, $shop_id)) {
// init quantity
$product_quantity = 0;
// if it's a simple product
if (empty($product_attribute_ids)) {
$allowed_warehouse_for_product = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, 0, (int) $shop_id);
$allowed_warehouse_for_product_clean = array();
foreach ($allowed_warehouse_for_product as $warehouse) {
$allowed_warehouse_for_product_clean[] = (int) $warehouse->warehouse_id;
}
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
continue;
}
$product_quantity = $manager->getProductRealQuantities($product_id, null, $allowed_warehouse_for_product_clean, true);
/*Hook::exec('actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => 0,
'quantity' => $product_quantity
)
);*/
} else {
// else this product has attributes, hence loops on $ids_product_attribute
foreach ($product_attribute_ids as $product_attribute_id) {
$allowed_warehouse_for_combination = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, (int) $product_attribute_id, (int) $shop_id);
$allowed_warehouse_for_combination_clean = array();
foreach ($allowed_warehouse_for_combination as $warehouse) {
$allowed_warehouse_for_combination_clean[] = (int) $warehouse->warehouse_id;
}
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
continue;
}
$quantity = $manager->getProductRealQuantities($product_id, $product_attribute_id, $allowed_warehouse_for_combination_clean, true);
$query = new DbQuery();
$query->select('COUNT(*)');
$query->from('stock_available');
$query->where('id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id));
if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
$query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity), 'where' => 'id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
} else {
$query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity, 'depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute));
StockAvailable::addSqlShopParams($query['data']);
Db::getInstance()->insert($query['table'], $query['data']);
}
$product_quantity += $quantity;
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
}
}
// updates
// if $id_product has attributes, it also updates the sum for all attributes
$query = array('table' => 'stock_available', 'data' => array('quantity' => $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $shop_id));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
}
}
// In case there are no warehouses, removes product from StockAvailable
if (count($warehouse_ids) == 0 && JeproshopStockAvailableModelStockAvailable::dependsOnStock((int) $product_id)) {
$query = "UPDATE " . $db->quoteName('#__jeproshop_stock_available') . " SET " . $db->quoteName('quantity') . " = 0 ";
$query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id;
$db->setQuery($query);
$db->query();
}
JeproshopCache::clean('jeproshop_stock_available_get_quantity_available_by_product_' . (int) $product_id . '_*');
}
示例3: removeProductFromStockAvailable
/**
* Removes a given product from the stock available
*
* @param int $id_product
* @param int $id_product_attribute Optional
* @param mixed $id_shop shop id or shop object Optional
*/
public static function removeProductFromStockAvailable($id_product, $id_product_attribute = null, $shop = null)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
if (Shop::getContext() == SHOP::CONTEXT_SHOP) {
if (Shop::getContextShopGroup()->share_stock == 1) {
$pa_sql = '';
if ($id_product_attribute !== null) {
$pa_sql = '_attribute';
$id_product_attribute_sql = $id_product_attribute;
} else {
$id_product_attribute_sql = $id_product;
}
if ((int) Db::getInstance()->getValue('SELECT COUNT(*)
FROM ' . _DB_PREFIX_ . 'product' . $pa_sql . '_shop
WHERE id_product' . $pa_sql . '=' . (int) $id_product_attribute_sql . '
AND id_shop IN (' . implode(',', array_map('intval', Shop::getContextListShopID(SHOP::SHARE_STOCK))) . ')')) {
return true;
}
}
}
$res = Db::getInstance()->execute('
DELETE FROM ' . _DB_PREFIX_ . 'stock_available
WHERE id_product = ' . (int) $id_product . ($id_product_attribute ? ' AND id_product_attribute = ' . (int) $id_product_attribute : '') . StockAvailable::addSqlShopRestriction(null, $shop));
if ($id_product_attribute) {
if ($shop === null || !Validate::isLoadedObject($shop)) {
$shop_datas = array();
StockAvailable::addSqlShopParams($shop_datas);
$id_shop = (int) $shop_datas['id_shop'];
} else {
$id_shop = (int) $shop->id;
}
$stock_available = new StockAvailable();
$stock_available->id_product = (int) $id_product;
$stock_available->id_product_attribute = (int) $id_product;
$stock_available->id_shop = (int) $id_shop;
$stock_available->postSave();
}
return $res;
}
示例4: synchronize
public static function synchronize($id_product, $order_id_shop = null)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
if (Pack::isPack($id_product)) {
if (Validate::isLoadedObject($product = new Product((int) $id_product))) {
if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
$products_pack = Pack::getItems($id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack) {
StockAvailable::synchronize($product_pack->id, $order_id_shop);
}
}
} else {
return false;
}
}
$ids_warehouse = Warehouse::getWarehousesGroupedByShops();
if ($order_id_shop !== null) {
$order_warehouses = array();
$wh = Warehouse::getWarehouses(false, (int) $order_id_shop);
foreach ($wh as $warehouse) {
$order_warehouses[] = $warehouse['id_warehouse'];
}
}
$ids_product_attribute = array();
foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute) {
$ids_product_attribute[] = $id_product_attribute['id_product_attribute'];
}
$out_of_stock = StockAvailable::outOfStock($id_product);
$manager = StockManagerFactory::getManager();
foreach ($ids_warehouse as $id_shop => $warehouses) {
if (StockAvailable::dependsOnStock($id_product, $id_shop)) {
$product_quantity = 0;
if (empty($ids_product_attribute)) {
$allowed_warehouse_for_product = WareHouse::getProductWarehouseList((int) $id_product, 0, (int) $id_shop);
$allowed_warehouse_for_product_clean = array();
foreach ($allowed_warehouse_for_product as $warehouse) {
$allowed_warehouse_for_product_clean[] = (int) $warehouse['id_warehouse'];
}
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
continue;
}
$product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => 0, 'quantity' => $product_quantity));
} else {
foreach ($ids_product_attribute as $id_product_attribute) {
$allowed_warehouse_for_combination = WareHouse::getProductWarehouseList((int) $id_product, (int) $id_product_attribute, (int) $id_shop);
$allowed_warehouse_for_combination_clean = array();
foreach ($allowed_warehouse_for_combination as $warehouse) {
$allowed_warehouse_for_combination_clean[] = (int) $warehouse['id_warehouse'];
}
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
continue;
}
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
$query = new DbQuery();
$query->select('COUNT(*)');
$query->from('stock_available');
$query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
} else {
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array('depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute), 'quantity', $quantity));
StockAvailable::addSqlShopParams($query['data']);
Db::getInstance()->insert($query['table'], $query['data']);
}
$product_quantity += $quantity;
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
}
}
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $id_shop));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
}
}
if (count($ids_warehouse) == 0 && StockAvailable::dependsOnStock((int) $id_product)) {
Db::getInstance()->update('stock_available', array('quantity' => 0, 'quantity_remainder' => 0), 'id_product = ' . (int) $id_product);
}
Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*');
}