【问题标题】:Show qty for tier_price in product list在产品列表中显示 tier_price 的数量
【发布时间】:2015-07-20 20:42:45
【问题描述】:

我需要在产品列表中显示接近正常价格的 tier_price 的数量字段(最低 tier_price 的最高数量)。现在,产品列表中的 $_product->getTierPrice() 给了我 array(1),其中 'tier_price'=>xxx 和 'qty'=>1(其中 xxx 是我的等级价格中最低的)。是否可以在产品列表中获取 tier_price 的数量?

PS。在产品视图中,我可以使用 $_product->getTierPrice() 查看一系列等级价格。

Magento CE 1.7.0.2

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以将此代码放在 list.phtml 或 view.phtml 中以显示每个数量的等级价格。

    $attribute = $_product->getResource()->getAttribute('tier_price');
    $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
    $symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
    if ($attribute) {
        $attribute->getBackend()->afterLoad($_product);
        $tierPrices = $_product->getTierPrice();
    
        foreach($tierPrices as $tierPrice)
        {
        ?>
        <span class="priceqty"><?php echo '+'.round($tierPrice["price_qty"], 0);?></span><br>
        <span class="pricetitle"><?php echo $symbol.number_format($tierPrice["price"], 2, '.', '');?></span>
    <?php  
        } 
    } 
    ?>
    

    【讨论】:

      【解决方案2】:

      如果您正在寻找 Magento 方式:

       $attribute = $_product->getResource()->getAttribute('tier_price');
      
          if ($attribute) {
             $attribute->getBackend()->afterLoad($_product);
             $tierPrices = $_product->getTierPrice();
          }
      

      来自/app/code/core/Mage/Catalog/Model/Product/Type/Price.phpgetTierPrice()

      我已经在类别页面上测试了 Magento 1.4.0.2(它应该也可以在其他版本上工作)并且它可以工作

      如果您想使用 SQL 执行此操作,请查看此处: Magento: Display tier prices at category listing page

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多