I';我试图在自定义类别页面上显示可配置的样例(图1.9)


I'm trying to show configurable swatches on custom category page (magento 1.9)

我使用的是Magento 1.9.1.0,在类别和产品视图页面上有可配置的样例。

我正在尝试创建一个自定义的"商店"页面,其中列出了所有产品(商店只有+/-20个),显示了产品下方的可配置样例。

我可以创建商店页面,通过多种方式列出所有产品。。通过CMS、local.xml或使用控制器等。。。没有问题。

下面是local.xml示例*我设置了适当的路线,并将"默认类别"设置为"是锚点"。

<mystore_site_index_shop>
    <reference name="content">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <block type="core/text_list" name="product_list.name.after" as="name.after" />
                <block type="core/text_list" name="product_list.after" as="after" />
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
                </block>
            </block>
    </reference>
</mystore_site_index_shop>

我还在configurableswatches.xml 中添加了对该页面的页面引用

<mystore_site_index_shop>
    <update handle="product_list"/>
</mystore_site_index_shop>

它将适当的.js文件加载到页面。。。但是没有示出样本。

有人对我如何做到这一点有什么建议吗?我一定错过了一些显而易见的东西。。

谢谢!

尝试在mystore_site_index_shop块之后的local.xml文件中添加产品列表更新。

内部local.xml

<mystore_site_index_shop>
   <update handle="product_list"/>
</mystore_site_index_shop>

--编辑--

尽管我能够使用上面发布的方法来完成这项工作。根据我的理解,正确的方法是将你的整个主题构建为rwd主题的子主题,允许你在没有任何技巧的情况下使用样例。

内部应用程序/design/frontend/YOURTHEME/default/etc/theme.xml

<?xml version="1.0"?>
<theme>
<parent>rwd/default</parent>
</theme>

如果您转到app/code/core/Mage/ConfiguratbleSwatches/etc/config.xml您将在第83行的catalog_block_product_list_collection事件中看到observer。

  <catalog_block_product_list_collection>
                <observers>
                    <configurableswatches>
                        <class>configurableswatches/observer</class>
                        <method>productListCollectionLoadAfter</method>
                    </configurableswatches>
                </observers>
            </catalog_block_product_list_collection>
若你们评论这个代码,你们将不会在产品列表页面上看到样例。

在事件上添加观察者方法以添加样例。

我希望这能有所帮助。

在列表页面上添加样本是通过多种方式完成的

我将为您提供方法。

方法1:你可以使用这个模块,它是免费的,或者你可以通过学习模块来学习方法

http://magebug.blogspot.in/2013/06/magento-how-to-display-color-options-in.html

Methos 2:[这将显示可配置产品的所有选项]

<?php if($_product->isConfigurable()): ?>
  //get attributes
  <?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
  <?php if(count($attributes)): ?>
    <ul>
    <?php foreach($attributes as $att): ?>
      <?php $pAtt=$att->getProductAttribute();
        //get the child products
        $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
        $frontValues =array() ?>
      <li><?php echo $pAtt->getFrontendLabel() ?>
       <ul>
       <?php foreach($allProducts as $p): ?>
         //check stock, status, ...
         //do not show unsaleable options
         <?php if(!$p->isSaleable()) continue; ?>
         <?php $out=$p->getAttributeText($pAtt->getName()); ?>
         <?php $frontValues[$out]=$out; ?>
       <?php endforeach ?>
        <li><?php echo implode('</li><li>', $frontValues) ?></li>
       </ul>
      </li>
    <?php endforeach ?>
    </ul>
  <?php endif ?>
<?php endif ?>

您可以用图像或标签替换下拉列表。

希望这对你有用。

如果您查看Mage_ConfigurableSwatches_ModelObserver,则会发现

  public function convertLayerBlock(Varien_Event_Observer $observer)
{
    $front = Mage::app()->getRequest()->getRouteName();
    $controller = Mage::app()->getRequest()->getControllerName();
    $action = Mage::app()->getRequest()->getActionName();
    // Perform this operation if we're on a category view page or search results page
    if (($front == 'catalog' && $controller == 'category' && $action == 'view')
        || ($front == 'catalogsearch' && $controller == 'result' && $action == 'index')) {
        // Block name for layered navigation differs depending on which Magento edition we're in
        $blockName = 'catalog.leftnav';
        if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
            $blockName = ($front == 'catalogsearch') ? 'enterprisesearch.leftnav' : 'enterprisecatalog.leftnav';
        } elseif ($front == 'catalogsearch') {
            $blockName = 'catalogsearch.leftnav';
        }
        Mage::helper('configurableswatches/productlist')->convertLayerBlock($blockName);
    }
}

正如您所看到的,条件需要您的路由($front、$controller、$action)来处理。您可以通过重写和添加您的条件来覆盖这个观察者。