我正在寻找一个简单的库存指标。
最佳答案
将此添加到您想要库存指示器的yourtheme / template / catalog / product / view.phtml中。
<?php
$qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
switch ($qty) {
case $qty > 5 :
$stockcss .= 'stockindicator-green';
$stocktext = "In stock";
break;
case $qty <= 5:
$stockcss .= 'stockindicator-green';
$stocktext = "Low stock";
break;
case $qty <= 0:
$stockcss .= 'stockindicator-green';
$stocktext = "Out of stock";
break;
}
?>
Stock: <div class="stockindicator <?php echo $stockcss ?>" title="<?php echo $stocktext ?>"></div>
将以下代码添加到/skin/frontend/yourTheme/default/css/styles.css
.stockindicator {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
}
.stockindicator-green { background-color: #46A40E; }
.stockindicator-yellow { background-color: #F9E700; }
.stockindicator-red { background-color: #E42620; }
关于css - Magento:带有CSS的简单股票指标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14205850/