【问题标题】:Show inventory of simple product in Magento在 Magento 中显示简单产品的库存
【发布时间】:2014-07-23 11:37:07
【问题描述】:

我想在结帐页面上显示库存数量。但当库存超过 15 件时,则显示 15+。

我有可配置的产品修复,但简单的不起作用。

<?php } elseif($custom->getTypeId() == 'configurable' ) {  ?>

        <?php

        $children = $custom->getTypeInstance()->getUsedProducts();
        $totaal = count($children);
        $i = 0;
        $childStockQty = 0;
            if ($totaal > 0) {
                foreach ($children as $child) {
                    $i++;
                    $childStock = $child->getStockItem();
                    $childStockQty = $childStock->getQty();
                    $childStockPid = $childStock->getProductId();
                    $childStockQty_tot = $childStockQty_tot + $childStockQty; 

                    echo Mage::getModel('catalog/product')->load($child->getEntityId())->getAttributeText('kleur');

                    if($childStockQty > 15)
                    {
                        echo ': 15+';
                    }
                    else
                    {
                        echo ': ' . round($childStockQty, 0);
                    }
                    if($i != $totaal)
                    {
                        echo '</br>';
                    }
                }
                //echo $childStockQty_tot;
            }

        ?>

【问题讨论】:

  • 你的问题是什么。请详细说明

标签: php magento inventory


【解决方案1】:

我可以看到你的代码被包裹在

elseif($custom->getTypeId() == 'configurable' )

因此它仅有效地显示可配置产品,这很有意义,因为您正在调用 getUsedProducts() ,这在简单产品中不可用。 我想你需要这样的东西:

if ($custom->getTypeId() === 'simple') {
    $quantity = $custom->getStockItem()->getQty();
    if ($quantity >= 15) {
    } else ...
}

如果这不是您要找的,请告诉我

【讨论】:

    【解决方案2】:

    当我编辑文件 /template/checkout/cart/item/default.phtml 时,代码 getTypeId() == 'simple' ) {//echo $_item->getProductId();$quantity = $custom- >getStockItem()->getQty();if ($quantity >= 15){echo ': 15+';} 否则{回声':'。 round($quantity, 0);} if($i != $totaal){echo '';}?>

    比只在错误的地方看到你 15+。 https://www.weddingdeco.nl/checkout/cart/#

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多