// Stock decrementation when order is shipped

This commit is contained in:
mDeflotte
2011-10-20 09:08:59 +00:00
parent 61c672ceeb
commit 46c9939258
17 changed files with 212 additions and 125 deletions
+34 -34
View File
@@ -27,50 +27,50 @@
class CurrencyCore extends ObjectModel
{
public $id;
public $id;
/** @var string Name */
public $name;
public $name;
/** @var string Iso code */
public $iso_code;
public $iso_code;
/** @var string Iso code numeric */
public $iso_code_num;
public $iso_code_num;
/** @var string Symbol for short display */
public $sign;
public $sign;
/** @var int bool used for displaying blank between sign and price */
public $blank;
public $blank;
/** @var string Conversion rate from euros */
public $conversion_rate;
public $conversion_rate;
/** @var boolean True if currency has been deleted (staying in database as deleted) */
public $deleted = 0;
public $deleted = 0;
/** @var int ID used for displaying prices */
public $format;
public $format;
/** @var int bool Display decimals on prices */
public $decimals;
public $decimals;
/** @var int bool active */
public $active;
public $active;
protected $fieldsRequired = array('name', 'iso_code', 'sign', 'conversion_rate', 'format', 'decimals');
protected $fieldsSize = array('name' => 32, 'iso_code' => 3, 'iso_code_num' => 3, 'sign' => 8);
protected $fieldsValidate = array('name' => 'isGenericName', 'iso_code' => 'isLanguageIsoCode', 'iso_code_num' => 'isNumericIsoCode', 'blank' => 'isInt', 'sign' => 'isGenericName',
protected $fieldsRequired = array('name', 'iso_code', 'sign', 'conversion_rate', 'format', 'decimals');
protected $fieldsSize = array('name' => 32, 'iso_code' => 3, 'iso_code_num' => 3, 'sign' => 8);
protected $fieldsValidate = array('name' => 'isGenericName', 'iso_code' => 'isLanguageIsoCode', 'iso_code_num' => 'isNumericIsoCode', 'blank' => 'isInt', 'sign' => 'isGenericName',
'format' => 'isUnsignedId', 'decimals' => 'isBool', 'conversion_rate' => 'isFloat', 'deleted' => 'isBool', 'active' => 'isBool');
protected $table = 'currency';
protected $identifier = 'id_currency';
protected $table = 'currency';
protected $identifier = 'id_currency';
/** @var array Currency cache */
static protected $currencies = array();
static protected $currencies = array();
protected $webserviceParameters = array(
protected $webserviceParameters = array(
'objectsNodeName' => 'currencies',
);
@@ -152,11 +152,11 @@ class CurrencyCore extends ObjectModel
}
/**
* Return formated sign
*
* @param string $side left or right
* @return string formated sign
*/
* Return formated sign
*
* @param string $side left or right
* @return string formated sign
*/
public function getSign($side=NULL)
{
if (!$side)
@@ -175,10 +175,10 @@ class CurrencyCore extends ObjectModel
}
/**
* Return available currencies
*
* @return array Currencies
*/
* Return available currencies
*
* @return array Currencies
*/
static public function getCurrencies($object = false, $active = 1, Shop $shop = null)
{
if (!$shop)
@@ -267,13 +267,13 @@ class CurrencyCore extends ObjectModel
}
/**
* Refresh the currency conversion rate
* The XML file define conversion rate for each from a default currency ($isoCodeSource).
*
* @param $data XML content which contains all the conversion rates
* @param $isoCodeSource The default currency used in the XML file
* @param $defaultCurrency The default currency object
*/
* Refresh the currency conversion rate
* The XML file define conversion rate for each from a default currency ($isoCodeSource).
*
* @param $data XML content which contains all the conversion rates
* @param $isoCodeSource The default currency used in the XML file
* @param $defaultCurrency The default currency object
*/
public function refreshCurrency($data, $isoCodeSource, $defaultCurrency)
{
// fetch the conversion rate of the default currency
+1 -1
View File
@@ -607,7 +607,7 @@ class OrderCore extends ObjectModel
public function getCurrentStateFull($id_lang)
{
return Db::getInstance()->getRow('
SELECT oh.`id_order_state`, osl.`name`, os.`logable`
SELECT oh.`id_order_state`, osl.`name`, os.`logable`, os.`shipped`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (osl.`id_order_state` = oh.`id_order_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
+6 -6
View File
@@ -70,7 +70,7 @@ class OrderHistoryCore extends ObjectModel
return $fields;
}
public function changeIdOrderState($new_order_state, $id_order)
public function changeIdOrderState($new_order_state, $id_order, $id_warehouse = null)
{
if ($new_order_state != NULL)
{
@@ -89,12 +89,12 @@ class OrderHistoryCore extends ObjectModel
if ($newOS->logable AND (!$oldOrderStatus OR !$oldOrderStatus->logable))
ProductSale::addProductSale($product['id_product'], $product['cart_quantity']);
/* If becoming unlogable => removing sale */
elseif (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
else if (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']);
if (!$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == Configuration::get('PS_OS_ERROR'))
{
Product::updateQuantity($product);
}
// The product is removed from the physical stock. $id_warehouse is needed
if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0)
Stock::updateQuantity($product['id_product'], $product['id_product_attribute'], -$product['cart_quantity'], $id_warehouse, $id_order);
// @todo If the old order states was "shipped" and the new is "not shipped" the stock is not decremented
}
$this->id_order_state = (int)($new_order_state);
+20 -16
View File
@@ -28,40 +28,43 @@
class OrderStateCore extends ObjectModel
{
/** @var string Name */
public $name;
public $name;
/** @var string Template name if there is any e-mail to send */
public $template;
public $template;
/** @var boolean Send an e-mail to customer ? */
public $send_email;
public $send_email;
/** @var boolean Allow customer to view and download invoice when order is at this state */
public $invoice;
public $invoice;
/** @var string Display state in the specified color */
public $color;
public $color;
public $unremovable;
public $unremovable;
/** @var boolean Log authorization */
public $logable;
public $logable;
/** @var boolean Delivery */
public $delivery;
public $delivery;
/** @var boolean Hidden */
public $hidden;
public $hidden;
/** @var boolean Shipped */
public $shipped;
protected $fieldsValidate = array('send_email' => 'isBool', 'invoice' => 'isBool', 'color' => 'isColor', 'logable' => 'isBool');
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 64, 'template' => 64);
protected $fieldsValidateLang = array('name' => 'isGenericName', 'template' => 'isTplName');
protected $fieldsValidate = array('send_email' => 'isBool', 'invoice' => 'isBool', 'color' => 'isColor', 'logable' => 'isBool', 'shipped' => 'isBool');
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 64, 'template' => 64);
protected $fieldsValidateLang = array('name' => 'isGenericName', 'template' => 'isTplName');
protected $table = 'order_state';
protected $identifier = 'id_order_state';
protected $table = 'order_state';
protected $identifier = 'id_order_state';
protected $webserviceParameters = array(
protected $webserviceParameters = array(
'fields' => array(
'unremovable' => array(),
'delivery' => array(),
@@ -79,6 +82,7 @@ class OrderStateCore extends ObjectModel
$fields['logable'] = (int)($this->logable);
$fields['delivery'] = (int)($this->delivery);
$fields['hidden'] = (int)($this->hidden);
$fields['shipped'] = (int)($this->shipped);
return $fields;
}
+2
View File
@@ -2156,6 +2156,8 @@ 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
*/
+25
View File
@@ -73,4 +73,29 @@ class StockCore extends ObjectModel
$fields['price_te'] = (float)round($this->price_te, 6);
return $fields;
}
/**
* For a given id_product and id_product_attribute update the quantity in stock
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_warehouse, $id_order = null)
{
$warehouse = new Warehouse($id_warehouse);
// Update quantity of the pack products
if (Pack::isPack($id_product))
{
$products_pack = Pack::getItems((int)($product['id_product']), (int)(Configuration::get('PS_LANG_DEFAULT')));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1);
self::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_warehouse, $id_order);
}
}
if ($delta_quantity > 0)
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_INC_REASON_DEFAULT');
else
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_DEC_REASON_DEFAULT');
StockManagerFactory::getManager()
->removeProduct($id_product, $id_product_attribute, $warehouse, $delta_quantity, $id_stock_mvt_reason, true, (int)$id_order);
}
}
+12 -1
View File
@@ -265,7 +265,7 @@ class StockAvailableCore extends ObjectModel
}
/**
* For a given id_product and id_product_attribute update quantity the quantity available
* For a given id_product and id_product_attribute update the quantity available
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null)
{
@@ -274,6 +274,17 @@ class StockAvailableCore extends ObjectModel
if (!$id_stock)
return false;
// Update quantity of the pack products
if (Pack::isPack($id_product))
{
$products_pack = Pack::getItems((int)($product['id_product']), (int)(Configuration::get('PS_LANG_DEFAULT')));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1);
self::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_shop);
}
}
$stock_available = new StockAvailable($id_stock);
$stock_available->quantity = $stock_available->quantity + $delta_quantity;
$stock_available->save();
+9
View File
@@ -241,4 +241,13 @@ class WarehouseCore extends ObjectModel
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query));
}
public static function getWarehouseList()
{
$query = new DbQuery();
$query->select('w.id_warehouse, name');
$query->from('warehouse w');
$query->innerJoin('warehouse_shop ws ON ws.id_warehouse = w.id_warehouse AND ws.id_shop = '.Context::getContext()->shop->getID(true));
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
}