【问题标题】:How to display Configurable Swatches in Home Page Magento 1.9如何在主页 Magento 1.9 中显示可配置色板
【发布时间】:2017-02-20 18:31:44
【问题描述】:

我的主页上有一个产品列表,但我很难在主页上的产品上显示可配置/色样。我的目录列表上的可配置/颜色样本工作正常。我猜我只需要配置我的布局,但我不知道如何。我正在使用 RWD 主题和 Magento 1.9。

任何人,请帮助我。谢谢!

更新!!

所以我发现这个

<script type="text/javascript">
    $j(document).on('product-media-loaded', function() {
        ConfigurableMediaImages.init('<?php echo $this->getImageType(); ?>');
        <?php foreach ($this->getProductImageFallbacks() as $imageFallback): ?>
        ConfigurableMediaImages.setImageFallback(<?php echo $imageFallback['product']->getId(); ?>, $j.parseJSON('<?php echo $imageFallback['image_fallback']; ?>'));
        <?php endforeach; ?>
        $j(document).trigger('configurable-media-images-init', ConfigurableMediaImages);
    });
</script>

在 app/design/frontend//default/configurableswatches/catalog/media/js.phtml

是问题的原因。

但在此之前,我将其粘贴到我的 local.xml 中

<cms_index_index translate="label">
    <update handle="product_list"/> 
    <reference name="content">
         <block type="configurableswatches/catalog_media_js_list" name="configurableswatches.media.js.list" />
     </reference>
</cms_index_index>

然后我发现产品没有填充它的小图像。 如果您注意到,上面的 javascript 中有一个 for 循环,但它不起作用,因为 getProductImageFallbacks() 返回 NULL。

这是我放在我的 CMS 内容(主页)上的内容

{{block type="catalog/product_list" column_count="5" category_id="21" template="catalog/product/homepage-list.phtml"}}

在 app/code/local/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php 中 public function getProductImageFallbacks($keepFrame = null) 的第 69 行

这个$products = $this-&gt;getProducts(); 给了我NULL。这就是为什么它不能提供正确的图像后备。

仍在等待答复。请帮我。

【问题讨论】:

    标签: magento magento-1.9 configurable-product


    【解决方案1】:

    试试下面的代码:

    <?php
    $categoryId = 3 //your category id's;
    $collection = Mage::getSingleton('catalog/category')->load($categoryId)
    ->getProductCollection()->addAttributeToFilter('visibility', 4)
    ->addAttributeToSelect('*')->addAttributeToFilter('status',1);
    
    foreach($collection as $pro):
    $productAttributeOptions =
    $pro->getTypeInstance(true)->getConfigurableAttributesAsArray($pro);
    ?>
    <h3 class="product-name"><?php  echo $pro->getName(); ?></h3>
    
    <?php
    

    // 提供额外的块,在这些块上悬挂产品的某些功能 列表

    // 提供针对此块的 UI 元素的功能将显示 产品名称的正下方

    if ($this->getChild('name.after')) {
    $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
    foreach ($_nameAfterChildren as $_nameAfterChildName) {
    $_nameAfterChild =
    $this->getChild('name.after')->getChild($_nameAfterChildName);
    $_nameAfterChild->setProduct($_product);
    echo $_nameAfterChild->toHtml();
    }
    }
    ?>
    <?php endforeach; ?>
    

    【讨论】:

    • 您好!感谢您的回答。我会试试的。我创建了另一个 list.phtml(我将其命名为 homepage-list.phtml),并根据我在 CMS 部分的主页内容编写了 {{block type="catalog/product_list" column_count="5" category_id="21" template= “目录/产品/主页-list.phtml”}}。我只是要将上面的代码添加到我的 homepage-list.phtml 中,对吧?
    【解决方案2】:

    要在特色产品列表的主页上显示可配置色板,请按照以下步骤操作:

    为自定义产品列表制作您自己的 list.phtml 文件 在您的 list.phtml 文件中,选择要显示可配置色板的位置并粘贴以下代码:

     $_nameAfterChild = $this->getLayout()->getBlock('product_list.swatches');
        $_nameAfterChild->setProduct($_product);
        echo $_nameAfterChild->toHtml();
    使用以下代码将此文件包含在 CMS 的主页中:
    {{block type="catalog/product_list" column_count="5" category_id="21" template="catalog/product/homepage-list.phtml"}}

    在您的主题中的local.xml 文件中粘贴以下代码:

    cms_index_index 更新句柄="product_list"/ /cms_index_index

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多