Magento小部件块中的分页 [英] Pagination in Magento widget block

查看:97
本文介绍了Magento小部件块中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在小部件块中进行分页.例如,具有ID 355的类别.我想在页面中显示该类别产品.所以我正在使用小部件(以下代码)

Hi is there any way to do pagination in widget block . For example have a category with id 355 . I want to display that category product in a page . So i am using widget( following code )

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" show_pager="0" products_count="160" template="Magento_CatalogWidget::product/widget/content/grid.phtml" conditions_encoded="^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,`aggregator`:`all`,`value`:`1`,`new_child`:``^],`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,`attribute`:`category_ids`,`operator`:`==`,`value`:`355`^]^]"}}

.但是该页面中正在显示该产品中最多有155个产品.但是对于155个产品,页面加载时间太长.因此,如果要进行分页,则很容易加载产品.

. But there are upto 155 product in that category the product are displaying in the page . But for 155 product the page load time is too high . So if there will be pagination for that then its easy to load the products .

推荐答案

实际上,寻呼机是为Magento \ CatalogWidget \ Block \ Product \ ProductsList实现的,您只需要使用 show_pager ="1" 并定义每页显示多少产品 products_per_page ="6" (如果忽略此参数,则默认值为5)

In fact Yes, pager is implemented for Magento\CatalogWidget\Block\Product\ProductsList, you just need to activate it using show_pager="1" and define how much products to show per page products_per_page="6" (if you ignore this param then default value is 5)

更新: 我想您需要添加参数 page_var_name ="np" ,其中"np"是分页参数的名称(您可以在方便时命名),如下所示,这应该可以解决分页问题:

UPDATE : I guess you need to add the param page_var_name="np" where 'np' is the name of the pagination parameter (you can name it at your convenience), like following and this should resolve the pagination issue :

您的代码应像这样:

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" show_pager="1" products_per_page="6" products_count="160" page_var_name="np" template="Magento_CatalogWidget::product/widget/content/grid.phtml" conditions_encoded="^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,`aggregator`:`all`,`value`:`1`,`new_child`:``^],`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,`attribute`:`category_ids`,`operator`:`==`,`value`:`355`^]^]"}}

@see:供应商/magento/module-catalog-widget/模块/产品/ProductsList.php

class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implements BlockInterface, IdentityInterface
{
    /**
     * Default value for products count that will be shown
     */
    const DEFAULT_PRODUCTS_COUNT = 10;

    /**
     * Name of request parameter for page number value
     *
     * @deprecated
     */
    const PAGE_VAR_NAME = 'np';

    /**
     * Default value for products per page
     */
    const DEFAULT_PRODUCTS_PER_PAGE = 5;

    /**
     * Default value whether show pager or not
     */
    const DEFAULT_SHOW_PAGER = false;
...


   /**
     * Retrieve how many products should be displayed
     *
     * @return int
     */
    public function getProductsPerPage()
    {
        if (!$this->hasData('products_per_page')) {
            $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
        }
        return $this->getData('products_per_page');
    }

    /**
     * Return flag whether pager need to be shown or not
     *
     * @return bool
     */
    public function showPager()
    {
        if (!$this->hasData('show_pager')) {
            $this->setData('show_pager', self::DEFAULT_SHOW_PAGER);
        }
        return (bool)$this->getData('show_pager');
    }

    /**
     * Retrieve how many products should be displayed on page
     *
     * @return int
     */
    protected function getPageSize()
    {
        return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
    }

这篇关于Magento小部件块中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆