Magento:增加“数量"取消已发货订单时 [英] Magento: Increase "Qty" upon cancel a shipped order

查看:27
本文介绍了Magento:增加“数量"取消已发货订单时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆