Warm tip: This article is reproduced from serverfault.com, please click

php-根据自定义选项交换Magento产品图像

(php - Swap Magento Product images based on custom option)

发布于 2012-08-30 21:30:19

我的产品以网格格式显示,并直接从此页面购买。它们是带有自定义选项的简单产品。每个选项都是一种颜色。是否有被选择的下拉为相关色时的图像分配给每个产品/颜色组合并显示图像的方法吗?

 ` <?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;"> 
`
Questioner
Sam Danger
Viewed
11
Theodores 2012-08-31 09:59:16

在产品页面(而非类别页面)上,有几种商业模块有望实现此功能。因此,没有现成的简易选项。

出于SKU计数,从类别页面订购和数据库可维护性的考虑,可配置产品可能不是解决之道。

一个简单的解决方法是创建media / swatch / red.jpg,media / swatch / orange.jpg,media / swatch / redgreenstripes.jpg等。然后在前端代码中,拉出与所需选项匹配的色板。对于每种颜色选项,你都需要压缩代码,将其与get-base-dir-media-swatches串联,然后将其弹出到图像标签中。

Blutak和字符串解决方案?是的,但是你不必花一整天的时间编写模块。