// stocks : debug and optimisations

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9644 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-10-25 16:31:26 +00:00
parent 8f00f0f46f
commit e6dfc34e68
8 changed files with 63 additions and 86 deletions
+12
View File
@@ -327,6 +327,8 @@
'AdminCountriesController' => '', 'AdminCountriesController' => '',
'AdminCurrenciesControllerCore' => 'controllers/admin/AdminCurrenciesController.php', 'AdminCurrenciesControllerCore' => 'controllers/admin/AdminCurrenciesController.php',
'AdminCurrenciesController' => '', 'AdminCurrenciesController' => '',
'AdminCustomersControllerCore' => 'controllers/admin/AdminCustomersController.php',
'AdminCustomersController' => '',
'AdminDbControllerCore' => 'controllers/admin/AdminDbController.php', 'AdminDbControllerCore' => 'controllers/admin/AdminDbController.php',
'AdminDbController' => '', 'AdminDbController' => '',
'AdminDeliverySlipControllerCore' => 'controllers/admin/AdminDeliverySlipController.php', 'AdminDeliverySlipControllerCore' => 'controllers/admin/AdminDeliverySlipController.php',
@@ -343,8 +345,12 @@
'AdminHomeControllerCore' => 'controllers/admin/AdminHomeController.php', 'AdminHomeControllerCore' => 'controllers/admin/AdminHomeController.php',
'AdminHomeController' => 'override/controllers/admin/AdminHomeController.php', 'AdminHomeController' => 'override/controllers/admin/AdminHomeController.php',
'AdminImagesController' => 'controllers/admin/AdminImagesController.php', 'AdminImagesController' => 'controllers/admin/AdminImagesController.php',
'AdminInformationControllerCore' => 'controllers/admin/AdminInformationController.php',
'AdminInformationController' => '',
'AdminInvoicesControllerCore' => 'controllers/admin/AdminInvoicesController.php', 'AdminInvoicesControllerCore' => 'controllers/admin/AdminInvoicesController.php',
'AdminInvoicesController' => '', 'AdminInvoicesController' => '',
'AdminLanguagesControllerCore' => 'controllers/admin/AdminLanguagesController.php',
'AdminLanguagesController' => '',
'AdminLogsControllerCore' => 'controllers/admin/AdminLogsController.php', 'AdminLogsControllerCore' => 'controllers/admin/AdminLogsController.php',
'AdminLogsController' => '', 'AdminLogsController' => '',
'AdminMetaControllerCore' => 'controllers/admin/AdminMetaController.php', 'AdminMetaControllerCore' => 'controllers/admin/AdminMetaController.php',
@@ -354,7 +360,13 @@
'AdminOrdersController' => '', 'AdminOrdersController' => '',
'AdminPDFControllerCore' => 'controllers/admin/AdminPDFController.php', 'AdminPDFControllerCore' => 'controllers/admin/AdminPDFController.php',
'AdminPDFController' => '', 'AdminPDFController' => '',
'AdminPPreferencesControllerCore' => 'controllers/admin/AdminPPreferencesController.php',
'AdminPPreferencesController' => '',
'AdminPaymentControllerCore' => 'controllers/admin/AdminPaymentController.php',
'AdminPaymentController' => '',
'AdminProductsController' => 'controllers/admin/AdminProductsController.php', 'AdminProductsController' => 'controllers/admin/AdminProductsController.php',
'AdminProfilesControllerCore' => 'controllers/admin/AdminProfilesController.php',
'AdminProfilesController' => '',
'AdminQuickAccessesController' => 'controllers/admin/AdminQuickAccessesController.php', 'AdminQuickAccessesController' => 'controllers/admin/AdminQuickAccessesController.php',
'AdminRequestSqlControllerCore' => 'controllers/admin/AdminRequestSqlController.php', 'AdminRequestSqlControllerCore' => 'controllers/admin/AdminRequestSqlController.php',
'AdminRequestSqlController' => '', 'AdminRequestSqlController' => '',
+1 -1
View File
@@ -538,7 +538,7 @@ class OrderCore extends ObjectModel
*/ */
protected function setProductCurrentStock(&$product) protected function setProductCurrentStock(&$product)
{ {
$product['current_stock'] = StockManagerFactory::getManager()->getProductRealQuantities($product['product_id'], $product['product_attribute_id'], null, true); $product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
} }
/** /**
+7 -4
View File
@@ -2085,7 +2085,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute)) else if (is_string($productAttribute))
$sql->where('stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)'); $sql->where('stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)');
} }
$sql->where(ltrim($shop->addSqlRestriction(Shop::SHARE_STOCK, 'stock'), ' AND ')); $sql->where(ltrim($shop->addSqlRestriction(false, 'stock'), ' AND '));
} }
else else
{ {
@@ -2099,7 +2099,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute)) else if (is_string($productAttribute))
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)'; $sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)';
} }
$sql .= $shop->addSqlRestriction(Shop::SHARE_STOCK, 'stock').' '; $sql .= $shop->addSqlRestriction(false, 'stock').' ';
} }
return $sql; return $sql;
@@ -2125,7 +2125,7 @@ class ProductCore extends ObjectModel
FROM '._DB_PREFIX_.'stock_available FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.' WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'. AND id_product_attribute = 0'.
$context->shop->addSqlRestriction(Shop::SHARE_STOCK); $context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql); return (int)Db::getInstance()->getValue($sql);
} }
@@ -2149,7 +2149,7 @@ class ProductCore extends ObjectModel
FROM '._DB_PREFIX_.'stock_available FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.' WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'. AND id_product_attribute = 0'.
$context->shop->addSqlRestriction(Shop::SHARE_STOCK); $context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql); return (int)Db::getInstance()->getValue($sql);
} }
@@ -2185,6 +2185,9 @@ class ProductCore extends ObjectModel
return $productObj->addStockMvt(-(int)$product['cart_quantity'], (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, null); return $productObj->addStockMvt(-(int)$product['cart_quantity'], (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, null);
} }
/**
* @deprecated since 1.5.0
*/
public static function reinjectQuantities(&$orderDetail, $quantity, Context $context = null) public static function reinjectQuantities(&$orderDetail, $quantity, Context $context = null)
{ {
if (!$context) if (!$context)
+1 -5
View File
@@ -34,7 +34,6 @@ class GroupShopCore extends ObjectModel
public $active; public $active;
public $share_customer; public $share_customer;
public $share_order; public $share_order;
public $share_stock;
public $deleted; public $deleted;
protected $fieldsSize = array('name' => 64); protected $fieldsSize = array('name' => 64);
@@ -42,7 +41,6 @@ class GroupShopCore extends ObjectModel
'active' => 'isBool', 'active' => 'isBool',
'share_customer' => 'isBool', 'share_customer' => 'isBool',
'share_order' => 'isBool', 'share_order' => 'isBool',
'share_stock' => 'isBool',
'name' => 'isGenericName', 'name' => 'isGenericName',
); );
protected $table = 'group_shop'; protected $table = 'group_shop';
@@ -51,7 +49,6 @@ class GroupShopCore extends ObjectModel
private static $assoTables = array( private static $assoTables = array(
'attribute_group' => array('type' => 'group_shop'), 'attribute_group' => array('type' => 'group_shop'),
'attribute' => array('type' => 'group_shop'), 'attribute' => array('type' => 'group_shop'),
//'customer_group' => array('type' => 'group_shop'),
'feature' => array('type' => 'group_shop'), 'feature' => array('type' => 'group_shop'),
'group' => array('type' => 'group_shop'), 'group' => array('type' => 'group_shop'),
'manufacturer' => array('type' => 'group_shop'), 'manufacturer' => array('type' => 'group_shop'),
@@ -66,8 +63,7 @@ class GroupShopCore extends ObjectModel
$fields['name'] = pSQL($this->name); $fields['name'] = pSQL($this->name);
$fields['share_customer'] = (int)$this->share_customer; $fields['share_customer'] = (int)$this->share_customer;
$fields['share_stock'] = (int)$this->share_stock; $fields['share_order'] = ($fields['share_customer']) ? (int)$this->share_order : false;
$fields['share_order'] = ($fields['share_customer'] && $fields['share_stock']) ? (int)$this->share_order : false;
$fields['active'] = (int)$this->active; $fields['active'] = (int)$this->active;
$fields['deleted'] = (int)$this->deleted; $fields['deleted'] = (int)$this->deleted;
return $fields; return $fields;
+4 -15
View File
@@ -79,7 +79,6 @@ class ShopCore extends ObjectModel
'module_currency' => array('type' => 'fk_shop'), 'module_currency' => array('type' => 'fk_shop'),
'module_country' => array('type' => 'fk_shop'), 'module_country' => array('type' => 'fk_shop'),
'module_group' => array('type' => 'fk_shop'), 'module_group' => array('type' => 'fk_shop'),
//'stock' => array('type' => 'fk_shop', 'primary' => 'id_stock'),
'product' => array('type' => 'shop'), 'product' => array('type' => 'shop'),
'product_lang' => array('type' => 'fk_shop'), 'product_lang' => array('type' => 'fk_shop'),
'referrer' => array('type' => 'shop'), 'referrer' => array('type' => 'shop'),
@@ -108,7 +107,6 @@ class ShopCore extends ObjectModel
*/ */
const SHARE_CUSTOMER = 'share_customer'; const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order'; const SHARE_ORDER = 'share_order';
const SHARE_STOCK = 'share_stock';
public function getFields() public function getFields()
{ {
@@ -162,14 +160,6 @@ class ShopCore extends ObjectModel
foreach (Shop::getAssoTables() as $table_name => $row) foreach (Shop::getAssoTables() as $table_name => $row)
{ {
// Special case for stock if current shop is in a share stock group
/*if ($table_name == 'stock')
{
$group = new GroupShop($this->id_group_shop);
if ($group->share_stock && $group->getTotalShops() > 1)
continue;
}*/
$id = 'id_'.$row['type']; $id = 'id_'.$row['type'];
if ($row['type'] == 'fk_shop') if ($row['type'] == 'fk_shop')
$id = 'id_shop'; $id = 'id_shop';
@@ -410,7 +400,6 @@ class ShopCore extends ObjectModel
'name' => $row['group_name'], 'name' => $row['group_name'],
'share_customer' => $row['share_customer'], 'share_customer' => $row['share_customer'],
'share_order' => $row['share_order'], 'share_order' => $row['share_order'],
'share_stock' => $row['share_stock'],
'totalShops' => self::getTotalShopsByIdGroupShop($row['id_group_shop']), 'totalShops' => self::getTotalShopsByIdGroupShop($row['id_group_shop']),
'shops' => array(), 'shops' => array(),
); );
@@ -537,12 +526,12 @@ class ShopCore extends ObjectModel
* If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID * If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID
* *
* @param int $shop_id * @param int $shop_id
* @param int $type Shop::SHARE_CUSTOMER | Shop::SHARE_ORDER | Shop::SHARE_STOCK * @param int $type Shop::SHARE_CUSTOMER | Shop::SHARE_ORDER
* @return array * @return array
*/ */
public static function getSharedShops($shop_id, $type) public static function getSharedShops($shop_id, $type)
{ {
if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER, Shop::SHARE_STOCK))) if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER)))
die('Wrong argument ($type) in Shop::getSharedShops() method'); die('Wrong argument ($type) in Shop::getSharedShops() method');
Shop::cacheShops(); Shop::cacheShops();
@@ -670,8 +659,8 @@ class ShopCore extends ObjectModel
{ {
if ($shop_id || $shop_group_id) if ($shop_id || $shop_group_id)
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') '; $restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') ';
else if ($share == Shop::SHARE_STOCK) //else if ($share == Shop::SHARE_STOCK)
$restriction = ' AND '.$alias.'id_shop = '.$this->getID(true); // $restriction = ' AND '.$alias.'id_shop = '.$this->getID(true);
} }
return $restriction; return $restriction;
@@ -83,27 +83,6 @@ class AdminGroupShopControllerCore extends AdminController
), ),
'p' => $this->l('Share customers between shops of this group') 'p' => $this->l('Share customers between shops of this group')
), ),
array(
'type' => 'radio',
'label' => $this->l('Share stock:'),
'name' => 'share_stock',
'required' => true,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'share_stock_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'share_stock_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'p' => $this->l('Share stock between shops of this group')
),
array( array(
'type' => 'radio', 'type' => 'radio',
'label' => $this->l('Share orders:'), 'label' => $this->l('Share orders:'),
@@ -159,7 +138,6 @@ class AdminGroupShopControllerCore extends AdminController
if (Shop::getTotalShops() > 1 && $obj->id) if (Shop::getTotalShops() > 1 && $obj->id)
$disabled = array( $disabled = array(
'share_customer' => true, 'share_customer' => true,
'share_stock' => true,
'share_order' => true, 'share_order' => true,
'active' => false 'active' => false
); );
@@ -59,7 +59,6 @@ class AdminProductsController extends AdminController
'name_category' => array('title' => $this->l('Category'), 'width' => 100, 'filter_key' => 'cl!name'), 'name_category' => array('title' => $this->l('Category'), 'width' => 100, 'filter_key' => 'cl!name'),
'price' => array('title' => $this->l('Base price'), 'width' => 70, 'price' => true, 'align' => 'right', 'filter_key' => 'a!price'), 'price' => array('title' => $this->l('Base price'), 'width' => 70, 'price' => true, 'align' => 'right', 'filter_key' => 'a!price'),
'price_final' => array('title' => $this->l('Final price'), 'width' => 70, 'price' => true, 'align' => 'right', 'havingFilter' => true, 'orderby' => false), 'price_final' => array('title' => $this->l('Final price'), 'width' => 70, 'price' => true, 'align' => 'right', 'havingFilter' => true, 'orderby' => false),
'quantity' => array('title' => $this->l('Quantity'), 'width' => 30, 'align' => 'right', 'filter_key' => 'a!quantity', 'type' => 'decimal'),
'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'filter_key' => 'a!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false), 'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'filter_key' => 'a!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false),
'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position'), 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position'),
); );
@@ -70,14 +69,14 @@ class AdminProductsController extends AdminController
else else
$this->_category = new Category(1); $this->_category = new Category(1);
$this->_join = Product::sqlStock('a').' $this->_join = '
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (a.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang`) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (a.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang`)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$this->context->country->id.' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$this->context->country->id.' AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)'; LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)';
$this->_filter = 'AND cp.`id_category` = '.(int)($this->_category->id); $this->_filter = 'AND cp.`id_category` = '.(int)($this->_category->id);
$this->_select = 'cl.name `name_category`, cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final, SUM(stock.quantity) AS quantity'; $this->_select = 'cl.name `name_category`, cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final';
parent::__construct(); parent::__construct();
} }
+1 -1
View File
@@ -327,7 +327,7 @@ class MailAlerts extends Module
$sql = 'SELECT id_product, quantity $sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock_available FROM '._DB_PREFIX_.'stock_available
WHERE id_product_attribute = '.(int)$params['id_product_attribute'] WHERE id_product_attribute = '.(int)$params['id_product_attribute']
.Context::getContext()->shop->addSqlRestriction(Shop::SHARE_STOCK); .Context::getContext()->shop->addSqlRestriction();
$result = Db::getInstance()->getRow($sql); $result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0) if ($this->_customer_qty AND $result['quantity'] > 0)