Magento 1.9 - Set item backorder message

I'm setting an item backorder message based on various criteria; stock and what the expected ship date is.

However, what's happening now, is sometimes a backorder date in the past is shown. Today, I saw an email go out with a backorder date of a year in the past.

I'd like to, if an expected ship date is in the past, then just not show a date or go into the else and say no expected ship date. Not sure why that isn't happening currently.

Below is my current code.

$itembackordermessage = '';

$inventory =  Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);

if($inventory->getQty() <= 0 && $inventory->getBackorders() >= 1) {
    $backorder = true;
    $itembackordermessage = 'This item is on backorder';
    if ($product->getExpectedShipDate() && (new DateTime($product->getExpectedShipDate())) > (new DateTime())) {
        $shipdate = $product->getExpectedShipDate();
        $itembackordermessage .= ' and will ship on <strong>' . $shipdate . '</strong>';
    } else {
        $itembackordermessage .= ' (no expected ship date available)';
    }
}
phpmagentologicmagento-1.9

Answers

comments powered by Disqus