duanqi6007 2012-08-30 21:30
浏览 50
已采纳

根据自定义选项交换Magento产品图片

My products are displayed in a grid format, and purchased directly from this page. They are simple products with custom options. Each option is a color. Is there a way to assign an image to each product/color combo and display that image when the drop down for the associated color is is selected?

 ` <?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;"> 
`
  • 写回答

2条回答 默认 最新

  • dongniaocheng3773 2012-08-31 01:59
    关注

    There are several commercial modules promising this functionality on the product page but not the category page. Therefore there is no off the shelf easy option.

    For reasons of SKU count, ordering from the category page and database maintainability, configurable products may not be the way to go here.

    A simple workaround is to create media/swatch/red.jpg, media/swatch/orange.jpg, media/swatch/redgreenstripes.jpg and so on. Then in the frontend code, pull up the swatch matching the option required. For each colour option you'll need to strtolower the code, concatenate it with get-base-dir-media-swatches and pop it in an image tag.

    A Blutak and string solution? Yes, but you won't need to spend all day writing a module.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)