1

I'm trying to display a message for virtual products in the cart that they will be processed in 1 to 3 days. I got this to display but it is also displaying the standard message treating it as a backorder.

Here is a portion of my default.phtml

<?php $_product = $this->getProduct() ?>
    <?php if ($_product->getTypeId() == "virtual"): ?>
    <p class="item-msg"><span class="fa fa-check"></span><?php echo $this->__('Item will be processed in 1 to 3 business days') ?></p>
    <?php endif; ?>
    <?php if ($messages = $this->getMessages()): ?>
    <?php foreach ($messages as $message): ?>
        <p class="item-msg <?php echo $message['type'] ?>">* <?php echo $this->escapeHtml($message['text']) ?></p>
    <?php endforeach; ?>
    <?php endif; ?>

How can I modify the above code to only show virtual products one message and other products the standard backorder message?

1 Answer 1

1

I would probably leverage the existing messaging system here, shown in your snippet. You could do that using an observer. Assuming you have an extension to add this to already, it would be something like this:

app/code/local/My/Extension/etc/config.xml

Under the config/frontend/events node:

<sales_quote_item_set_product>
    <observers>
        <addVirtualProductNotice>
            <type>singleton</type>
            <class>My_Extension_Model_Observer</class>
            <method>addVirtualProductNotice</method>
        </addVirtualProductNotice>
    </observers>
</sales_quote_item_set_product>

app/code/local/My/Extension/Model/Observer.php

class My_Extension_Model_Observer
{
    public function addVirtualProductNotice(Varien_Event_Observer $observer)
    {
        /* @var Mage_Catalog_Model_Product $product */
        $product = $observer->getProduct();
        if ($product->getIsVirtual()) {
            /* @var Mage_Sales_Model_Quote_Item $item */
            $item = $observer->getQuoteItem();
            $message = Mage::getSingleton('core/message')->notice(Mage::helper('checkout')->__('Item will be processed in 1 to 3 business days.'));
            Mage::getSingleton('checkout/session')->addQuoteItemMessage($item->getId(), $message);
        }
        return $this;
    }
}

To prevent virtual products from displaying the backorder message, I suggest setting the Backorders value to “Allow Qty Below 0” rather than “Allow Qty Below 0 and Notify Customer” under the Inventory tab of those products. It’s not clear whether you need to track the stock of these products at all, so if that is the case you could also just set Manage Stock to “No” on those products instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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