// Stock : product can now be returned
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11091 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -189,4 +189,25 @@ class ProductSupplierCore extends ObjectModel
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given Supplier, Product, returns the purchased price
|
||||
*
|
||||
* @param int $id_product
|
||||
* @param int $id_product_attribute Optional
|
||||
* @return Array keys: price_te, id_currency
|
||||
*/
|
||||
public static function getProductPrice($id_supplier, $id_product, $id_product_attribute = 0)
|
||||
{
|
||||
if (is_null($id_supplier) || is_null($id_product))
|
||||
return;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('product_supplier_price_te as price_te, id_currency');
|
||||
$query->from('product_supplier');
|
||||
$query->where('id_product = '.(int)$id_product.' AND id_product_attribute = '.(int)$id_product_attribute);
|
||||
$query->where('id_supplier = '.(int)$id_supplier);
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,13 +455,15 @@ class StockManagerCore implements StockManagerInterface
|
||||
|
||||
// Gets client_orders_qty
|
||||
$query = new DbQuery();
|
||||
$query->select('SUM(od.product_quantity)');
|
||||
$query->select('SUM(od.product_quantity) + SUM(od.product_quantity_refunded)');
|
||||
$query->from('order_detail od');
|
||||
$query->leftjoin('orders o ON o.id_order = od.id_order');
|
||||
$query->where('od.product_id = '.(int)$id_product);
|
||||
if (0 != $id_product_attribute)
|
||||
$query->where('od.product_attribute_id = '.(int)$id_product_attribute);
|
||||
$query->where('o.delivery_number = 0');
|
||||
$query->leftJoin('order_history oh ON (oh.id_order = o.id_order AND oh.date_add = o.date_upd)');
|
||||
$query->leftJoin('order_state os ON (os.id_order_state = oh.id_order_state)');
|
||||
$query->where('os.shipped != 1');
|
||||
$query->where('o.valid = 1');
|
||||
// @FIXME: Once part-shipping is done, remove the comment on the line below.
|
||||
// $query->where('o.id_warehouse IN (0, '.implode(', ', $ids_warehouse).')');
|
||||
|
||||
@@ -428,34 +428,45 @@ class AdminOrdersControllerCore extends AdminController
|
||||
if (!sizeof($this->_errors) AND $productList)
|
||||
foreach ($productList AS $key => $id_order_detail)
|
||||
{
|
||||
$qtyCancelProduct = abs($qtyList[$key]);
|
||||
$orderDetail = new OrderDetail((int)($id_order_detail));
|
||||
$qty_cancel_product = abs($qtyList[$key]);
|
||||
$order_detail = new OrderDetail((int)($id_order_detail));
|
||||
|
||||
// Reinject product
|
||||
if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Tools::isSubmit('reinjectQuantities')))
|
||||
{
|
||||
$reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected);
|
||||
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
|
||||
// TODO (Denis) : fix reinject quantities
|
||||
// if (!Product::reinjectQuantities($orderDetail, $quantityToReinject))
|
||||
// $this->_errors[] = Tools::displayError('Cannot re-stock product').' <span class="bold">'.$orderDetail->product_name.'</span>';
|
||||
// else
|
||||
// {
|
||||
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int)($orderDetail->product_attribute_id) : NULL;
|
||||
$newProductQty = Product::getQuantity($orderDetail->product_id, $updProductAttributeID);
|
||||
$product = get_object_vars(new Product($orderDetail->product_id, false, $this->context->language->id, $order->id_shop));
|
||||
if (!empty($orderDetail->product_attribute_id))
|
||||
{
|
||||
$updProduct['quantity_attribute'] = (int)($newProductQty);
|
||||
$product['quantity_attribute'] = $updProduct['quantity_attribute'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$updProduct['stock_quantity'] = (int)($newProductQty);
|
||||
$product['stock_quantity'] = $updProduct['stock_quantity'];
|
||||
}
|
||||
Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
|
||||
// }
|
||||
$reinjectable_quantity = (int)$qty_cancel_product->product_quantity - (int)$qty_cancel_product->product_quantity_reinjected;
|
||||
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
|
||||
|
||||
// @since 1.5.0 : Advanced Stock Management
|
||||
$product_to_inject = new Product($qty_cancel_product->product_id, false, $this->context->language->id, $order->id_shop);
|
||||
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $qty_cancel_product->id_warehouse != 0)
|
||||
{
|
||||
$id_supplier = $product_to_inject->id_supplier;
|
||||
$price = ProductSupplier::getProductPrice($id_supplier, $qty_cancel_product->product_id, $order_detail->product_attribute_id);
|
||||
$price_te = $price['price_te'];
|
||||
$id_currency = $price['id_currency'];
|
||||
$warehouse = new Warehouse($id_warehouse);
|
||||
|
||||
$price_te = Tools::convertPriceFull($price_te, $from = new Currency($id_currency), $to = new Currency($warehouse->id_currency));
|
||||
|
||||
$stock_manager->addProduct($qty_cancel_product->product_id,
|
||||
$qty_cancel_product->product_attribute_id,
|
||||
$warehouse,
|
||||
$quantity_to_reinject,
|
||||
null,
|
||||
$price_te,
|
||||
true);
|
||||
StockAvailable::synchronize($order_detail->product_id);
|
||||
}
|
||||
else if ($order_detail->id_warehouse == 0)
|
||||
{
|
||||
StockAvailable::updateQuantity($order_detail->product_id,
|
||||
$order_detail->product_attribute_id,
|
||||
$quantity_to_reinject,
|
||||
$order->id_shop);
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Cannot re-stock product');
|
||||
}
|
||||
|
||||
// Delete product
|
||||
|
||||
Reference in New Issue
Block a user