It was some logic issue in your code
issue1: 'Items' => $order->getAllVisibleItems()
not works it is big object.it print and var_dump is stuck works.
change the function $data['Items']=$this->createOrderItems($order->getIncrementId());
and modified code
public function exportOrder($order)
{
Mage::log('Shopaton Order exportOrder', null, 'Shopatron.log');
$dirPath = Mage::getBaseDir('var') . DS . 'export';
if (!is_dir($dirPath))
{
mkdir($dirPath, 0777, true);
}
$customerIP = Mage::helper('core/http')->getRemoteAddr(true);
$data=array();
//Getting the Proper 2 Character State
$regionModel = Mage::getSingleton('directory/region');
$regionModel->load($order->getShippingAddress()->getRegionId());
$sstate_code = $regionModel->getCode();
$regionModel->load($order->getBillingAddress()->getRegionId());
$bstate_code = $regionModel->getCode();
Mage::log($bstate_code, null, 'Shopatron.log');
Mage::log($sstate_code, null, 'Shopatron.log');
$data = array('OrderID'=>$order->getIncrementId(),
'Email'=>$order->getData('customer_email'),
'CustomerIP'=>$customerIP,
'ShipMethod' =>$order->getData('shipping_method'),
'ShippingPhone' =>$order->getShippingAddress()->getData('telephone'),
'ShippingFirstName'=>$order->getShippingAddress()->getFirstname(),
'ShippingLastName' => $order->getShippingAddress()->getLastname(),
'ShippingStreet' => $order->getShippingAddress()->getStreet(),
'ShippingCity' => $order->getShippingAddress()->getCity(),
'ShippingState' => $sstate_code,
'ShippingCountry' => $order->getShippingAddress()->getCountryId(),
'ShippingZip' => substr($order->getShippingAddress()->getPostcode(),0,5),
'BillingPhone' => $order->getBillingAddress()->getData('telephone'),
'BillingFirstName' => $order->getBillingAddress()->getFirstname(),
'BillingLastName' => $order->getBillingAddress()->getLastname(),
'BillingStreet' => $order->getBillingAddress()->getStreet(),
'BillingCity' => $order->getBillingAddress()->getcity(),
'BillingState' => $bstate_code,
'BillingCountry' => $order->getBillingAddress()->getCountryId(),
'BillingZip' => substr($order->getBillingAddress()->getPostcode(),0,5),
//Why can't I call getAllVisibleItems?
//'Items' => $order->getAllVisibleItems()
);
try{
$data['Items']=$this->createOrderItems($order->getIncrementId());
} catch(Exception $e){
Mage::log($e->getMessage(), null, 'system.log');
//Nothing shows up in the log to help troubleshoot
}
//$xstrout = toXmlRpc($data);
/*file_put_contents(
$dirPath. DS .$data['OrderID'].'.xml22',
print "<PRE>" . htmlentities ( $xstrout ) . "</PRE>",
FILE_APPEND
);*/
//sendMsg($xstrout);
return true;
}
Issue:
lot of issue:
public function createOrderItems($orderId)
{
Mage::log('Shopatron Order createOrderItems', null, 'Shopatron.log');
$order=Mage::getModel('sales/order')->loadByIncrementId($orderId);
$items=$order->getAllVisibleItems();
$i=0;
$IO=array();
$itemcount=count($items);
foreach ($items as $item)
{
$IO[$i]['name']=$item->getName();
$IO[$i]['price']=$item->getPrice();
$IO[$i]['sku']=$item->getSku();
$IO[$i]['id']=$item->getProductId();
// $IO[$i]['upc']=getUpcFromSku($item->getSku());
$IO[$i]['qty']=$item->getQtyOrdered(); //$item->getQtyToInvoice();
//$IO[$i]['options']=createOptionsArray($item->getProductOptions(), $itemId);
if($itemcount>1)
{
$IO[$i]['shipping']=$order->getData('shipping_amount')/$itemcount;
$IO[$i]['tax'] = $order->getData('tax_amount')/$itemcount;
}
elseif($itemcount == 1)
{
$IO[$i]['shipping']=$order->getData('shipping_amount');
$IO[$i]['tax'] = $order->getData('tax_amount');
}
$i++;
}
return $IO;
}
}
With sales_order_shipment_save_commit_after
you will run into the same issue. The other mentioned events do not tell if the shipment was/will be created successfully.
Probably the sales_order_shipment_save_after
event is just fine, but you miss a point: The save()
method is not only called on create operations but also on update. In your case, I guess, the latter fires on invoice creation.
Stick with the event and test in your observer method whether the shipment was just created or not:
// Observer::shipmentSaveAfter()
if ($observer->getShipment()->getOrigData('entity_id')) {
// shipment updated, do nothing
return;
}
// shipment new, send text message
This is not 100% reliable though as the original data is populated on load and as such not necessarily during multiple calls to the save()
method.
Alternatively you could register a flag on sales_order_shipment_save_before
:
// Observer::shipmentSaveBefore()
if ($observer->getShipment()->isObjectNew()) {
Mage::register('send_shipment_message', true);
}
// Observer::shipmentSaveAfter()
if (!Mage::registry('send_shipment_message')) {
// shipment updated, do nothing
return;
}
Mage::unregister('send_shipment_message');
// shipment new, send text message
Best Answer
There are lots of example of links for events lists but mostly I follow below link, it contain almost all events, and this blog has
sales_order_shipment_save_after
as well, so I hope it will help you.https://www.rakeshjesadiya.com/list-of-all-events-in-magento-2/
Thanks :)