// 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
+1 -1
View File
@@ -538,7 +538,7 @@ class OrderCore extends ObjectModel
*/
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);
}
/**
+9 -6
View File
@@ -2085,7 +2085,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute))
$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
{
@@ -2099,7 +2099,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute))
$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;
@@ -2125,7 +2125,7 @@ class ProductCore extends ObjectModel
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'.
$context->shop->addSqlRestriction(Shop::SHARE_STOCK);
$context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql);
}
@@ -2149,7 +2149,7 @@ class ProductCore extends ObjectModel
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'.
$context->shop->addSqlRestriction(Shop::SHARE_STOCK);
$context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql);
}
@@ -2157,7 +2157,7 @@ class ProductCore extends ObjectModel
* Update available product quantities
*
* @deprecated since 1.5.0
*
*
* @param array $product Array with ordered product (quantity, id_product_attribute if applicable)
* @return mixed Query result
*/
@@ -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);
}
/**
* @deprecated since 1.5.0
*/
public static function reinjectQuantities(&$orderDetail, $quantity, Context $context = null)
{
if (!$context)
@@ -2227,7 +2230,7 @@ class ProductCore extends ObjectModel
if ($this->isAvailableWhenOutOfStock($this->getOutOfStock()))
return true;
if(isset($this->id_product_attribute))
$id_product_attribute = $this->id_product_attribute;
else
+8 -12
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -34,15 +34,13 @@ class GroupShopCore extends ObjectModel
public $active;
public $share_customer;
public $share_order;
public $share_stock;
public $deleted;
protected $fieldsSize = array('name' => 64);
protected $fieldsValidate = array(
'active' => 'isBool',
'share_customer' => 'isBool',
'share_order' => 'isBool',
'share_stock' => 'isBool',
'name' => 'isGenericName',
);
protected $table = 'group_shop';
@@ -51,7 +49,6 @@ class GroupShopCore extends ObjectModel
private static $assoTables = array(
'attribute_group' => array('type' => 'group_shop'),
'attribute' => array('type' => 'group_shop'),
//'customer_group' => array('type' => 'group_shop'),
'feature' => array('type' => 'group_shop'),
'group' => array('type' => 'group_shop'),
'manufacturer' => array('type' => 'group_shop'),
@@ -66,20 +63,19 @@ class GroupShopCore extends ObjectModel
$fields['name'] = pSQL($this->name);
$fields['share_customer'] = (int)$this->share_customer;
$fields['share_stock'] = (int)$this->share_stock;
$fields['share_order'] = ($fields['share_customer'] && $fields['share_stock']) ? (int)$this->share_order : false;
$fields['share_order'] = ($fields['share_customer']) ? (int)$this->share_order : false;
$fields['active'] = (int)$this->active;
$fields['deleted'] = (int)$this->deleted;
return $fields;
}
public static function getGroupShops($active = true)
{
return Db::getInstance()->executeS('SELECT *
return Db::getInstance()->executeS('SELECT *
FROM '._DB_PREFIX_.'group_shop
WHERE `deleted`= 0 AND `active`='.(int)$active);
}
public function delete()
{
if (!$res = parent::delete())
@@ -126,7 +122,7 @@ class GroupShopCore extends ObjectModel
/**
* Return a group shop ID from group shop name
*
*
* @param string $name
* @return int
*/
@@ -137,7 +133,7 @@ class GroupShopCore extends ObjectModel
WHERE name = \''.pSQL($name).'\'';
return (int)Db::getInstance()->getValue($sql);
}
public function copyGroupShopData($old_id, $tables_import = false, $deleted = false)
{
foreach (GroupShop::getAssoTables() AS $table_name => $row)
+4 -15
View File
@@ -79,7 +79,6 @@ class ShopCore extends ObjectModel
'module_currency' => array('type' => 'fk_shop'),
'module_country' => array('type' => 'fk_shop'),
'module_group' => array('type' => 'fk_shop'),
//'stock' => array('type' => 'fk_shop', 'primary' => 'id_stock'),
'product' => array('type' => 'shop'),
'product_lang' => array('type' => 'fk_shop'),
'referrer' => array('type' => 'shop'),
@@ -108,7 +107,6 @@ class ShopCore extends ObjectModel
*/
const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order';
const SHARE_STOCK = 'share_stock';
public function getFields()
{
@@ -162,14 +160,6 @@ class ShopCore extends ObjectModel
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'];
if ($row['type'] == 'fk_shop')
$id = 'id_shop';
@@ -410,7 +400,6 @@ class ShopCore extends ObjectModel
'name' => $row['group_name'],
'share_customer' => $row['share_customer'],
'share_order' => $row['share_order'],
'share_stock' => $row['share_stock'],
'totalShops' => self::getTotalShopsByIdGroupShop($row['id_group_shop']),
'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
*
* @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
*/
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');
Shop::cacheShops();
@@ -670,8 +659,8 @@ class ShopCore extends ObjectModel
{
if ($shop_id || $shop_group_id)
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') ';
else if ($share == Shop::SHARE_STOCK)
$restriction = ' AND '.$alias.'id_shop = '.$this->getID(true);
//else if ($share == Shop::SHARE_STOCK)
// $restriction = ' AND '.$alias.'id_shop = '.$this->getID(true);
}
return $restriction;