From 78ddaa120ca7b92ac4cebf29b5d01d30c248f946 Mon Sep 17 00:00:00 2001
From: mDeflotte
Date: Thu, 20 Oct 2011 09:08:59 +0000
Subject: [PATCH] // Stock decrementation when order is shipped
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9486 b9a71923-0436-4b27-9f14-aed3839534dd
---
admin-dev/tabs/AdminAccess.php | 2 +-
admin-dev/tabs/AdminImport.php | 2 +-
admin-dev/tabs/AdminOrders.php | 126 +++++++++++-------
admin-dev/tabs/AdminOrdersStates.php | 9 +-
admin-dev/tabs/AdminProducts.php | 2 -
classes/Currency.php | 68 +++++-----
classes/Order.php | 2 +-
classes/OrderHistory.php | 12 +-
classes/OrderState.php | 36 ++---
classes/Product.php | 2 +
classes/stock/Stock.php | 25 ++++
classes/stock/StockAvailable.php | 13 +-
classes/stock/Warehouse.php | 9 ++
.../AdminStockInstantStateController.php | 7 +-
install-dev/sql/db.sql | 11 +-
install-dev/sql/db_settings_lite.sql | 8 +-
install-dev/sql/upgrade/1.5.0.1.sql | 3 +
17 files changed, 212 insertions(+), 125 deletions(-)
diff --git a/admin-dev/tabs/AdminAccess.php b/admin-dev/tabs/AdminAccess.php
index e32e238d9..37b531e4c 100644
--- a/admin-dev/tabs/AdminAccess.php
+++ b/admin-dev/tabs/AdminAccess.php
@@ -38,7 +38,7 @@ class AdminAccess extends AdminTab
if (!in_array($perm, array('view', 'add', 'edit', 'delete', 'all')))
throw new PrestashopException('permission not exists');
- $enabled = (int)Tools::getValue('enabled') ;
+ $enabled = (int)Tools::getValue('enabled');
$id_tab = (int)(Tools::getValue('id_tab'));
$id_profile = (int)(Tools::getValue('id_profile'));
$res = true;
diff --git a/admin-dev/tabs/AdminImport.php b/admin-dev/tabs/AdminImport.php
index 5b0ac7e04..70c278e88 100644
--- a/admin-dev/tabs/AdminImport.php
+++ b/admin-dev/tabs/AdminImport.php
@@ -984,7 +984,7 @@ class AdminImport extends AdminTab
$this->_warnings[] = sprintf(Tools::displayError('No image found for combination with id_product = %s and image position = %s.'), $product->id, (int)$info['image_position']);
}
- $id_product_attribute = $product->addProductAttribute((float)($info['price']), (float)($info['weight']), 0, (float)($info['ecotax']), (int)($info['quantity']), $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int)($info['default_on']), strval($info['upc']));
+ $id_product_attribute = $product->addProductAttribute((float)($info['price']), (float)($info['weight']), 0, (float)($info['ecotax']), $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int)($info['default_on']), strval($info['upc']));
$id_attribute_group = 0;
$group = '';
foreach (explode($fsep, $info['group']) as $group)
diff --git a/admin-dev/tabs/AdminOrders.php b/admin-dev/tabs/AdminOrders.php
index cfe035e8d..600724fa2 100644
--- a/admin-dev/tabs/AdminOrders.php
+++ b/admin-dev/tabs/AdminOrders.php
@@ -30,19 +30,19 @@ class AdminOrders extends AdminTab
public function __construct()
{
$this->context = Context::getContext();
- $this->table = 'order';
- $this->className = 'Order';
- $this->view = true;
+ $this->table = 'order';
+ $this->className = 'Order';
+ $this->view = true;
$this->colorOnBackground = true;
- $this->_select = '
+ $this->_select = '
a.id_order AS id_pdf,
CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
os.`color`,
IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new,
(SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';
- $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
- LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`)
+ $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
+ LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';
@@ -52,7 +52,7 @@ class AdminOrders extends AdminTab
foreach ($states AS $state)
$statesArray[$state['id_order_state']] = $state['name'];
- $this->fieldsDisplay = array(
+ $this->fieldsDisplay = array(
'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),
'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),
@@ -61,14 +61,13 @@ class AdminOrders extends AdminTab
'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));
- $this->shopLinkType = 'shop';
- $this->shopShareDatas = Shop::SHARE_ORDER;
+ $this->shopLinkType = 'shop';
+ $this->shopShareDatas = Shop::SHARE_ORDER;
parent::__construct();
}
public function postProcess()
{
-
/* Update shipping number */
if (Tools::isSubmit('submitShippingNumber') AND ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order)))
{
@@ -116,24 +115,29 @@ class AdminOrders extends AdminTab
$history = new OrderHistory();
$history->id_order = (int)$id_order;
$history->id_employee = (int)$this->context->employee->id;
- $history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order));
- $order = new Order((int)$order->id);
- $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang));
- $templateVars = array();
- if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number)
- $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
- elseif ($history->id_order_state == Configuration::get('PS_OS_CHEQUE'))
- $templateVars = array(
- '{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''),
- '{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : ''));
- elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE'))
- $templateVars = array(
- '{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''),
- '{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''),
- '{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : ''));
- if ($history->addWithemail(true, $templateVars))
- Tools::redirectAdmin(self::$currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token);
- $this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.');
+ if (!(int)Tools::getValue('id_warehouse'))
+ $this->_errors[] = Tools::displayError('An error occurred while changing the status.');
+ else
+ {
+ $history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order), (int)Tools::getValue('id_warehouse'));
+ $order = new Order((int)$order->id);
+ $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang));
+ $templateVars = array();
+ if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number)
+ $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
+ else if ($history->id_order_state == Configuration::get('PS_OS_CHEQUE'))
+ $templateVars = array(
+ '{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''),
+ '{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : ''));
+ elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE'))
+ $templateVars = array(
+ '{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''),
+ '{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''),
+ '{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : ''));
+ if ($history->addWithemail(true, $templateVars))
+ Tools::redirectAdmin(self::$currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token);
+ $this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.');
+ }
}
}
else
@@ -144,7 +148,7 @@ class AdminOrders extends AdminTab
elseif (isset($_POST['submitMessage']))
{
$_GET['view'.$this->table] = true;
- if ($this->tabAccess['edit'] === '1')
+ if ($this->tabAccess['edit'] === '1')
{
if (!($id_order = (int)(Tools::getValue('id_order'))) OR !($id_customer = (int)(Tools::getValue('id_customer'))))
$this->_errors[] = Tools::displayError('An error occurred before sending message');
@@ -232,14 +236,14 @@ class AdminOrders extends AdminTab
$full_product_list = $productList;
$full_quantity_list = $qtyList;
- if ($customizationList)
- {
- foreach ($customizationList as $key => $id_order_detail)
- {
- $full_product_list[$id_order_detail] = $id_order_detail;
- $full_quantity_list[$id_order_detail] = $customizationQtyList[$key];
- }
- }
+ if ($customizationList)
+ {
+ foreach ($customizationList as $key => $id_order_detail)
+ {
+ $full_product_list[$id_order_detail] = $id_order_detail;
+ $full_quantity_list[$id_order_detail] = $customizationQtyList[$key];
+ }
+ }
if ($productList OR $customizationList)
{
@@ -575,9 +579,37 @@ class AdminOrders extends AdminTab
';
+ $warehouse_list = Warehouse::getWarehouseList();
+ echo '';
+
echo '
+
';
@@ -594,7 +626,7 @@ class AdminOrders extends AdminTab
{
echo '
'.$this->l('This order has been placed by a').' '.$this->l('guest').'';
- if(!Customer::customerExists($customer->email))
+ if (!Customer::customerExists($customer->email))
{
echo '
-
+
+
';
diff --git a/admin-dev/tabs/AdminProducts.php b/admin-dev/tabs/AdminProducts.php
index df90c0fc6..b871e4893 100644
--- a/admin-dev/tabs/AdminProducts.php
+++ b/admin-dev/tabs/AdminProducts.php
@@ -514,7 +514,6 @@ class AdminProducts extends AdminTab
Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
Tools::getValue('attribute_ecotax'),
- false,
Tools::getValue('id_image_attr'),
Tools::getValue('attribute_reference'),
Tools::getValue('attribute_supplier_reference'),
@@ -556,7 +555,6 @@ class AdminProducts extends AdminTab
Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
Tools::getValue('attribute_ecotax'),
- Tools::getValue('attribute_quantity'),
Tools::getValue('id_image_attr'),
Tools::getValue('attribute_reference'),
Tools::getValue('attribute_supplier_reference'),
diff --git a/classes/Currency.php b/classes/Currency.php
index d33f201bb..8cc7f9235 100644
--- a/classes/Currency.php
+++ b/classes/Currency.php
@@ -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
diff --git a/classes/Order.php b/classes/Order.php
index 98726bf9d..ef55b047a 100644
--- a/classes/Order.php
+++ b/classes/Order.php
@@ -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`)
diff --git a/classes/OrderHistory.php b/classes/OrderHistory.php
index 2f3b8bbaf..c35d38591 100644
--- a/classes/OrderHistory.php
+++ b/classes/OrderHistory.php
@@ -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);
diff --git a/classes/OrderState.php b/classes/OrderState.php
index 16f720253..b50db5d29 100644
--- a/classes/OrderState.php
+++ b/classes/OrderState.php
@@ -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;
}
diff --git a/classes/Product.php b/classes/Product.php
index 2ca356827..cf5c89c59 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -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
*/
diff --git a/classes/stock/Stock.php b/classes/stock/Stock.php
index 6a84c8149..f82791e0e 100644
--- a/classes/stock/Stock.php
+++ b/classes/stock/Stock.php
@@ -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);
+ }
}
\ No newline at end of file
diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php
index 771255a70..70a404add 100644
--- a/classes/stock/StockAvailable.php
+++ b/classes/stock/StockAvailable.php
@@ -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();
diff --git a/classes/stock/Warehouse.php b/classes/stock/Warehouse.php
index fdaf63fc3..1dd7a4665 100644
--- a/classes/stock/Warehouse.php
+++ b/classes/stock/Warehouse.php
@@ -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);
+ }
}
diff --git a/controllers/admin/AdminStockInstantStateController.php b/controllers/admin/AdminStockInstantStateController.php
index 1044d8b99..f0778133f 100644
--- a/controllers/admin/AdminStockInstantStateController.php
+++ b/controllers/admin/AdminStockInstantStateController.php
@@ -93,12 +93,7 @@ class AdminStockInstantStateControllerCore extends AdminController
public function initContent()
{
- $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));
-
- $this->context->smarty->assign('warehouse_list', Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query));
+ $this->context->smarty->assign('warehouse_list', Warehouse::getWarehouseList());
$this->context->smarty->assign('current_warehouse', $this->getCurrentWarehouseId());
parent::initContent();
diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql
index 04d6d893a..50490dfcf 100644
--- a/install-dev/sql/db.sql
+++ b/install-dev/sql/db.sql
@@ -1118,14 +1118,15 @@ CREATE TABLE `PREFIX_order_slip_detail` (
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_order_state` (
- `id_order_state` int(10) unsigned NOT NULL auto_increment,
- `invoice` tinyint(1) unsigned default '0',
- `send_email` tinyint(1) unsigned NOT NULL default '0',
+ `id_order_state` int(10) UNSIGNED NOT NULL auto_increment,
+ `invoice` tinyint(1) UNSIGNED default '0',
+ `send_email` tinyint(1) UNSIGNED NOT NULL default '0',
`color` varchar(32) default NULL,
- `unremovable` tinyint(1) unsigned NOT NULL,
+ `unremovable` tinyint(1) UNSIGNED NOT NULL,
`hidden` tinyint(1) UNSIGNED NOT NULL default '0',
`logable` tinyint(1) NOT NULL default '0',
- `delivery` tinyint(1) unsigned NOT NULL default '0',
+ `delivery` tinyint(1) UNSIGNED NOT NULL default '0',
+ `shipped` tinyint(1) UNSIGNED NOT NULL default '0',
PRIMARY KEY (`id_order_state`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql
index 9bee48250..deab4ed26 100644
--- a/install-dev/sql/db_settings_lite.sql
+++ b/install-dev/sql/db_settings_lite.sql
@@ -265,9 +265,9 @@ INSERT INTO `PREFIX_category` (`id_category`, `id_parent`, `level_depth`, `nleft
INSERT INTO `PREFIX_category_lang` (`id_category`, `id_lang`, `name`, `description`, `link_rewrite`, `meta_title`, `meta_keywords`, `meta_description`) VALUES
(1, 1, 'Home', '', 'home', NULL, NULL, NULL),(1, 2, 'Accueil', '', 'home', NULL, NULL, NULL),(1, 3, 'Inicio', '', 'home', NULL, NULL, NULL),(1, 4, 'Start', '', 'home', NULL, NULL, NULL),(1, 5, 'Home page', '', 'home', NULL, NULL, NULL);
-INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`) VALUES
-(1, 0, 1, 'lightblue', 1, 0, 0),(2, 1, 1, '#DDEEFF', 1, 1, 0),(3, 1, 1, '#FFDD99', 1, 1, 1),(4, 1, 1, '#EEDDFF', 1, 1, 1),(5, 1, 0, '#DDFFAA', 1, 1, 1),
-(6, 0, 1, '#DADADA', 1, 0, 0),(7, 1, 1, '#FFFFBB', 1, 0, 0),(8, 0, 1, '#FFDFDF', 1, 0, 0),(9, 1, 1, '#FFD3D3', 1, 0, 0),(10, 0, 1, 'lightblue', 1, 0, 0),(11, 0, 0, 'lightblue', 1, 0, 0),(12, 1, 0, '#DDEEFF', 1, 1, 0);
+INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`, `shipped`) VALUES
+(1, 0, 1, 'lightblue', 1, 0, 0, 0),(2, 1, 1, '#DDEEFF', 1, 1, 0, 0),(3, 1, 1, '#FFDD99', 1, 1, 1, 0),(4, 1, 1, '#EEDDFF', 1, 1, 1, 1),(5, 1, 0, '#DDFFAA', 1, 1, 1, 1),
+(6, 0, 1, '#DADADA', 1, 0, 0, 0),(7, 1, 1, '#FFFFBB', 1, 0, 0, 0),(8, 0, 1, '#FFDFDF', 1, 0, 0, 0),(9, 1, 1, '#FFD3D3', 1, 0, 0, 0),(10, 0, 1, 'lightblue', 1, 0, 0, 0),(11, 0, 0, 'lightblue', 1, 0, 0, 0),(12, 1, 0, '#DDEEFF', 1, 1, 0, 0);
INSERT INTO `PREFIX_order_state_lang` (`id_order_state`, `id_lang`, `name`, `template`) VALUES
(1, 1, 'Awaiting cheque payment', 'cheque'),
@@ -1370,7 +1370,7 @@ INSERT INTO `PREFIX_stock_available` (`id_stock_available`, `id_product`, `id_pr
(38, 9, 0, 1, 1, 0, 2);
INSERT INTO `PREFIX_warehouse` (`id_warehouse`, `id_currency`, `id_address`, `id_employee`, `reference`, `name`, `management_type`) VALUES
-(1, 1, 0, 1, 'default_warehouse', 'default warehous', 'FIFO');
+(1, 1, 0, 1, 'default_warehouse', 'default warehouse', 'FIFO');
INSERT INTO `PREFIX_warehouse_shop` (`id_warehouse`, `id_shop`) VALUES
(1, 1);
diff --git a/install-dev/sql/upgrade/1.5.0.1.sql b/install-dev/sql/upgrade/1.5.0.1.sql
index ef0d0e4f4..0c0194ed4 100644
--- a/install-dev/sql/upgrade/1.5.0.1.sql
+++ b/install-dev/sql/upgrade/1.5.0.1.sql
@@ -218,3 +218,6 @@ INSERT INTO `PREFIX_module_access` (`id_profile`, `id_module`, `configure`, `vie
ALTER TABLE `PREFIX_carrier` ADD `position` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
/* PHP:add_carrier_position();*/
+
+ALTER TABLE `PREFIX_order_state` ADD COLUMN `shipped` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `delivery`;
+UPDATE `PREFIX_order_state` SET `shipped` = 1 WHERE id_order_states IN (4, 5);