Question

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?

Was it helpful?

Solution

Try using below code to check if the order has shipped.

<?php $hasShipment = $this->getOrder()->getShipmentsCollection()->count();
if($hasShipment){
    .... // Do your stuff
}
?>

OTHER TIPS

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top