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

Php I';我试图在自定义类别页面上显示可配置的样例(magento 1.9),php,magento,magento-1.9,magento-1.9.1,Php,Magento,Magento 1.9,Magento 1.9.1,我使用的是Magento 1.9.1.0,在类别和产品视图页面上有可配置的样例 我正在尝试创建一个自定义的“商店”页面,其中列出所有产品(商店只有+/-20),并显示产品下方的可配置样本 我能够创建一个商店页面,它以多种方式列出所有产品。。通过CMS、local.xml或使用控制器等。。。没问题 下面是local.xml示例*我有适当的路由设置,默认类别设置为“Is Anchor” 我还将页面引用添加到configurableswatches.xml中的页面 <mystore_site

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

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

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

下面是local.xml示例*我有适当的路由设置,默认类别设置为“Is Anchor”


我还将页面引用添加到configurableswatches.xml中的页面

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

将相应的.js文件加载到页面。。。但是,未显示任何样例

有人对我如何做到这一点有什么建议吗?我一定是错过了什么明显的东西


谢谢

如果您转到app/code/core/Mage/ConfigurableSwatches/etc/config.xml 您将在第83行的目录\块\产品\列表\收集事件上看到观察者


可配置样本/观察者
productListCollectionLoadAfter

在列表页面上添加样例可以通过多种方式完成

我将为您提供方法

方法1: 你可以使用这个免费的模块,也可以通过学习模块来学习做事情的方法

方法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 ?>

//获取属性
    • //检查库存、状态。。。 //不显示不可销售的选项
您可以用图像或标签替换下拉列表


希望这对您有用。

尝试在mystore\u site\u index\u商店块之后的local.xml文件中添加产品列表更新

在local.xml内部

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

--编辑--

尽管我能够使用上面发布的方法来实现这一点。根据我的理解,正确的方法是将你的整个主题作为rwd主题的子主题来构建,这样你就可以在没有任何黑客攻击的情况下使用样例

内置app/design/frontend/YOURTHEME/default/etc/theme.xml

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

rwd/默认值

如果查看Mage\u ConfigurableSwatches\u Model\u Observer,则

  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)来处理。您可以通过重写和添加条件来覆盖此观察者

谢谢你的指点。。。关于如何设置观察员,还有什么建议吗?我已经将(上面的)块复制到了modules config.xml中,但我确信还有更多内容。在“…索引商店”块成功之后,事件/观察者对添加“产品列表”块真的很陌生!我实际上是直接使用RWD主题——奇怪吗?谢谢
  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);
    }
}