// Fix some bug on advanced stock management

This commit is contained in:
rGaillard
2012-07-11 15:46:39 +00:00
parent 9195b74cb7
commit 3672b02c66
10 changed files with 66 additions and 41 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ class LinkCore
if (is_array($product) && isset($product['id_product']))
$product = new Product($product['id_product'], false, $id_lang);
else if (is_numeric($product) || !$product)
$product = new Product($product, false, $id_lang);
$product = new Product($product, false, $id_lang);
else
throw new PrestaShopException('Invalid product vars');
}
+13 -11
View File
@@ -2451,17 +2451,19 @@ class ProductCore extends ObjectModel
}
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($res as $row)
self::$_pricesLevel2[$cache_id_2][(int)$row['id_product_attribute']] = array(
'price' => $row['price'],
'ecotax' => $row['ecotax'],
'attribute_price' => (isset($row['attribute_price']) ? $row['attribute_price'] : null)
);
if ($default_on)
self::$_pricesLevel2[$cache_id_2][0] = array('price' => $row['price'],
'ecotax' => $row['ecotax'],
'attribute_price' => $row['attribute_price']);
if ($res)
{
foreach ($res as $row)
self::$_pricesLevel2[$cache_id_2][(int)$row['id_product_attribute']] = array(
'price' => $row['price'],
'ecotax' => $row['ecotax'],
'attribute_price' => (isset($row['attribute_price']) ? $row['attribute_price'] : null)
);
if ($default_on)
self::$_pricesLevel2[$cache_id_2][0] = array('price' => $row['price'],
'ecotax' => $row['ecotax'],
'attribute_price' => $row['attribute_price']);
}
}
$result = self::$_pricesLevel2[$cache_id_2][(int)$id_product_attribute];
+7 -4
View File
@@ -137,8 +137,8 @@ class HelperFormCore extends Helper
break;
case 'shop' :
$params['html'] = $this->renderAssoShop($params['type']);
$shops = Shop::getShops(true, null, true);
$disable_shops = isset($params['disable_shared']) ? $params['disable_shared'] : false;
$params['html'] = $this->renderAssoShop($disable_shops);
if (Shop::getTotalShops(false) == 1)
unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
break;
@@ -190,7 +190,7 @@ class HelperFormCore extends Helper
*
* @return string
*/
public function renderAssoShop()
public function renderAssoShop($disable_shared = false)
{
if (!Shop::isFeatureActive())
return;
@@ -228,8 +228,11 @@ class HelperFormCore extends Helper
$tpl = $this->createTemplate('assoshop.tpl');
$tree = Shop::getTree();
$nb_shop = 0;
foreach ($tree as $value)
foreach ($tree as &$value)
{
$value['disable_shops'] = (isset($value[$disable_shared]) && $value[$disable_shared]);
$nb_shop += count($value['shops']);
}
$tpl->assign(array(
'input' => array(
'type' => 'shop',
+2
View File
@@ -117,6 +117,7 @@ class ShopCore extends ObjectModel
*/
const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order';
const SHARE_STOCK = 'share_stock';
/**
* On shop instance, get its theme and URL data too
@@ -574,6 +575,7 @@ class ShopCore extends ObjectModel
'name' => $row['group_name'],
'share_customer' => $row['share_customer'],
'share_order' => $row['share_order'],
'share_stock' => $row['share_stock'],
'shops' => array(),
);
+20 -3
View File
@@ -309,8 +309,6 @@ class WarehouseCore extends ObjectModel
*/
public static function getProductWarehouseList($id_product, $id_product_attribute = 0, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->id;
// if it's a pack, returns warehouses if and only if some products use the advanced stock management
if (Pack::isPack($id_product))
@@ -321,11 +319,30 @@ class WarehouseCore extends ObjectModel
$res[]['id_warehouse'] = $warehouse;
return $res;
}
$share_stock = false;
if ($id_shop === null)
{
if (Shop::getContext() == Shop::CONTEXT_GROUP)
$shop_group = Shop::getContextShopGroup();
else
$shop_group = Context::getContext()->shop->getGroup();
$share_stock = $shop_group->share_stock;
}
else
{
$shop_group = Shop::getGroupFromShop($id_shop);
$share_stock = $shop_group['share_stock'];
}
if ($share_stock)
$ids_shop = Shop::getShops(true, (int)$shop_group->id, true);
else
$ids_shop = array((int)Context::getContext()->shop->id);
$query = new DbQuery();
$query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name');
$query->from('warehouse_product_location', 'wpl');
$query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop = '.(int)$id_shop);
$query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop IN ('.implode(',', array_map('intval', $ids_shop)).')');
$query->innerJoin('warehouse', 'w', 'ws.id_warehouse = w.id_warehouse');
$query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = '.(int)$id_product_attribute);