Magento 如何在产品页面和购物车页面的下拉列表中显示数量

Magento 如何在产品页面和购物车页面的下拉列表中显示数量,magento,magento-1.9,magento-1.9.2.1,Magento,Magento 1.9,Magento 1.9.2.1,我正在使用Magento ver。1.9.2.1 我只想在产品视图页面和购物车页面的下拉列表中显示简单和可配置产品的数量 我在app/design/frontend/rwd/default/template/catalog/product/view/addtocart.phtml页面中替换代码 替换以下代码 <input class="qty-decrease" value="-" type="button" onclick="var qty_el = document.getElemen

我正在使用Magento ver。1.9.2.1

我只想在产品视图页面和购物车页面的下拉列表中显示简单和可配置产品的数量

我在
app/design/frontend/rwd/default/template/catalog/product/view/addtocart.phtml
页面中替换代码

替换以下代码

<input class="qty-decrease" value="-" type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty ) && qty > 1 ) qty_el.value--;return false;">
            <input id="qty" class="input-text qty" type="text" maxlength="12" title="<?php echo $this->__('Qty') ?>" size="4" value="1" name="qty" style="padding-top: 0;">
<input class="qty-increase"  value="+" type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;">


在可配置产品中,数量不是他们自己的,在可配置产品中,数量来自关联产品,因此您必须为可配置产品设置条件。如果找到可配置产品,则您必须从其关联产品而不是可配置产品中获取数量。

我必须开发该代码,因此请自行尝试,如果仍然面临问题,请告诉我。确保一个可配置产品具有多个关联产品,因此您必须应用您的逻辑,即您要显示的产品数量,或者您可以对关联的产品数量求和。我在这方面做了很多尝试。所以如果你能发送你的代码就更好了。感谢您,我希望您非常了解如何使用此产品进行循环,并在下拉列表中获得部分所有项目数量和显示
$ids=Mage::getResourceSingleton('catalog/product\u type\u configurable')->getChildrenIds($configurable\u product\u id)$_subproducts=Mage::getModel('catalog/product')->getCollection()->addIdFilter($id);//获取每个产品的数量$product->getStockItem()->getQty()
<select class="input-text qty" name="qty" id="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?>
</select>