// Update and fix some bugs on front and admin itnerfaces relative to available quantities functionnality
This commit is contained in:
@@ -641,6 +641,7 @@ class CategoryCore extends ObjectModel
|
||||
.($active ? ' AND p.`active` = 1' : '')
|
||||
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '').
|
||||
' GROUP BY p.id_product';
|
||||
|
||||
if ($random === true)
|
||||
{
|
||||
$sql .= ' ORDER BY RAND()';
|
||||
|
||||
+59
-9
@@ -1633,18 +1633,35 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$sql = 'SELECT pa.*, GROUP_CONCAT(agl.`name`, \''.pSQL($attribute_value_separator).'\',
|
||||
al.`name` SEPARATOR \''.pSQL($attribute_separator).'\') as attribute_designation, IFNULL(stock.quantity, 0)
|
||||
al.`name` SEPARATOR \''.pSQL($attribute_separator).'\') as attribute_designation
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
|
||||
'.Product::sqlStock('pa', 'pa').'
|
||||
WHERE pa.`id_product` = '.(int)$this->id.'
|
||||
GROUP BY pa.`id_product_attribute`';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
|
||||
//Get quantity of each variations
|
||||
foreach ($res as $key => $row)
|
||||
{
|
||||
$cache_key = $row['id_product'].'_'.$row['id_product_attribute'].'_quantity';
|
||||
|
||||
if (!Cache::isStored($cache_key))
|
||||
Cache::store(
|
||||
$cache_key,
|
||||
StockAvailable::getQuantityAvailableByProduct($row['id_product'], $row['id_product_attribute'])
|
||||
);
|
||||
|
||||
$res[$key]['quantity'] = Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1657,18 +1674,35 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$sql = 'SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name,
|
||||
a.`id_attribute`, pa.`unit_price_impact`, IFNULL(stock.quantity, 0) as quantity
|
||||
a.`id_attribute`, pa.`unit_price_impact`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
|
||||
'.Product::sqlStock('pa', 'pa').'
|
||||
WHERE pa.`id_product` = '.(int)$this->id.'
|
||||
ORDER BY pa.`id_product_attribute`';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
|
||||
//Get quantity of each variations
|
||||
foreach ($res as $key => $row)
|
||||
{
|
||||
$cache_key = $row['id_product'].'_'.$row['id_product_attribute'].'_quantity';
|
||||
|
||||
if (!Cache::isStored($cache_key))
|
||||
Cache::store(
|
||||
$cache_key,
|
||||
StockAvailable::getQuantityAvailableByProduct($row['id_product'], $row['id_product_attribute'])
|
||||
);
|
||||
|
||||
$res[$key]['quantity'] = Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1683,18 +1717,34 @@ class ProductCore extends ObjectModel
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
$sql = 'SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name,
|
||||
a.`id_attribute`, pa.`unit_price_impact`, IFNULL(stock.quantity, 0) as quantity
|
||||
a.`id_attribute`, pa.`unit_price_impact`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
|
||||
'.Product::sqlStock('pa', 'pa').'
|
||||
WHERE pa.`id_product` = '.(int)$this->id.'
|
||||
AND pa.`id_product_attribute` = '.(int)$id_product_attribute.'
|
||||
ORDER BY pa.`id_product_attribute`';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
|
||||
//Get quantity of each variations
|
||||
foreach ($res as $key => $row)
|
||||
{
|
||||
$cache_key = $row['id_product'].'_'.$row['id_product_attribute'].'_quantity';
|
||||
|
||||
if (!Cache::isStored($cache_key))
|
||||
Cache::store(
|
||||
$cache_key,
|
||||
StockAvailable::getQuantityAvailableByProduct($row['id_product'], $row['id_product_attribute'])
|
||||
);
|
||||
|
||||
$res[$key]['quantity'] = Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getCombinationImages($id_lang)
|
||||
|
||||
+12
-4
@@ -294,12 +294,20 @@ class SupplierCore extends ObjectModel
|
||||
|
||||
public function getProductsLite($id_lang)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
$sql = '
|
||||
SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE p.`id_supplier` = '.(int)$this->id
|
||||
);
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.'
|
||||
)
|
||||
INNER JOIN `'._DB_PREFIX_.'product_supplier` ps ON (
|
||||
ps.`id_product` = p.`id_product`
|
||||
AND ps.`id_supplier` = '.(int)$this->id.'
|
||||
)
|
||||
GROUP BY p.`id_product`';
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -826,13 +826,13 @@ class ShopCore extends ObjectModel
|
||||
if ($tables_import && !isset($tables_import[$table_name]))
|
||||
continue;
|
||||
|
||||
// Special case for stock if current shop is in a share stock group
|
||||
/*if ($table_name == 'stock')
|
||||
// Special case for stock_available if current shop is in a share stock group
|
||||
if ($table_name == 'stock_available')
|
||||
{
|
||||
$group = new GroupShop($this->id_group_shop);
|
||||
if ($group->share_stock && $group->haveShops())
|
||||
continue;
|
||||
}*/
|
||||
}
|
||||
|
||||
$id = 'id_'.$row['type'];
|
||||
if ($row['type'] == 'fk_shop')
|
||||
|
||||
@@ -282,7 +282,7 @@ class StockAvailableCore extends ObjectModel
|
||||
$id_product_attribute = 0;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('quantity');
|
||||
$query->select('SUM(quantity)');
|
||||
$query->from('stock_available');
|
||||
|
||||
// if null, it's a product without attributes
|
||||
@@ -468,12 +468,17 @@ class StockAvailableCore extends ObjectModel
|
||||
{
|
||||
if ($group_shop->share_stock)
|
||||
{
|
||||
$id_shops_list = implode(', ', Shop::getIdShopsByIdGroupShop($group_shop->id));
|
||||
$shop_list = Shop::getIdShopsByIdGroupShop($group_shop->id);
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_shop IN ('.$id_shops_list.')'
|
||||
);
|
||||
if (count($shop_list) > 0)
|
||||
{
|
||||
$id_shops_list = implode(', ', $shop_list);
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_shop IN ('.$id_shops_list.')'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user