如何在magento中以编程方式进行自动运输? [英] How do i make auto shipping programatically in magento?
问题描述
我尝试了以下观察者代码.
I tried with following observer code.
...
public function automaticallyInvoiceShipCompleteOrder($observer)
{
$order = $observer->getEvent()->getOrder();
$orders = Mage::getModel('sales/order_invoice')->getCollection()
->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
$orders->getSelect()->limit(1);
if ((int)$orders->count() !== 0) {
return $this;
}
try {
if($order->canShip())
{
$itemQty = $order->getItemsCollection()->count();
$items[] = $itemQty;
// This first definition and 2nd look overlapping, our one is obsolete?
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
$ship = new Mage_Sales_Model_Order_Shipment_Api();
$shipmentId = $ship->create($order->getId(), $items, 'Shipment created through ShipMailInvoice', true, true);
//getting Error here
}
}
} catch (Exception $e) {
$order->addStatusHistoryComment(' Exception occurred during automaticallyInvoiceShipCompleteOrder action. Exception message: '.$e->getMessage(), false);
$order->save();
}
return $this;
}
.....
下订单时,我可以使用观察器捕获订单成功事件.最终在ajax调用中获得"Fatal error: Maximum function nesting level of '100' reached, aborting!
".
When i place the order, i can capture the order success event using observer. Finally getting "Fatal error: Maximum function nesting level of '100' reached, aborting!
" in ajax call itself.
我找不到解决方案.请为此提供一些建议
I could not found the solution. Kindly give some advice on this
推荐答案
每次保存订单时,都会调用此观察者方法,由于try块中的某些错误,该方法再次保存了您的订单.这就是我认为它会无休止地执行的原因,并且在第100次之后将引发致命错误.
Each time your order is saved, this observer method is called, which again saves your order due to some error in try block. That's the reason I think it will endlessly execute and after 100th time Fatal error will be thrown.
在try块的$ship->create()
中,您需要传递Order Increment ID
而不是Order Entity ID
.
In your try block's $ship->create()
, you need to pass Order Increment ID
and not Order Entity ID
.
这篇关于如何在magento中以编程方式进行自动运输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!