我的产品以网格格式显示,并直接从此页面购买。它们是带有自定义选项的简单产品。每个选项都是一种颜色。有没有办法为每个产品/颜色组合分配图像,并在选择相关颜色的下拉列表时显示该图像?
` <?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="productthumb" item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(600); ?>" rel="lightbox" title="<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>" />
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(220); ?>" width="220" height="160" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<form action="<?php echo Mage::getBaseUrl(); ?>checkout/cart/add/" method="post" style="display:block; clear:both;">
`
答案 0 :(得分:2)
有几个商业模块在产品页面上承诺此功能,但不在类别页面上。因此,没有现成的简易选择。
出于SKU计数的原因,从类别页面订购和数据库可维护性,可配置的产品可能不是这里的方式。
一个简单的解决方法是创建media / swatch / red.jpg,media / swatch / orange.jpg,media / swatch / redgreenstripes.jpg等。然后在前端代码中,拉出与所需选项匹配的样本。对于每种颜色选项,您需要使用strtolower代码,将其与get-base-dir-media-swatches连接并将其弹出到图像标记中。
Blutak和字符串解决方案?是的,但你不需要整天都在写一个模块。
答案 1 :(得分:0)
使用可配置产品。然后,您可以为每个组合分配图像。
要做到这一点:
然后,在您的网格中,显示可配置产品,但在选项下拉列表中显示相关简单产品的颜色属性,在选择时切换到正确的图像。
如果您不熟悉可配置产品,请参阅this page。它们比单纯的产品复杂一点,但值得学习。
答案 2 :(得分:0)
要将图像分配给每个产品/颜色组合,并在商店中显示该图像,请使用 Encoresky / CustomOptionimag 扩展访问此演示链接http://mage.encoreskydev.com/custom-option-image