doufei5537 2014-02-14 10:19
浏览 33
已采纳

Php / Magento根据库存数量显示图像

Nobody that can help me? (update 17-02)

Basicly what I need it the following.

  • Get the qty of stock of a product
  • Show qty number X
  • When negative number show 0
  • When it's > 0 show image X
  • When it's < 0 show image Y

Old info

In magento I am showing the stock qty with the actual numbers. When the number is lower then 0 he always shows 0. What I now want to do is add an image to both conditions.

For example when the qty is > 0 show a green image and when the qty = 0 then show a red image. Anybody knows how to do this?

 <div class="qty-amount2">
        <?php //echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
        <?php  $_op_voorraad = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
            if($_op_voorraad < 0){
                $_op_voorraad = 0;
            }
            echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>

  • 写回答

3条回答 默认 最新

  • dousui8263 2014-02-25 19:45
    关注

    Ok got this fixed by hiring a developer but will share it

     ?>
    <?php /* @var $this Mage_Catalog_Block_Product_View_Abstract */?>
    <?php $_product = $this->getProduct() ?>
    <?php if($_product->isSaleable()): ?>
    <?php  $_op_voorraad = (int) Mage::getModel('cataloginventory/stock_item')-       >loadByProduct($_product)->getQty();?>
    <?php if($_op_voorraad > 0): ?>
        <div class="qty-amount2"><img style="float: left;"   src="image_path" alt="">
            <?php echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>
        </div>
    <?php else: ?>
        <?php $_op_voorraad = 0;?>
        <div class=" qty-amount2 geen"><img src="image_path" alt="">
            <?php echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>
        </div>
    <?php endif;?>
    <?php else: ?>
    <div class="geen"><img src="image_path"   alt="">
    <p><?php echo $this->__('Availability: Out of stock.') ?></p></div>
    <?php endif; ?><br>
    
    <?php echo $this->getPriceHtml($_product) ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误