1

I want to add extra information in a transactional email when the order has a product which is backordered.

I know where and how to edit the email templates following this guide: http://www.flyingtophat.co.uk/blog/2011/08/31/magento-displaying-custom-attributes-in-emails.html

The problem is I don't know how to check if the order has backorder items. I found that the table sales_flat_order_item has a a field qty_backordered but it has no value and is NULL.

I can get the value of the field with the following code

echo $_item->getQtyBackordered();

My question is, why is the value of the field NULL? How can I make sure the field gets populated with the amount of items which are backordered? Or maybe there is another solution?

The only thing I actually need is to check if a placed order has at least 1 item backordered (so I can display extra backorder information).

1

qty_backordered set to NULL means your item was in stock in requested quantity by the moment of order was placed.

Other result means you have a problem with your installation. I'd suggest disabling 3rd party extensions to test if the problem is off-core.

  • Ok thanks, I will disable all extension and do a test order to check what's going on. – Akif Jul 14 '14 at 11:44
1

To add it to the Email:

app/design/frontend/default/<your_template>/template/email/order/items/order/default.phtml

and find this ~line 31:

<strong style="font-size:11px;"><?php echo $this->htmlEscape($_item->getName()) ?></strong>

Add the following line right after that:

    <?php if ($_item->getQtyBackordered()): ?>

        <p style="font-size: 10px;color: #CCC">
   * This product is not available  in the requested quantity. <?php echo  
   $_item->getQtyBackordered()*1 ?> of the items will be backordered.</p>

    <?php endif; ?>
0

Something like this ?

$items = $order->getItems();

$hasBackorderedItems = false;
foreach($items as $item){ // loop though all items in order checking the backorder qty
     if($item->getQtyBackordered() > 0){
        $hasBackorderedItems = true; // order has back order item stop loop
        break;
     }
}

This is not the most efficient way

  • Normally this would be sufficient. But the problem is the field QtyBackordered is allways NULL and has no value. – Akif Jul 8 '14 at 9:52
  • If the field is NULL then it means that there are no items on backorder. If the value is always null I'd check your stock settings to make sure the stock is being managed by Magento. – Danny Dev Nz Jul 8 '14 at 23:22
  • Yes, the value is always null. No matter if it has backorder items or not. The stock is managed. I think there is a bug somewhere why Magento doesn't write to the field. Do you have any clue in which file it writes to this field? – Akif Jul 10 '14 at 14:29
0

We just ran into the same problem as the topic starter. But we work with configurable products, and I just figured out the qty_backordered field is set to the child order_item (simples) only. The problem is that in the emails the items displayed are the parent order_items (configurables) which have indeed the qty_backordered set to NULL.

So we fixed this as follows in the email template:

<?php
    $itemQtyBackordered = intval($_item->getQtyBackordered());
    $childQtyBackordered = 0;

    if ($itemQtyBackordered === 0) // if no qty backordered found on item, check if the child item has it
    {
        $childOrderItems = Mage::getModel('sales/order_item')->getCollection()->addAttributeToFilter('parent_item_id', array('eq' => $_item->getItemId()));
        if ($childOrderItems->count() > 0)
        {
            $child = $childOrderItems->getFirstItem();
            $childQtyBackordered = intval($child->getQtyBackordered());
        }
    }
?>

<?php if ($itemQtyBackordered > 0 || $childQtyBackordered > 0): ?>
    <p>your message</p>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.