Magento:增加“数量"取消发货单后 [英] Magento: Increase "Qty" upon cancel a shipped order
问题描述
我正在使用Magento 1.7.0.2.我使用货到付款"作为付款方式.我会准确告诉您在任何订单上应遵循的步骤.下订单时(数量减少1个项目),如果客户支付了订单的总价,我将为其创建货件.我为该订单创建了发票.
I'm on Magento 1.7.0.2. I'm using "Cash On Delivery" as my payment method.I'll tell you exactly the steps That i follow on any order. When an order is placed(Qty decreased 1 item), I create a shipment for it and if customer paid the order grand total price. I create an invoice for that order.
我的问题,如果下订单(数量减少1件),我将为此订单创建货件.如果客户拒绝付款,我将打开此订单并取消"该订单,在这种情况下,数量"不会增加,那么如何使它增加呢?
My problem, If an order is placed(Qty decreased 1 item), I create a shipment for this order. If the customer refused to pay, I open this order and "Cancel" it and on this case the "Qty" doesn't increase so How can I make it increase?
推荐答案
感谢R.S,他为我提供了更多帮助&更多.
Thanks to R.S as he helped me more & more.
我按照RS答复 https://stackoverflow.com/a/13330543/1794834 上的所有说明进行操作,并且我只更改了观察者代码.这是与我一起使用Magento 1.7.0.2.的观察者代码.
I followed all instructions on R.S's reply https://stackoverflow.com/a/13330543/1794834 and I've only changed the observer code. Here is the observer code that worked with me on Magento 1.7.0.2.
$curr_date = date('Y-m-d H:i:s');
$order = $observer->getEvent()->getOrder();
foreach ($order->getItemsCollection() as $item)
{
$productId = $item->getProductId();
$qty = (int)$item->getQtyOrdered();
$product = Mage::getModel('catalog/product')->load($productId);
$stock_obj = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
$stockData = $stock_obj->getData();
$product_qty_before = (int)$stock_obj->getQty();
$product_qty_after = (int)($product_qty_before + $qty);
$stockData['qty'] = $product_qty_after;
/*
* it may be case that admin has enabled product add in stock, after product sold,
* he set is_in_stock = 0 and if order cancelled then we need to update only qty not is_in_stock status.
* make a note of it
*/
if($product_qty_after != 0) {
$stockData['is_in_stock'] = 1;
}else{
$stockData['is_in_stock'] = 0;
}
$productInfoData = $product->getData();
$productInfoData['updated_at'] = $curr_date;
$product->setData($productInfoData);
$product->setStockData($stockData);
$product->save();
}
这篇关于Magento:增加“数量"取消发货单后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!