Magento 成功页面上的小产品问题
Small product issue on success page Magento
我尝试在 Magento 1.9 的结帐成功页面上获取产品详细信息,但我不知道为什么我两次获得相同的产品。这是我在 app/design/frontend/base/default/template/checkout/success.phtml 文件
中添加的内容
<tbody>
<?php
foreach ($items as $item):
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$productType = $_product->getTypeId();
$entityId = $_product->getEntityId();
$options = $item->getProductOptions();
if ($productType == "bundle") {
$bundled_product = new Mage_Catalog_Model_Product();
$bundled_product->load($entityId);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection( $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product );
$bundled_items = array();
foreach ($selectionCollection as $option) {
$bundled_items[] = $option->product_id;
}?>
<tr>
<td rowspan="1">
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?>
</span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
} else if (in_array($entityId, $bundled_items)) {
} else {
?>
<tr>
<td>
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php
echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {
?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?></span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
}
?>
<?php endforeach ?>
</tbody>
这是预期的行为。复合产品的数据库中插入了几行:捆绑包、可配置项。
在您的情况下,第一个是捆绑产品本身,第二个是选定的简单产品。
您可以在模板中将 } else {
替换为 } elseif (!$item->getParentId()) {
以跳过子简单产品。
我尝试在 Magento 1.9 的结帐成功页面上获取产品详细信息,但我不知道为什么我两次获得相同的产品。这是我在 app/design/frontend/base/default/template/checkout/success.phtml 文件
中添加的内容 <tbody>
<?php
foreach ($items as $item):
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$productType = $_product->getTypeId();
$entityId = $_product->getEntityId();
$options = $item->getProductOptions();
if ($productType == "bundle") {
$bundled_product = new Mage_Catalog_Model_Product();
$bundled_product->load($entityId);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection( $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product );
$bundled_items = array();
foreach ($selectionCollection as $option) {
$bundled_items[] = $option->product_id;
}?>
<tr>
<td rowspan="1">
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?>
</span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
} else if (in_array($entityId, $bundled_items)) {
} else {
?>
<tr>
<td>
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php
echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {
?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?></span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
}
?>
<?php endforeach ?>
</tbody>
这是预期的行为。复合产品的数据库中插入了几行:捆绑包、可配置项。
在您的情况下,第一个是捆绑产品本身,第二个是选定的简单产品。
您可以在模板中将 } else {
替换为 } elseif (!$item->getParentId()) {
以跳过子简单产品。