Magento 1.9 check if order got shipment
-
14-04-2021 - |
Pregunta
I want to load a specific block in the transactional email only when the order is shipped. I want to load the block, buy using the following code:
{{block type='core/template' area='frontend' template='email/order/invoiceemailhead.phtml' order=$order}}
I already use that template to check the paymentmethod, but using;
<?php if($this->getOrder()->getPayment()->getMethodInstance()->getCode()=='cashondelivery'):?>
How can I also check if a order is shipped? What code do I need for this?
Solución
Try using below code to check if the order has shipped.
<?php $hasShipment = $this->getOrder()->getShipmentsCollection()->count();
if($hasShipment){
.... // Do your stuff
}
?>
Otros consejos
If you want to check if the order is completely shipped, the following function could help:
/**
* @param Mage_Sales_Model_Order $order
* @return boolean
*/
protected function isOrderCompletelyShipped(Mage_Sales_Model_Order $order)
{
foreach ($order->getAllItems() as $item) {
if ($item->getParentItemId()) {
continue;
}
if ($item->getQtyShipped() !== $item->getQtyOrdered()) {
return false;
}
}
return true;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange