Magento:简单的股票指标与css

时间:2013-01-07 23:23:54

标签: css magento retina-display magento-1.6 hdpi

我正在寻找一个简单的股票指标。

1 个答案:

答案 0 :(得分:3)

将此添加到您想要股票指示器的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; }