Magento 类别按属性排序

发布于 2024-09-25 09:05:37 字数 1328 浏览 5 评论 0原文

我目前正在尝试为 Magento 类别页面创建一个特殊的排序功能。

我有几个属性,需要使用它们进行排序:

第一个属性名为设计师。该属性是在可配置产品上设置的。

接下来的属性称为颜色和尺寸。这些不是在可配置产品本身上设置的,而是在“简单产品”上设置的,我将其组合起来制作可配置产品。

$attributes_designers = $this->getRequest()->getParam('designers');   
$attributes_colors = $this->getRequest()->getParam('color');
$attributes_sizes = $this->getRequest()->getParam('size');

$currentCategory =  Mage::getModel('catalog/layer')->getCurrentCategory(); 
$_productCollection = $currentCategory->getProductCollection();

if(count($attributes_designers)>0 and !in_array("ALL",$attributes_designers)) {        
    $_productCollection->addAttributeToFilter('designer',$attributes_designers);
}
if(count($attributes_colors)>0 and !in_array("ALL",$attributes_colors)) {        
    $_productCollection->addAttributeToFilter('color',$attributes_colors);
}
if(count($attributes_sizes)>0 and !in_array("ALL",$attributes_sizes)) {        
    $_productCollection->addAttributeToFilter('size',$attributes_sizes);
}
if(isset($_GET['order'])) $_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir'));

$_productCollection->load();

不幸的是,我无法使属性颜色和尺寸正常工作,因为它们没有在可配置产品上设置,但它是子项。

有谁知道如何让它发挥作用吗?

提前致谢

I am currently trying to make a special sort function for a Magento category page.

I have several attributes, which I need to use for sorting:

The first attribute is named designers. This attribute is set on a configurable product.

The next attributes are named colour and size. These are not set on the configurable product itself, but on the ”simple products”, that I combine to make the configurable product.

$attributes_designers = $this->getRequest()->getParam('designers');   
$attributes_colors = $this->getRequest()->getParam('color');
$attributes_sizes = $this->getRequest()->getParam('size');

$currentCategory =  Mage::getModel('catalog/layer')->getCurrentCategory(); 
$_productCollection = $currentCategory->getProductCollection();

if(count($attributes_designers)>0 and !in_array("ALL",$attributes_designers)) {        
    $_productCollection->addAttributeToFilter('designer',$attributes_designers);
}
if(count($attributes_colors)>0 and !in_array("ALL",$attributes_colors)) {        
    $_productCollection->addAttributeToFilter('color',$attributes_colors);
}
if(count($attributes_sizes)>0 and !in_array("ALL",$attributes_sizes)) {        
    $_productCollection->addAttributeToFilter('size',$attributes_sizes);
}
if(isset($_GET['order'])) $_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir'));

$_productCollection->load();

Unfortunately I’m unable to get the attribute colour and size working, since they are not set on the configurable product, but it’s children.

Does anyone have an idea how to get this working?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2024-10-02 09:05:37

两件事:

  • 我假设您知道这一点,但只是为了确保:您可以通过在目录>>中编辑属性来轻松地使任何属性可排序。属性>>管理属性,编辑其中一个,底部选项称为“用于产品列表中的排序” - 您应该将其设置为“是”。
  • 正如您所发现的,Magento 不会希望根据与其关联的简单产品中的任何值对可配置产品进行排序。这实际上很有道理。如果您尝试按颜色排序,并且您有一个包含 2 个简单产品的可配置产品,其中一个的颜色为“Apple Red”,另一个的颜色为“Zealot Black”,那么它将如何排序?做你所希望的事情根本没有逻辑意义。它仅根据分配给可配置产品的属性进行排序。

Two things:

  • I assume you know this, but just to make sure: You can easily make any of your attributes sortable by editing the attribute in Catalog >> Attributes >> Manage Attributes, editing one and the bottom option is called "Used for Sorting in Product Listing" - which you should set to "Yes".
  • As you have found out, Magento isn't going to want to sort a configurable product by any values in the simple products that have been associated to it. This actually makes plenty of sense. If you are trying to sort by color, and you have a configurable product with 2 simple products, one of which has the color of "Apple Red" and the other with "Zealot Black", then how would it sort that? It simply cannot make logical sense to do what you are hoping. It only sorts based on attributes assigned to the configurable product.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文