// Fixed stock_available when ordering products

This commit is contained in:
bMancone
2012-04-16 13:39:15 +00:00
parent b1202ee5dd
commit 662f94c93a
4 changed files with 47 additions and 12 deletions
+17 -2
View File
@@ -189,7 +189,7 @@ abstract class PaymentModuleCore extends Module
$order->invoice_date = '0000-00-00 00:00:00'; $order->invoice_date = '0000-00-00 00:00:00';
$order->delivery_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00';
// Creating order // Creating order
$result = $order->add(); $result = $order->add();
@@ -199,7 +199,7 @@ abstract class PaymentModuleCore extends Module
if (!$order->addOrderPayment($amount_paid)) if (!$order->addOrderPayment($amount_paid))
throw new PrestaShopException('Can\'t save Order Payment'); throw new PrestaShopException('Can\'t save Order Payment');
} }
// Amount paid by customer is not the right one -> Status = payment error // Amount paid by customer is not the right one -> Status = payment error
// We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php
// if ($order->total_paid != $order->total_paid_real) // if ($order->total_paid != $order->total_paid_real)
@@ -552,6 +552,21 @@ abstract class PaymentModuleCore extends Module
$file_attachement $file_attachement
); );
} }
// updates stock in shops
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
{
$product_list = $order->getProducts();
foreach ($product_list as $product)
{
// if the available quantities depends on the physical stock
if (StockAvailable::dependsOnStock($product['product_id']))
{
// synchronizes
StockAvailable::synchronize($product['product_id']);
}
}
}
} }
else else
{ {
+7 -2
View File
@@ -131,7 +131,7 @@ class OrderDetailCore extends ObjectModel
/** @var float $tax_rate **/ /** @var float $tax_rate **/
public $tax_rate; public $tax_rate;
/** @var int Id warehouse */ /** @var int Id warehouse */
public $id_warehouse; public $id_warehouse;
@@ -364,8 +364,13 @@ class OrderDetailCore extends ObjectModel
{ {
if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR')) if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR'))
{ {
if (StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity'])) $update_quantity = true;
if (!StockAvailable::dependsOnStock($product['id_product']))
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);
if ($update_quantity)
$product['stock_quantity'] -= $product['cart_quantity']; $product['stock_quantity'] -= $product['cart_quantity'];
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT'))
$this->outOfStock = true; $this->outOfStock = true;
Product::updateDefaultAttribute($product['id_product']); Product::updateDefaultAttribute($product['id_product']);
+8 -4
View File
@@ -109,7 +109,8 @@ class OrderHistoryCore extends ObjectModel
ProductSale::addProductSale($product['product_id'], $product['product_quantity']); ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
// @since 1.5.0 - Stock Management // @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) && if (!Pack::isPack($product['product_id']) &&
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED'))) ($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop); StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
} }
// if becoming unlogable => removes sale // if becoming unlogable => removes sale
@@ -119,12 +120,14 @@ class OrderHistoryCore extends ObjectModel
// @since 1.5.0 - Stock Management // @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) && if (!Pack::isPack($product['product_id']) &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED'))) ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop); StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
} }
// if waiting for payment => payment error/canceled // if waiting for payment => payment error/canceled
else if (!$new_os->logable && !$old_os->logable && else if (!$new_os->logable && !$old_os->logable &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED'))) ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop); StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
// @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management : // @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management :
// decrements the physical stock using $id_warehouse // decrements the physical stock using $id_warehouse
@@ -176,7 +179,8 @@ class OrderHistoryCore extends ObjectModel
true true
); );
} }
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); if (!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop);
} }
} }
} }
+15 -4
View File
@@ -315,7 +315,6 @@ class AdminOrdersControllerCore extends AdminController
$history->id_order = $order->id; $history->id_order = $order->id;
$history->id_employee = (int)$this->context->employee->id; $history->id_employee = (int)$this->context->employee->id;
$history->changeIdOrderState($order_state->id, $order->id); $history->changeIdOrderState($order_state->id, $order->id);
$carrier = new Carrier($order->id_carrier, $order->id_lang); $carrier = new Carrier($order->id_carrier, $order->id_lang);
$templateVars = array(); $templateVars = array();
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number)
@@ -333,7 +332,19 @@ class AdminOrdersControllerCore extends AdminController
); );
// Save all changes // Save all changes
if ($history->addWithemail(true, $templateVars)) if ($history->addWithemail(true, $templateVars))
{
// synchronizes quantities if needed..
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
{
foreach ($order->getProducts() as $product)
{
if (StockAvailable::dependsOnStock($product['product_id']))
StockAvailable::synchronize($product['product_id']);
}
}
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&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.'); $this->errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.');
} }
else else
@@ -1579,7 +1590,7 @@ class AdminOrdersControllerCore extends AdminController
// Check fields validity // Check fields validity
$this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null); $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
// If multiple product_quantity, the order details concern a product customized // If multiple product_quantity, the order details concern a product customized
$product_quantity = 0; $product_quantity = 0;
if (is_array(Tools::getValue('product_quantity'))) if (is_array(Tools::getValue('product_quantity')))
@@ -1695,8 +1706,8 @@ class AdminOrdersControllerCore extends AdminController
'result' => $res, 'result' => $res,
'error' => Tools::displayError('Error occurred while editing this product line') 'error' => Tools::displayError('Error occurred while editing this product line')
))); )));
if (is_array(Tools::getValue('product_quantity'))) if (is_array(Tools::getValue('product_quantity')))
$view = $this->createTemplate('_customized_data.tpl')->fetch(); $view = $this->createTemplate('_customized_data.tpl')->fetch();
else else