Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

magento 2如何获得特色产品系列

在Magento商店中展示特色产品是交叉销售和向上销售产品的有效方式。但是,要显示特色产品,商店管理员可能需要获得特色产品集合。因此,在今天的帖子中,我将向您展示三个步骤,以便在Magento 2中获得精选产品系列

如何获得精选产品系列

  • 第1步:创建FeaturedProducts块
  • 第2步:在phtml文件中插入
  • 第3步:刷新缓存和测试结果

第1步:创建FeaturedProducts块

要获得Feature Product集合,首先需要创建一个FeaturedProducts块。为此,请按照路径Mageplaza/Productslider/Block/FeaturedProducts.php添加以下代码:

<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_Productslider
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
namespace Mageplaza\Productslider\Block;
/**
 * Class FeaturedProducts
 * @package Mageplaza\Productslider\Block
 */
class FeaturedProducts extends AbstractSlider
{
    /**
     * get collection of feature products
     * @return mixed
     */
    public function getProductCollection()
    {
        $visibleProducts = $this->_catalogProductVisibility->getVisibleInCatalogIds();
        $collection = $this->_productCollectionFactory->create()->setVisibility($visibleProducts);
        $collection->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addAttributeToSelect('*')
            ->addStoreFilter($this->getStoreId())
            ->setPageSize($this->getProductsCount())
            ->addAttributeToFilter('is_featured', '1');
        return $collection;
    }
}

第2步:在phtml文件中插入

在块中收集后,现在您可以按照此片段从块中获取产品收集Mageplaza/HelloWorld/view/frontend/templates/list.phtml

接下来,请在下面插入以下代码 phtml file

<?php
$collection = $block->getProductCollection();
foreach ($collection as $_product) {
    echo $product->getName() . ' - ' . $product->getProductUrl() . '<br />';
}

第3步:刷新缓存和测试结果

最后,为了完成特色产品系列,让我们刷新缓存和测试结果。

结论

以上是关于如何在Magento 2中获得特色产品系列的说明。我希望这篇文章在管理特色产品系列时对您有所帮助

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论