// Removing some id_warehouse

// Adding some checks with advanced_stock_management product attribute

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11375 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte
2011-12-19 16:01:41 +00:00
parent f1af46cfa6
commit 772147a6ee
10 changed files with 101 additions and 105 deletions
-38
View File
@@ -54,39 +54,6 @@
statesShipped.push({$state['id_order_state']});
{/if}
{/foreach}
{literal}
function showWarehouseList()
{
{/literal}{if (count($warehouse_list) > 1)}{literal}
$('#warehouse').show();
{/literal}{/if}{literal}
}
function hideWarehouseList()
{
$('#warehouse').hide();
}
$(document).ready(function() {
hideWarehouseList();
$("input.datepicker").datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd'
});
$('#id_order_state').change(function() {
if ($.inArray(parseInt($(this).val()), statesShipped) >= 0)
{
showWarehouseList();
}
else
{
hideWarehouseList();
}
});
});
{/literal}
</script>
{if ($HOOK_INVOICE)}
@@ -130,11 +97,6 @@
<option value="{$state['id_order_state']}" {if $state['id_order_state'] == $currentState->id}selected="selected"{/if}>{$state['name']|stripslashes}</option>
{/foreach}
</select>
<select name="id_warehouse" id="warehouse">
{foreach from=$warehouse_list item=warehouse}
<option value="{$warehouse['id_warehouse']}">{$warehouse['name']}</option>
{/foreach}
</select>
<input type="hidden" name="id_order" value="{$order->id}" />
<input type="submit" name="submitState" value="{l s='Add'}" class="button" />
</form>
@@ -61,7 +61,7 @@
<td valign="top" style="vertical-align:top;">
<input {if $product->advanced_stock_management == 1 && $stock_management_active == 1}value="on" checked="checked" {/if} {if $stock_management_active == 0}disabled="disabled" {/if}
type="checkbox" name="advanced_stock_management" class="advanced_stock_management" id="advanced_stock_management" />
<label style="float:none;font-weight:normal" for="depends_on_stock_1">{l s='I want to use the advanced stock management system for this product'} {if $stock_management_active == 0}&nbsp;-&nbsp;<b>{l s='Not possible if stock management is not enabled'}</b>{/if}</label>
<label style="float:none;font-weight:normal" for="advanced_stock_management">{l s='I want to use the advanced stock management system for this product'} {if $stock_management_active == 0}&nbsp;-&nbsp;<b>{l s='Not possible if stock management is not enabled'}</b>{/if}</label>
<br /><br />
</td>
</tr>
+4 -1
View File
@@ -1231,7 +1231,10 @@ class AdminControllerCore extends Controller
{
if (Tab::checkTabRights($tab['id_tab']) === true)
{
if ($tab['name'] == 'Stock' && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 0)
if ($tab['name'] == 'Stock'
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 0
&& (int)$product['advanced_stock_management'] == 1
)
{
unset($tabs[$index]);
continue;
+3 -2
View File
@@ -380,7 +380,8 @@ class CartCore extends ObjectModel
p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`,
stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`active`, p.`date_add`,
p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery, p.`wholesale_price`');
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery, p.`wholesale_price`,
p.advanced_stock_management');
// Build FROM
$sql->from('cart_product', 'cp');
@@ -1358,7 +1359,7 @@ class CartCore extends ObjectModel
$product['warehouse_list'] = array();
if ($stock_management_active)
if ($stock_management_active && (int)$product['advanced_stock_management'] == 1)
{
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
// Does the product is in stock ?
+1 -1
View File
@@ -3060,7 +3060,7 @@ class ProductCore extends ObjectModel
$context = Context::getContext();
$sql = new DbQuery();
$sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`');
$sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, p.advanced_stock_management');
$sql->from('category_product', 'cp');
$sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
$sql->join($context->shop->addSqlAssociation('product', 'p'));
+5 -1
View File
@@ -448,6 +448,8 @@ class OrderCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'product` p
ON p.id_product = od.product_id
WHERE od.`id_order` = '.(int)($this->id));
}
@@ -606,7 +608,9 @@ class OrderCore extends ObjectModel
*/
protected function setProductCurrentStock(&$product)
{
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['id_warehouse'] > 0)
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& (int)$product['advanced_stock_management'] == 1
&& (int)$product['id_warehouse'] > 0)
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], (int)$product['id_warehouse'], true);
else
$product['current_stock'] = '--';
+40 -27
View File
@@ -65,7 +65,7 @@ class OrderHistoryCore extends ObjectModel
),
);
public function changeIdOrderState($new_order_state, $id_order, $id_warehouse = null)
public function changeIdOrderState($new_order_state, $id_order)
{
if ($new_order_state != NULL)
{
@@ -75,58 +75,71 @@ class OrderHistoryCore extends ObjectModel
/* Best sellers */
$newOS = new OrderState((int)($new_order_state), $order->id_lang);
$oldOrderStatus = OrderHistory::getLastOrderState((int)$id_order);
$cart = Cart::getCartByOrderId($id_order);
$isValidated = $this->isValidated();
if (Validate::isLoadedObject($cart))
foreach ($cart->getProducts() as $product)
if (Validate::isLoadedObject($order))
foreach ($order->getProductsDetail() as $product)
{
/* If becoming logable => adding sale */
if ($newOS->logable AND (!$oldOrderStatus OR !$oldOrderStatus->logable))
{
ProductSale::addProductSale($product['id_product'], $product['cart_quantity']);
ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
}
/* If becoming unlogable => removing sale */
else if (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
{
ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']);
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
// @since 1.5.0
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity'], $order->id_shop);
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
}
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == Configuration::get('PS_OS_ERROR'))
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity'], $order->id_shop);
if ((!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') || (int)$product['advanced_stock_management'] != 1)
&& !$isValidated
&& $newOS->logable
&& isset($oldOrderStatus)
&& $oldOrderStatus
&& $oldOrderStatus->id == Configuration::get('PS_OS_ERROR')
)
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
// If order is shipped for the first time and
// if we use advanced stock management system, decrement stock preperly.
// The product is removed from the physical stock. $id_warehouse is needed
// @TODO Checks $id_warehouse
else if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
else if ($newOS->shipped == 1
&& $oldOrderStatus->shipped == 0
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& (int)$product['advanced_stock_management'] == 1
)
{
$manager = StockManagerFactory::getManager();
$warehouse = new Warehouse($id_warehouse);
$warehouse = new Warehouse($product['id_warehouse']);
$manager->removeProduct(
$product['id_product'],
$product['id_product_attribute'],
$warehouse,
$product['cart_quantity'],
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
true,
(int)$id_order
$product['product_id'],
$product['product_attribute_id'],
$warehouse,
$product['product_quantity'],
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
true,
(int)$id_order
);
if (StockAvailable::dependsOnStock($product['id_product'], $order->id_shop))
StockAvailable::synchronize($product['id_product']);
if (StockAvailable::dependsOnStock($product['product_id'], $order->id_shop))
StockAvailable::synchronize($product['product_id']);
else
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity'], $order->id_shop);
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
}
else if ($newOS->shipped == 0 && $oldOrderStatus->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
else if ($newOS->shipped == 0
&& $oldOrderStatus->shipped == 1
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& (int)$product['advanced_stock_management'] == 1
)
{
$manager = StockManagerFactory::getManager();
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['id_product'], $product['id_product_attribute'], $product['cart_quantity']);
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['cart_quantity']);
foreach ($mvts as $mvt)
{
$manager->addProduct(
$product['id_product'],
$product['product_id'],
$product['id_product_attribute'],
new Warehouse($mvt['id_warehouse']),
$mvt['physical_quantity'],
@@ -136,10 +149,10 @@ class OrderHistoryCore extends ObjectModel
);
}
if (StockAvailable::dependsOnStock($product['id_product'], $order->id_shop))
StockAvailable::synchronize($product['id_product']);
if (StockAvailable::dependsOnStock($product['product_id'], $order->id_shop))
StockAvailable::synchronize($product['product_id']);
else
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity'], $order->id_shop);
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['physical_quantity'], $order->id_shop);
}
}
+8 -1
View File
@@ -101,6 +101,8 @@ class OrderInvoiceCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'product` p
ON p.id_product = od.product_id
WHERE od.`id_order` = '.(int)$this->id_order.'
AND od.`id_order_invoice` = '.(int)$this->id);
}
@@ -173,7 +175,12 @@ class OrderInvoiceCore extends ObjectModel
*/
protected function setProductCurrentStock(&$product)
{
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& (int)$product['advanced_stock_management'] == 1
&& (int)$product['id_warehouse'] > 0)
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
else
$product['current_stock'] = '--';
}
/**
+35 -29
View File
@@ -226,29 +226,24 @@ class AdminOrdersControllerCore extends AdminController
$history = new OrderHistory();
$history->id_order = (int)$id_order;
$history->id_employee = (int)$this->context->employee->id;
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !(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.');
}
$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));
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
@@ -439,7 +434,13 @@ class AdminOrdersControllerCore extends AdminController
// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $order_detail->id_warehouse != 0)
$product = new Product($order_detail->product_id);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& $product->advanced_stock_management
&& $order_detail->id_warehouse != 0
)
{
$mvts = StockMvt::getNegativeStockMvts(
$order_detail->id_order,
@@ -989,10 +990,15 @@ class AdminOrdersControllerCore extends AdminController
// gets warehouses to ship products, if and only if advanced stock management is activated
$warehouse_list = null;
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$order_details = $order->getOrderDetailList();
foreach ($order_details as $order_detail)
{
$order_details = $order->getOrderDetailList();
foreach ($order_details as $order_detail)
$product = new Product($order_detail['product_id']);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& $product->advanced_stock_management
)
{
$warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
foreach ($warehouses as $warehouse)
@@ -1098,7 +1104,7 @@ class AdminOrdersControllerCore extends AdminController
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1)
$product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
else
$product['warehouse_list'][$attribute['id_product_attribute']] = array();
@@ -1107,7 +1113,7 @@ class AdminOrdersControllerCore extends AdminController
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1)
$product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
else
$product['warehouse_list'][0] = array();
@@ -3747,10 +3747,10 @@ class AdminProductsControllerCore extends AdminController
return Tools::jsonEncode(array('error' => 'Undefined value'));
if ((int)Tools::getValue('value') != 1 && (int)Tools::getValue('value') != 0)
return Tools::jsonEncode(array('error' => 'Uncorrect value'));
$product->advanced_stock_management = (int)Tools::getValue('value');
$product->save();
if (StockAvailable::dependsOnStock($product->id) == 1 && (int)Tools::getValue('value') == 0)
StockAvailable::setProductDependsOnStock($product->id, 0);
$product->advanced_stock_management = (int)Tools::getValue('value');
$product->save();
if (StockAvailable::dependsOnStock($product->id) == 1 && (int)Tools::getValue('value') == 0)
StockAvailable::setProductDependsOnStock($product->id, 0);
break;
}