自定义产品集合上的 Magento 分层导航

     2023-04-13     161

关键词:

【中文标题】自定义产品集合上的 Magento 分层导航【英文标题】:Magento layered navigation on custom product collection 【发布时间】:2011-08-09 06:32:32 【问题描述】:

我一直在为 Magento(1.8.0.0 版)开发一个自定义模块,该模块显示某个产品的相关产品列表。

为了实现这一点,我通过覆盖 Mage_Catalog_Block_Product_List 类创建了自己的模块。

基本上是这样的:

我从控制器捕获产品 entity_id 并将产品存储在注册表中,以便我可以在名为 list.php 的自定义编写块中使用它

这是填充产品集合的方法:

protected function _getProductCollection()

    if (is_null($this->_productCollection)) 
        $prod = Mage::registry('chosenproduct');
        $this->_productCollection = $prod->getRelatedProductCollection()
            ->addAttributeToSelect('required_options')
            ->addAttributeToFilter(array(array('attribute'=>'accessory_manufacturer','neq'=>false)))
            ->addAttributeToSort('position', 'asc')
            ->addStoreFilter()
            ->setPageSize(30)
            ->setCurPage(1);
        ;

        $this->_addProductAttributesAndPrices($this->_productCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
        $this->setProductCollection($this->_productCollection);
    

    return $this->_productCollection;

我还在自定义模块的布局 .xml 中添加了以下内容,以确保显示分层导航:

<reference name="left">
        <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
    </reference>

分层导航显示,但似乎将所有产品作为集合而不是我上面添加的方法中使用的自定义集合。

我也知道我可以使用这个$layer = Mage::getSingleton('catalog/layer');获取目录/图层

图层类还有一个名为 prepareProductCollection 和 setCollection 的方法,但由于某种原因我无法让它工作。

有什么帮助吗?

基本上,我希望为自定义集合中的产品提供分层导航。

谢谢,

【问题讨论】:

【参考方案1】:

我只是设法实现了我想要的。我已经覆盖了Mage_Catalog_Model_Layer 类和Mage_Catalog_Model_Category

现在两者都有一个名为 $_customCollection 的新变量:protected $_customProductCollection;

我已经覆盖了两个类中的 getProductCollection(),并在方法的开头添加了这个:

if(isset($this->_customProductCollection))
        return $this->_customProductCollection;
    

我还有一个方法可以让我在这两个类中设置这个“customProductCollection”。设置好之后,分层导航/类别的其余数据都基于这个集合。

;)

【讨论】:

这个设置方法是什么,从哪里调用的?

Magento:自定义集合中缺少分页

】Magento:自定义集合中缺少分页【英文标题】:Magento:Paginationmissingincustomcollection【发布时间】:2014-09-2813:54:29【问题描述】:在显示自定义产品集合时,我遇到了分页问题。由于我是Magento的新手,请容忍我理解的任何幼稚。目... 查看详情

Magento 从目录和搜索中隐藏可配置产品

】Magento从目录和搜索中隐藏可配置产品【英文标题】:Magentohideconfigurableproductfromcatalogandsearch【发布时间】:2014-07-3116:37:29【问题描述】:我希望使用分层导航通过自定义属性(例如colour_group)按相似颜色对产品进行分组目前我... 查看详情

Magento 以任意顺序获取产品集合

】Magento以任意顺序获取产品集合【英文标题】:Magentogetaproductcollectioninanarbitraryorder【发布时间】:2010-10-2117:34:46【问题描述】:我已经为我们的Magento商店开发了一个自定义搜索引擎,我正在尝试以非常特定的顺序加载产品集合... 查看详情

用于添加产品愿望清单的 Magento 自定义 API

】用于添加产品愿望清单的Magento自定义API【英文标题】:MagentocustomAPIforaddingproductwishlist【发布时间】:2013-08-0610:40:35【问题描述】:我正在为愿望清单实现magento自定义API。谁能知道,如何添加愿望清单。我尝试使用magento\'wishli... 查看详情

Magento - 自定义选项不会更新可配置产品的价格

】Magento-自定义选项不会更新可配置产品的价格【英文标题】:Magento-Customoptionsdonotupdatepriceofconfigurableproduct【发布时间】:2016-11-0712:01:38【问题描述】:在Magento1.9中,我创建了具有2个关联产品的可配置产品。在超级产品属性配... 查看详情

Magento 自定义集合打破了分页

】Magento自定义集合打破了分页【英文标题】:Magentocustomcollectionbreakspagination【发布时间】:2012-01-2006:47:39【问题描述】:我通过向Varien_Data_Collection集合对象添加项目来创建集合。$collection=newVarien_Data_Collection();foreach($array_of_produc... 查看详情

magento-获取自定义产品属性

Howtogetacustomproductattributeinsideaview(.phtml)file.<?php$_product=$this->getProduct();echo$_product->getData('attribute_name');?> 查看详情

magento 导出具有自定义字段的产品

】magento导出具有自定义字段的产品【英文标题】:magentoexportproductswithcustomfield【发布时间】:2014-08-2016:48:40【问题描述】:我正在使用数据流-配置文件来导出所有产品。但我需要来自默认列映射器的更多列。我需要以下列实体I... 查看详情

Magento:高级搜索结果的分层导航

】Magento:高级搜索结果的分层导航【英文标题】:Magento:LayeredNavigationonAdvancedSearchResults【发布时间】:2012-10-2606:05:59【问题描述】:我需要在Magento高级搜索结果页面上显示分层导航过滤器,就像在目录搜索结果页面上一样。我... 查看详情

如何从产品属性在 magento 中添加自定义搜索字段

】如何从产品属性在magento中添加自定义搜索字段【英文标题】:Howtoaddcustomsearchfieldinmagentofromproductattribute【发布时间】:2015-12-2517:11:07【问题描述】:我想添加具有以下字段、搜索文本、品牌名称(组合框)属性和搜索按钮的... 查看详情

Magento 2.3.5:使用自定义选项和价格将产品添加到购物车

】Magento2.3.5:使用自定义选项和价格将产品添加到购物车【英文标题】:Magento2.3.5:Addproducttocartwithcustomoptionsandprice【发布时间】:2020-09-0600:52:21【问题描述】:为什么Magento的文档如此糟糕?为它构建一个插件非常困难。无论如... 查看详情

改进magento中的分层导航

ImprovedLayeredNavigationbyAmastyisapremium5-year-oldMagentoextension,towhichyoucanentrustyournavigation.Itincludes7mods:SeolayerednavigationShopbybrandsAjaxLayeredNavigationLayerednavigationfiltersAdvancedcategoriesmenuLayeredNavigationproPriceslidersandothernumericfiltershttp://amasty.com/ 查看详情

Magento JOIN 在两个过滤的自定义集合之间

】MagentoJOIN在两个过滤的自定义集合之间【英文标题】:MagentoJOINbetweentwofilteredcustomcollections【发布时间】:2013-06-0106:45:38【问题描述】:我有两个自定义模型(“myorder”和“myarticle”)。每个“myarticle”都有一个外键“rif_ord_app... 查看详情

xml在magento中添加自定义活动链接到客户帐户导航(代码片段)

查看详情

将“添加到购物车”按钮重定向到 Magento 中的不同自定义页面/在 Magento 的产品页面中添加新按钮

】将“添加到购物车”按钮重定向到Magento中的不同自定义页面/在Magento的产品页面中添加新按钮【英文标题】:Redirect"AddToCart"ButtontodifferentcustompageInMagento/AddnewButtoninProductPageinMagento【发布时间】:2015-09-0506:00:00【问题描... 查看详情

Magento 获取未加载所有属性的相关产品

】Magento获取未加载所有属性的相关产品【英文标题】:Magentogetrelatedproductsnothavingallattributesloaded【发布时间】:2017-08-2223:46:06【问题描述】:我正在接手一个项目,看到之前的开发人员添加了一个自定义相关产品关联。所以他实... 查看详情

Magento:自定义模块错误(在 Layout.php 中找不到类)

】Magento:自定义模块错误(在Layout.php中找不到类)【英文标题】:Magento:errorforcustommodule(ClassnotfoundinLayout.php)【发布时间】:2013-01-1714:57:36【问题描述】:我尝试在Magento中创建一个新的自定义模块(块),它将在产品详细信息... 查看详情

将 WooCommerce 自定义产品属性转换为定义的产品属性

】将WooCommerce自定义产品属性转换为定义的产品属性【英文标题】:ConvertWooCommerceCustomProductAttributesintoDefinedProductAttributes【发布时间】:2016-12-2023:44:57【问题描述】:我正在尝试使用WooCommerce的分层导航属性过滤器侧边栏小部件... 查看详情