Show backorder status on magento frontend

耗尽温柔 提交于 2019-12-07 01:57:00

问题


I need to show on the product page (frontend) that the current item is for backorder ONLY and is not in stock.

I have at the moment those in stock showing qty of what is available and those products on backorder doesn't show anything.

Does anyone know a code I can put in the view.phtml file that will ONLY show a message on those products set as backorder?

Thanks!

Simon.


回答1:


To do this make sure you have enabled backorders from inventory tab.

If you are on product page then first of all retrieve product qty.

<?php
$inventory = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

if( (int)$inventory->getQty() == 0 && $inventory->getBackorders() )
{
  // No Backorders => getBackorders() = 0
  // Allow Qty Below 0 => getBackorders() = 1
  // Allow Qty Below 0 and Notify Customer => getBackorders() = 2
  echo "display your backordedr message";
}
?>

You can also put this code in app\design\frontend\base\default\template\catalog\product\view\type\default.phtml file where availability message of product come from.




回答2:


Here is the code that you need to add in view.phtml. This will show the backorder message:

$inventory =  Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$inv_qty = (int)$inventory->getQty();
if($inventory->getBackorders() >= 0 && $inv_qty == 0)
{ 
    echo "Your backorder message goes here";
}


来源:https://stackoverflow.com/questions/16459229/show-backorder-status-on-magento-frontend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!