Hi All,
I am trying to display the Add to Cart button even for products which are out of stock. I have enabled back orders and also implemented the following code on view.phtml and list.phtml
<?php if ($_product->isAvailable()): ?>
<?php //Added this segment to get quantity to determine whether we need to display a back order message is there is no quantity ?>
<?php $stocklevel = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() ?>
<?php if($stocklevel >= 1): ?>
<span style="color: #198504; font-size: 12px; "><?php echo $this->__('IN STOCK ') ?></span><?php echo $this->__('(Quantity Available:') ?><span style="color: #198504; font-size: 12px; "><?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?></span><?php echo $this->__(')') ?></p><p><?php echo $this->__('STOCK DUE: ') ?><?php echo $_product->getData('stock_due_date') ?><?php echo $this->__(' (Qty: ') ?><?php echo $_product->getData('stock_due_qty') ?><?php echo $this->__(')') ?></p>
<?php else: ?>
<span style="color: #ff0000; font-size: 14px; "><?php echo $this->__('NO STOCK (Quantity Available: ') ?></span><?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?><?php echo $this->__(')') ?></span><br>
<span style="color: #198504; font-size: 14px; "><?php echo $this->__('STOCK DUE: ') ?></span><?php echo $_product->getData('stock_due_date') ?><?php echo $this->__(' (Quantity Available: ') ?><?php echo $_product->getData('stock_due_qty') ?><?php echo $this->__(')') ?></span>
<?php endif; ?>
Has anybody managed to get the Add to Cart button displaying for out of stock items on their site and if so, be willing to suggest on how this can be acheived?
Thanks in advance for any advice.
Solved! Go to Solution.
This link should see you right. It is probably due to the fact you need to set the product to "In Stock" as well as enabling back orders. You should not need to modify any templates.
Regards,
Andy
This link should see you right. It is probably due to the fact you need to set the product to "In Stock" as well as enabling back orders. You should not need to modify any templates.
Regards,
Andy
Hi @ethantram
Go to Admin panel which you want to 0 qty show add to cart button Catalog >> Manage Products >> select your product >> go to left side Product Information "Inventory" section and untick "Backorders" option select "Allow Qty Below 0" after save product and clean all Cache check front-end.
Hope this helps you.
Hi,
You can display addtocart button on frontend for out of stock products by using magento event :
call below lines in <events> in your module's config.xml :
<catalog_product_is_salable_after>
<observers>
<Company_Module_Model_Observer>
<class>Company_Module_Model_Observer</class>
<method>modifySaleable</method>
</Company_Module_Model_Observer>
</observers>
</catalog_product_is_salable_after>
Now, in your module's model , create a file observer.php and write the following code in that file :
<?php
class Company_Module_Model_Observer {
public function modifySaleable($observer){
$saleable = $observer->getSalable();
$saleable->setIsSalable(true);
}
}
?>
and your problem will be solved .
Thanks
If you're setting the product to 'In Stock' then it's no longer an 'out of stock' product is it?
The question was: "How do you enable the 'add the cart' button for 'OUT OF STOCK' items?