-1

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

4

1 回答 1

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; }
于 2013-01-07T23:23:53.697 回答