我创建了一个与3个产品相关联的组,现在我需要在分组产品页面中显示每个关联产品的单个图像,并让客户从组中选择任何相关产品并添加它他的车。
答案 0 :(得分:0)
请按以下步骤操作:
打开app / design / frontend / your_theme / template / catalog / product / view / type / grouped.phtml
如果不存在,请从基本文件夹中复制此文件,并将其放在主题中的确切文件夹路径中。
转到第50行并添加以下内容
<th></th>
前
<th><?php echo $this->__('Product Name') ?></th>
然后转到第64行并添加
<td><a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(50) ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a></td>
前
<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
完成后,这会在您的产品详细信息页面中添加一个新的td,并添加相关产品的图片。
希望这会对你有所帮助。
请更改你的app / design / frontend / your_theme / template / catalog / product / view / type / grouped.phtml
以下内容:
<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php if ($_product->isAvailable() && $_hasAssociatedProducts): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
<table class="data-table grouped-items-table" id="super-product-table">
<col />
<col />
<col width="1" />
<thead>
<tr>
<th><?php echo $this->__('Product Name') ?></th>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<th class="a-right"><?php echo $this->__('Price') ?></th>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<th class="a-center"><?php echo $this->__('Qty') ?></th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php if ($_hasAssociatedProducts): ?>
<?php //echo "<pre>"; print_r($_hasAssociatedProducts); exit; ?>
<?php $_collectionSize = count($_associatedProducts) ?>
<?php $_columnCount = 3; ?>
<?php $i=0; foreach ($_associatedProducts as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php else: ?>
<div><?php echo $this->__('No options of this product are available.') ?>
<?php endif; ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
这将在类别列表页面上逐一向您显示产品块。显然您需要在外部div中调用grouped.phtml,以便这些块位于主要产品之下...目前它们正在进入右侧区域与主要产品图像相邻。
您还需要根据需要应用css。
谢谢希望这一点清除。
答案 1 :(得分:0)
使用以下代码替换app/design/frontend/base/default/template/catalog/product/view/type/grouped.phtml
。
<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php if ($this->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable() && $_hasAssociatedProducts): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
<table class="data-table grouped-items-table" id="super-product-table">
<col />
<col />
<col width="1" />
<thead>
<tr>
<th><?php echo $this->__('Product Image'); ?></th>
<th><?php echo $this->__('Product Name') ?></th>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<th class="a-right"><?php echo $this->__('Price') ?></th>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<th class="a-center"><?php echo $this->__('Qty') ?></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><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(35); ?>" width="35" height="35" alt="<?php echo $this->stripTags($this->getImageLabel($_item, 'small_image'), null, true) ?>" /></td>
<td><?php echo $this->escapeHtml($_item->getName()) ?></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php echo $this->getTierPriceHtml($_item) ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<td class="a-center">
<?php if ($_item->isSaleable()) : ?>
<input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?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>