How to get only configurable products as a bestseller in Magento 2?Magento 2: to use or not to use the ObjectManager directly?Display Bestsellers products firstCan't get “products ordered” collection with configurable products included (top 10 products)Filter product collection to include only one parent configurable productbestseller how is it determined? Can it be based on number of orders instead of quantity?Magento 2 : get best seller product on daily basisJS minification issue still pendingHow to get Class names of all the elements while writing LESS?Best Sellers ReportMagento 2 - how to change the product name in a configurable productGet Configurable Product options, Price And Add to cart Button On Related Product Section

Can someone clarify Hamming's notion of important problems in relation to modern academia?

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?

How to travel to Japan while expressing milk?

Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Sums of two squares in arithmetic progressions

Mathematica command that allows it to read my intentions

Why do I get negative height?

What are the G forces leaving Earth orbit?

What does the same-ish mean?

In the UK, is it possible to get a referendum by a court decision?

Can a virus destroy the BIOS of a modern computer?

How to show a landlord what we have in savings?

If a warlock makes a Dancing Sword their pact weapon, is there a way to prevent it from disappearing if it's farther away for more than a minute?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Convert seconds to minutes

How can a day be of 24 hours?

Getting extremely large arrows with tikzcd

What do you call someone who asks many questions?

What historical events would have to change in order to make 19th century "steampunk" technology possible?

Did 'Cinema Songs' exist during Hiranyakshipu's time?

Why were 5.25" floppy drives cheaper than 8"?

How can I prove that a state of equilibrium is unstable?

How to stretch the corners of this image so that it looks like a perfect rectangle?



How to get only configurable products as a bestseller in Magento 2?


Magento 2: to use or not to use the ObjectManager directly?Display Bestsellers products firstCan't get “products ordered” collection with configurable products included (top 10 products)Filter product collection to include only one parent configurable productbestseller how is it determined? Can it be based on number of orders instead of quantity?Magento 2 : get best seller product on daily basisJS minification issue still pendingHow to get Class names of all the elements while writing LESS?Best Sellers ReportMagento 2 - how to change the product name in a configurable productGet Configurable Product options, Price And Add to cart Button On Related Product Section













0















My site contain only configurable products and I want to display bestseller products. I know there are many extension available for bestseller products but i want to display only configurable products.



Can anyone help me solve this.



Thanks In Advance.










share|improve this question
























  • Have you got solution?

    – Chirag Patel
    14 hours ago











  • @ChiragPatel, Not yet I have got error in addAttributeToFilter()

    – Sanjay Gohil
    14 hours ago











  • Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

    – Chirag Patel
    13 hours ago















0















My site contain only configurable products and I want to display bestseller products. I know there are many extension available for bestseller products but i want to display only configurable products.



Can anyone help me solve this.



Thanks In Advance.










share|improve this question
























  • Have you got solution?

    – Chirag Patel
    14 hours ago











  • @ChiragPatel, Not yet I have got error in addAttributeToFilter()

    – Sanjay Gohil
    14 hours ago











  • Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

    – Chirag Patel
    13 hours ago













0












0








0


1






My site contain only configurable products and I want to display bestseller products. I know there are many extension available for bestseller products but i want to display only configurable products.



Can anyone help me solve this.



Thanks In Advance.










share|improve this question
















My site contain only configurable products and I want to display bestseller products. I know there are many extension available for bestseller products but i want to display only configurable products.



Can anyone help me solve this.



Thanks In Advance.







magento2.2.6 best-seller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









Hassan Ali Shahzad

655317




655317










asked 17 hours ago









Sanjay GohilSanjay Gohil

476215




476215












  • Have you got solution?

    – Chirag Patel
    14 hours ago











  • @ChiragPatel, Not yet I have got error in addAttributeToFilter()

    – Sanjay Gohil
    14 hours ago











  • Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

    – Chirag Patel
    13 hours ago

















  • Have you got solution?

    – Chirag Patel
    14 hours ago











  • @ChiragPatel, Not yet I have got error in addAttributeToFilter()

    – Sanjay Gohil
    14 hours ago











  • Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

    – Chirag Patel
    13 hours ago
















Have you got solution?

– Chirag Patel
14 hours ago





Have you got solution?

– Chirag Patel
14 hours ago













@ChiragPatel, Not yet I have got error in addAttributeToFilter()

– Sanjay Gohil
14 hours ago





@ChiragPatel, Not yet I have got error in addAttributeToFilter()

– Sanjay Gohil
14 hours ago













Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

– Chirag Patel
13 hours ago





Try addFilter('type_id', 'simple') insted of addAttributeToFilter()

– Chirag Patel
13 hours ago










3 Answers
3






active

oldest

votes


















1














Its better to use productRepository:-
inject BestSellerProducts class in your class via DI



 $bestSellerProducts->getBestSellingProducts();


your custom class can be as:-



<?php
namespace VendorModlueNameModel;

use MagentoFrameworkApiSearchCriteriaBuilder;
use MagentoCatalogApiProductRepositoryInterface;

class BestSellerProducts

/** @var ProductRepositoryInterface */
protected $productRepository;

/** @var SearchCriteriaBuilder */
protected $searchCriteriaBuilder;

/**
* Initialize dependencies.
*
* @param ProductRepositoryInterface $productRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
ProductRepositoryInterface $productRepository,
SearchCriteriaBuilder $searchCriteriaBuilder
)
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;


/**
* Get products with filter.
*
* @return MagentoCatalogApiDataProductInterface[]
*/
public function getBestSellingProducts()

$searchCriteria = $this->searchCriteriaBuilder->addFilter('type_id', 'configurable', 'eq')->create();
$products = $this->productRepository->getList($searchCriteria);
return $products->getItems();







share|improve this answer






























    0














    Try with below way.



    Step 1 : Create block file.



    <?php
    namespace NamespaceModulenameBlock;

    class BestSeller extends MagentoFrameworkViewElementTemplate


    protected $_collectionFactory;
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
    array $data = []
    )

    $this->_collectionFactory = $collectionFactory;
    parent::__construct($context, $data);



    public function getBestSellerData()

    $bestSellerProdcutCollection = $this->_collectionFactory->create()
    ->setModel('MagentoCatalogModelProduct')
    ->setPeriod('month');

    $bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
    ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
    ->load();

    return $bsProducts;




    Step 2 : Create phtml file to display collection.



    <?php
    $bestSeller = $block->getBestSellerData(); ?>
    <h1>Best Seller Collection.....</h1>
    <ul>
    <?php foreach ($bestSeller as $product)
    ?>
    <li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
    <?php ?>
    </ul>


    Note : Use Factory methode insted of object manager.



    I hope it works!






    share|improve this answer























    • I will try and let you know within 10 minutes

      – Sanjay Gohil
      16 hours ago











    • Okay, let me know if you have any query.

      – Chirag Patel
      16 hours ago


















    0














    try this way..



    using block class file



    <?php
    namespace VendorModuleBlock;

    class BestSeller extends MagentoFrameworkViewElementTemplate


    protected $_collectionFactory;
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
    array $data = []
    )

    $this->_collectionFactory = $collectionFactory;
    parent::__construct($context, $data);



    public function getBestSellerData()

    $bestsellers = $this->_collectionFactory->create()
    ->setModel('MagentoCatalogModelProduct')
    ->setPeriod('month');

    $collection = $bestsellers->addAttributeToSelect('*')
    ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
    ->load();

    return $collection;




    or using object manager



    <?php 
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $productCollection = $objectManager->create('MagentoReportsModelResourceModelReportCollectionFactory');
    $collection = $productCollection->create('MagentoSalesModelResourceModelReportBestsellersCollection');

    $collection->setPeriod('month');

    $products = $collection->addAttributeToSelect('*')
    ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
    ->setPageSize(10)
    ->load();


    foreach ($products as $product)
    print_r($product->getData());



    Don't use Object Manager instance directly check this for more details






    share|improve this answer

























    • Let me know if you have any confusion for implementation.

      – Rakesh Donga
      14 hours ago











    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268298%2fhow-to-get-only-configurable-products-as-a-bestseller-in-magento-2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Its better to use productRepository:-
    inject BestSellerProducts class in your class via DI



     $bestSellerProducts->getBestSellingProducts();


    your custom class can be as:-



    <?php
    namespace VendorModlueNameModel;

    use MagentoFrameworkApiSearchCriteriaBuilder;
    use MagentoCatalogApiProductRepositoryInterface;

    class BestSellerProducts

    /** @var ProductRepositoryInterface */
    protected $productRepository;

    /** @var SearchCriteriaBuilder */
    protected $searchCriteriaBuilder;

    /**
    * Initialize dependencies.
    *
    * @param ProductRepositoryInterface $productRepository
    * @param SearchCriteriaBuilder $searchCriteriaBuilder
    */
    public function __construct(
    ProductRepositoryInterface $productRepository,
    SearchCriteriaBuilder $searchCriteriaBuilder
    )
    $this->productRepository = $productRepository;
    $this->searchCriteriaBuilder = $searchCriteriaBuilder;


    /**
    * Get products with filter.
    *
    * @return MagentoCatalogApiDataProductInterface[]
    */
    public function getBestSellingProducts()

    $searchCriteria = $this->searchCriteriaBuilder->addFilter('type_id', 'configurable', 'eq')->create();
    $products = $this->productRepository->getList($searchCriteria);
    return $products->getItems();







    share|improve this answer



























      1














      Its better to use productRepository:-
      inject BestSellerProducts class in your class via DI



       $bestSellerProducts->getBestSellingProducts();


      your custom class can be as:-



      <?php
      namespace VendorModlueNameModel;

      use MagentoFrameworkApiSearchCriteriaBuilder;
      use MagentoCatalogApiProductRepositoryInterface;

      class BestSellerProducts

      /** @var ProductRepositoryInterface */
      protected $productRepository;

      /** @var SearchCriteriaBuilder */
      protected $searchCriteriaBuilder;

      /**
      * Initialize dependencies.
      *
      * @param ProductRepositoryInterface $productRepository
      * @param SearchCriteriaBuilder $searchCriteriaBuilder
      */
      public function __construct(
      ProductRepositoryInterface $productRepository,
      SearchCriteriaBuilder $searchCriteriaBuilder
      )
      $this->productRepository = $productRepository;
      $this->searchCriteriaBuilder = $searchCriteriaBuilder;


      /**
      * Get products with filter.
      *
      * @return MagentoCatalogApiDataProductInterface[]
      */
      public function getBestSellingProducts()

      $searchCriteria = $this->searchCriteriaBuilder->addFilter('type_id', 'configurable', 'eq')->create();
      $products = $this->productRepository->getList($searchCriteria);
      return $products->getItems();







      share|improve this answer

























        1












        1








        1







        Its better to use productRepository:-
        inject BestSellerProducts class in your class via DI



         $bestSellerProducts->getBestSellingProducts();


        your custom class can be as:-



        <?php
        namespace VendorModlueNameModel;

        use MagentoFrameworkApiSearchCriteriaBuilder;
        use MagentoCatalogApiProductRepositoryInterface;

        class BestSellerProducts

        /** @var ProductRepositoryInterface */
        protected $productRepository;

        /** @var SearchCriteriaBuilder */
        protected $searchCriteriaBuilder;

        /**
        * Initialize dependencies.
        *
        * @param ProductRepositoryInterface $productRepository
        * @param SearchCriteriaBuilder $searchCriteriaBuilder
        */
        public function __construct(
        ProductRepositoryInterface $productRepository,
        SearchCriteriaBuilder $searchCriteriaBuilder
        )
        $this->productRepository = $productRepository;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;


        /**
        * Get products with filter.
        *
        * @return MagentoCatalogApiDataProductInterface[]
        */
        public function getBestSellingProducts()

        $searchCriteria = $this->searchCriteriaBuilder->addFilter('type_id', 'configurable', 'eq')->create();
        $products = $this->productRepository->getList($searchCriteria);
        return $products->getItems();







        share|improve this answer













        Its better to use productRepository:-
        inject BestSellerProducts class in your class via DI



         $bestSellerProducts->getBestSellingProducts();


        your custom class can be as:-



        <?php
        namespace VendorModlueNameModel;

        use MagentoFrameworkApiSearchCriteriaBuilder;
        use MagentoCatalogApiProductRepositoryInterface;

        class BestSellerProducts

        /** @var ProductRepositoryInterface */
        protected $productRepository;

        /** @var SearchCriteriaBuilder */
        protected $searchCriteriaBuilder;

        /**
        * Initialize dependencies.
        *
        * @param ProductRepositoryInterface $productRepository
        * @param SearchCriteriaBuilder $searchCriteriaBuilder
        */
        public function __construct(
        ProductRepositoryInterface $productRepository,
        SearchCriteriaBuilder $searchCriteriaBuilder
        )
        $this->productRepository = $productRepository;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;


        /**
        * Get products with filter.
        *
        * @return MagentoCatalogApiDataProductInterface[]
        */
        public function getBestSellingProducts()

        $searchCriteria = $this->searchCriteriaBuilder->addFilter('type_id', 'configurable', 'eq')->create();
        $products = $this->productRepository->getList($searchCriteria);
        return $products->getItems();








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 16 hours ago









        Hassan Ali ShahzadHassan Ali Shahzad

        655317




        655317























            0














            Try with below way.



            Step 1 : Create block file.



            <?php
            namespace NamespaceModulenameBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestSellerProdcutCollection = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $bsProducts;




            Step 2 : Create phtml file to display collection.



            <?php
            $bestSeller = $block->getBestSellerData(); ?>
            <h1>Best Seller Collection.....</h1>
            <ul>
            <?php foreach ($bestSeller as $product)
            ?>
            <li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
            <?php ?>
            </ul>


            Note : Use Factory methode insted of object manager.



            I hope it works!






            share|improve this answer























            • I will try and let you know within 10 minutes

              – Sanjay Gohil
              16 hours ago











            • Okay, let me know if you have any query.

              – Chirag Patel
              16 hours ago















            0














            Try with below way.



            Step 1 : Create block file.



            <?php
            namespace NamespaceModulenameBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestSellerProdcutCollection = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $bsProducts;




            Step 2 : Create phtml file to display collection.



            <?php
            $bestSeller = $block->getBestSellerData(); ?>
            <h1>Best Seller Collection.....</h1>
            <ul>
            <?php foreach ($bestSeller as $product)
            ?>
            <li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
            <?php ?>
            </ul>


            Note : Use Factory methode insted of object manager.



            I hope it works!






            share|improve this answer























            • I will try and let you know within 10 minutes

              – Sanjay Gohil
              16 hours ago











            • Okay, let me know if you have any query.

              – Chirag Patel
              16 hours ago













            0












            0








            0







            Try with below way.



            Step 1 : Create block file.



            <?php
            namespace NamespaceModulenameBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestSellerProdcutCollection = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $bsProducts;




            Step 2 : Create phtml file to display collection.



            <?php
            $bestSeller = $block->getBestSellerData(); ?>
            <h1>Best Seller Collection.....</h1>
            <ul>
            <?php foreach ($bestSeller as $product)
            ?>
            <li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
            <?php ?>
            </ul>


            Note : Use Factory methode insted of object manager.



            I hope it works!






            share|improve this answer













            Try with below way.



            Step 1 : Create block file.



            <?php
            namespace NamespaceModulenameBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestSellerProdcutCollection = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $bsProducts;




            Step 2 : Create phtml file to display collection.



            <?php
            $bestSeller = $block->getBestSellerData(); ?>
            <h1>Best Seller Collection.....</h1>
            <ul>
            <?php foreach ($bestSeller as $product)
            ?>
            <li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
            <?php ?>
            </ul>


            Note : Use Factory methode insted of object manager.



            I hope it works!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 16 hours ago









            Chirag PatelChirag Patel

            2,468423




            2,468423












            • I will try and let you know within 10 minutes

              – Sanjay Gohil
              16 hours ago











            • Okay, let me know if you have any query.

              – Chirag Patel
              16 hours ago

















            • I will try and let you know within 10 minutes

              – Sanjay Gohil
              16 hours ago











            • Okay, let me know if you have any query.

              – Chirag Patel
              16 hours ago
















            I will try and let you know within 10 minutes

            – Sanjay Gohil
            16 hours ago





            I will try and let you know within 10 minutes

            – Sanjay Gohil
            16 hours ago













            Okay, let me know if you have any query.

            – Chirag Patel
            16 hours ago





            Okay, let me know if you have any query.

            – Chirag Patel
            16 hours ago











            0














            try this way..



            using block class file



            <?php
            namespace VendorModuleBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestsellers = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $collection = $bestsellers->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $collection;




            or using object manager



            <?php 
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $productCollection = $objectManager->create('MagentoReportsModelResourceModelReportCollectionFactory');
            $collection = $productCollection->create('MagentoSalesModelResourceModelReportBestsellersCollection');

            $collection->setPeriod('month');

            $products = $collection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->setPageSize(10)
            ->load();


            foreach ($products as $product)
            print_r($product->getData());



            Don't use Object Manager instance directly check this for more details






            share|improve this answer

























            • Let me know if you have any confusion for implementation.

              – Rakesh Donga
              14 hours ago















            0














            try this way..



            using block class file



            <?php
            namespace VendorModuleBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestsellers = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $collection = $bestsellers->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $collection;




            or using object manager



            <?php 
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $productCollection = $objectManager->create('MagentoReportsModelResourceModelReportCollectionFactory');
            $collection = $productCollection->create('MagentoSalesModelResourceModelReportBestsellersCollection');

            $collection->setPeriod('month');

            $products = $collection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->setPageSize(10)
            ->load();


            foreach ($products as $product)
            print_r($product->getData());



            Don't use Object Manager instance directly check this for more details






            share|improve this answer

























            • Let me know if you have any confusion for implementation.

              – Rakesh Donga
              14 hours ago













            0












            0








            0







            try this way..



            using block class file



            <?php
            namespace VendorModuleBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestsellers = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $collection = $bestsellers->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $collection;




            or using object manager



            <?php 
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $productCollection = $objectManager->create('MagentoReportsModelResourceModelReportCollectionFactory');
            $collection = $productCollection->create('MagentoSalesModelResourceModelReportBestsellersCollection');

            $collection->setPeriod('month');

            $products = $collection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->setPageSize(10)
            ->load();


            foreach ($products as $product)
            print_r($product->getData());



            Don't use Object Manager instance directly check this for more details






            share|improve this answer















            try this way..



            using block class file



            <?php
            namespace VendorModuleBlock;

            class BestSeller extends MagentoFrameworkViewElementTemplate


            protected $_collectionFactory;
            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoSalesModelResourceModelReportBestsellersCollectionFactory $collectionFactory,
            array $data = []
            )

            $this->_collectionFactory = $collectionFactory;
            parent::__construct($context, $data);



            public function getBestSellerData()

            $bestsellers = $this->_collectionFactory->create()
            ->setModel('MagentoCatalogModelProduct')
            ->setPeriod('month');

            $collection = $bestsellers->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->load();

            return $collection;




            or using object manager



            <?php 
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $productCollection = $objectManager->create('MagentoReportsModelResourceModelReportCollectionFactory');
            $collection = $productCollection->create('MagentoSalesModelResourceModelReportBestsellersCollection');

            $collection->setPeriod('month');

            $products = $collection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->setPageSize(10)
            ->load();


            foreach ($products as $product)
            print_r($product->getData());



            Don't use Object Manager instance directly check this for more details







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 14 hours ago

























            answered 17 hours ago









            Rakesh DongaRakesh Donga

            2,368316




            2,368316












            • Let me know if you have any confusion for implementation.

              – Rakesh Donga
              14 hours ago

















            • Let me know if you have any confusion for implementation.

              – Rakesh Donga
              14 hours ago
















            Let me know if you have any confusion for implementation.

            – Rakesh Donga
            14 hours ago





            Let me know if you have any confusion for implementation.

            – Rakesh Donga
            14 hours ago

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268298%2fhow-to-get-only-configurable-products-as-a-bestseller-in-magento-2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form