【发布时间】:2013-09-25 16:47:48
【问题描述】:
我正在尝试在产品列表页面中显示捆绑产品和分组产品的选项。
我在互联网上找到了一个显示可配置产品的脚本,但我很难在捆绑和分组中找到一个。
基本上,我希望它显示的选项与我查看实际产品页面时完全相同。
谢谢
【问题讨论】:
-
您找到解决方案了吗?
标签: magento
我正在尝试在产品列表页面中显示捆绑产品和分组产品的选项。
我在互联网上找到了一个显示可配置产品的脚本,但我很难在捆绑和分组中找到一个。
基本上,我希望它显示的选项与我查看实际产品页面时完全相同。
谢谢
【问题讨论】:
标签: magento
试试下面的代码
1 ) 如果你已经覆盖了 list.php 文件,请将下面这三个函数放入,否则首先覆盖该文件 Mage/Catalog/Block?Product/List.php
protected function _getProduct($sku)
{
$_productId = Mage::getModel('catalog/product')->getIdBySku($sku);
if($_productId)
{
return Mage::getModel('catalog/product')->load($_productId);
}
return null;
}
public function getAssociatedProducts($sku)
{
$_product = $this->_getProduct($sku);
$simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
return $simpleProducts;
}
/**
* Set preconfigured values to grouped associated products
*
* @return Mage_Catalog_Block_Product_View_Type_Grouped
*/
public function setPreconfiguredValue($sku) {
$_product = $this->_getProduct($sku);
$configValues = $_product->getPreconfiguredValues()->getSuperGroup();
if (is_array($configValues)) {
$associatedProducts = $this->getAssociatedProducts($sku);
foreach ($associatedProducts as $item) {
if (isset($configValues[$item->getId()])) {
$item->setQty($configValues[$item->getId()]);
}
}
}
return $this;
}
2 ) 将以下代码放入您的 list.phtml 文件 design/frontend/default/default/template/catelog/product/list.phtml 此行之后
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->getTypeId() == 'grouped'){ ?>
<?php $this->setPreconfiguredValue($_product->getSku()); ?>
<?php $_associatedProducts = $this->getAssociatedProducts($_product->getSku()); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<table class="data-table grouped-items-table" id="super-product-table">
<col />
<col />
<col width="1" />
<thead>
<tr>
<th><?php echo $this->__('Name') ?></th>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<th class="a-right"><?php echo $this->__('Price') ?></th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php if ($_hasAssociatedProducts): ?>
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('super-product-table')</script>
<?php } ?>
3)
也许这对你有帮助! 注意:此代码仅适用于分组产品
【讨论】: