2013-03-08 31 views
0

我想顯示magento中售罄的產品百分比。如何在magento中顯示售罄百分比

對於我有10個手錶品牌的,在兩個被銷售一空例如,

在我的產品欲售完百分比如20%,並且其指示售完酒吧percetage 。

請幫助我。

問候 MD.Samiuddin

回答

0

嗨你的意思是這樣?

PHP:

<?php 
    $initialAmount = 10; 
    $itemsLeft = Mage::getModel('cataloginventory/stock_item') 
        ->loadByProduct($_product)->getQty(); 
    $sold = $initialAmount - $itemsLeft; 
    $perc = $sold/$initialAmount*100; 
?> 

CSS

<style> 
    .bar { 
     height: 20px; 
     width:100%; 
     border: 1px solid #000000; 
     background-color: green; 
    } 

    .fill { 
     height: 20px; 
     width: <?php echo $perc; ?>%; 
     background-color: #FF0000; 
     font-size: 12px; 
     text-align: right; 
     line-height: 20px; 
     vertical-align: middle; 
    } 
</style> 

HTML

<div class='bar'> 
    <div class="fill"> <?php echo $perc; ?>%</div> 
</div> 

檢驗 Example

+0

非常感謝我一直在尋找這一點。但股票價值應該是動態的。 – samiuddin 2013-03-09 05:15:19

+0

也許這將工作:http://stackoverflow.com/questions/7808213/magento-how-to-display-how-many-times-a-product-has-been-sold – khoekman 2013-03-09 18:47:58