【问题标题】:In magento how to display associated products image in grouped products page在magento中如何在分组产品页面中显示相关产品图像
【发布时间】:2014-05-02 14:04:08
【问题描述】:

我创建了一个与 3 个产品相关联的组,现在我需要在分组的产品页面中显示每个相关产品的单独图像,并让客户从组中选择任何相关产品并将其添加到他的购物车。

【问题讨论】:

    标签: magento


    【解决方案1】:

    请按以下步骤进行:

    打开 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,并在它们列出的位置添加相关产品的图像。

    希望对你有所帮助。

    再次更新

    请更改您的应用/设计/前端/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。

    谢谢,希望这一切都解决了。

    【讨论】:

    • 是的,如果我添加此代码,我可以在表格中获取图像,但我需要自定义整个分组产品页面,并且必须单独显示带有标题的图像,就像我们在类别中显示所有产品一样page.@SKV
    • 我需要像分类页面一样重新设计我的分组产品页面。@SKV
    • Priya,您可以将网格布局 HTML 从 app/design/frontend/your_theme/template/catalog/product/view.phtml 复制到 grouped.phtml 的循环中。不要忘记更改产品循环的对象..这个建议是为了开始实现你想要的。
    • 你能简单解释一下我需要在哪里复制我的view.phtml。如何更改产品循环的对象?@SKV
    • 我需要在网格视图中显示,而不是列表视图。请找到我的附加图像。我需要显示附件中提到的产品。我不想显示描述。@SKV
    【解决方案2】:

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多