简体   繁体   English

当产品列表页上的limit = all时,Magento产品计数错误

[英]Magento incorrect product count when limit=all on product list page

In the process of upgrading a pre-1.4 Magento site to version 1.4.1.2, I've run across a problem. 在将1.4版之前的Magento网站升级到1.4.1.2版的过程中,我遇到了一个问题。 On the product list view pages, the option to view all products only shows 10 (in categories with more than 10 products). 在产品列表查看页面上,查看所有产品的选项仅显示10个(类别超过10个产品)。 Here are some relevant settings from the catalog section of the system configuration: 以下是系统配置目录部分中的一些相关设置:

List Mode: Grid Only
Products per Page on Grid Allowed Values: 8,16,32
Products per Page on Grid Default Value: 8
Allow All Products per Page: Yes

There are no explicit limits set in the layout file THEME/layout/catalog.xml. 在布局文件THEME / layout / catalog.xml中没有设置任何明确的限制。

On the product list view, if the "limit" parameter is set to one of the allowed integer values (8,16,32), the listing works as expected. 在产品列表视图上,如果将“ limit”参数设置为允许的整数值之一(8、16、32),则该列表将按预期工作。 But if the parameter "limit=all" is used, only 10 products are displayed. 但是,如果使用参数“ limit = all”,则仅显示10个产品。

Using the firephp extension to look at the product list page for a category with 184 products, I see the following: 使用firephp扩展名查看具有184个产品的类别的产品列表页面,我看到以下内容:

limit=16
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->count() returns 16
THEME/template/catalog/product/list/toolbar.phtml: $this->getCollection()->getSize() returns 184

limit=all
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->count() returns 10
THEME/template/catalog/product/list/toolbar.phtml: $this->getCollection()->getSize() returns 184

I've looked in the _getProductCollection() method in Mage_Catalog_Block_Product_List, but don't see the query limit set anywhere. 我已经查看了Mage_Catalog_Block_Product_List中的_getProductCollection()方法,但是没有在任何地方看到设置的查询限制。 Any ideas where this limit of 10 is coming from or how to get the "all" limit to work correctly? 有什么想法来自这个限制10,或者如何使“所有”限制正常工作?

Update 更新资料

count() and getSize() return different values in THEME/template/catalog/product/list.phtml count()和getSize()在THEME / template / catalog / product / list.phtml中返回不同的值

limit=16
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->count() returns 16
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->getSize() returns 184
THEME/template/catalog/product/list/toolbar.phtml: $this->getCollection()->getSize() returns 184

limit=all
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->count() returns 10
THEME/template/catalog/product/list.phtml: $this->getLoadedProductCollection()->getSize() returns 184
THEME/template/catalog/product/list/toolbar.phtml: $this->getCollection()->getSize() returns 184

This only occurs in my custom theme. 这仅发生在我的自定义主题中。 If I switch the theme to the "base" package, the limit=all condition returns 184 products for both count() and getSize(). 如果将主题切换为“基本”包,则limit = all条件为count()和getSize()返回184个产品。 My custom theme has only minor markup / CSS changes to list.phtml (the PHP code is the same). 我的自定义主题仅对list.phtml进行了少量标记/ CSS更改(PHP代码相同)。

The Pager was the culprit. 寻呼机是元凶。 The pre-1.4 Magento theme utilized some Pager logic in THEME/template/catalog/category/view.phtml. 1.4版之前的Magento主题在THEME / template / catalog / category / view.phtml中利用了一些Pager逻辑。 In 1.4.x, the Pager has been revised, and needs to have an explicit limit set for use on the category view page. 在1.4.x中,已对Pager进行了修订,并且需要设置一个明确的限制,以便在类别视图页面上使用。

The take-home message here is that if you find yourself instantiating the "product_list_toolbar_pager", make sure you set the limit to the same limit used on the toolbar. 这里的提示是,如果您发现自己实例化了“ product_list_toolbar_pager”,请确保将限制设置为与工具栏上使用的限制相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM