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
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
add a comment |
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
Have you got solution?
– Chirag Patel
14 hours ago
@ChiragPatel, Not yet I have got error in addAttributeToFilter()
– Sanjay Gohil
14 hours ago
TryaddFilter('type_id', 'simple')
insted ofaddAttributeToFilter()
– Chirag Patel
13 hours ago
add a comment |
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
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
magento2.2.6 best-seller
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
TryaddFilter('type_id', 'simple')
insted ofaddAttributeToFilter()
– Chirag Patel
13 hours ago
add a comment |
Have you got solution?
– Chirag Patel
14 hours ago
@ChiragPatel, Not yet I have got error in addAttributeToFilter()
– Sanjay Gohil
14 hours ago
TryaddFilter('type_id', 'simple')
insted ofaddAttributeToFilter()
– 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
add a comment |
3 Answers
3
active
oldest
votes
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();
add a comment |
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!
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
add a comment |
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
Let me know if you have any confusion for implementation.
– Rakesh Donga
14 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
add a comment |
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();
add a comment |
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();
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();
answered 16 hours ago
Hassan Ali ShahzadHassan Ali Shahzad
655317
655317
add a comment |
add a comment |
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!
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
add a comment |
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!
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
add a comment |
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!
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!
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
add a comment |
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
add a comment |
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
Let me know if you have any confusion for implementation.
– Rakesh Donga
14 hours ago
add a comment |
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
Let me know if you have any confusion for implementation.
– Rakesh Donga
14 hours ago
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofaddAttributeToFilter()
– Chirag Patel
13 hours ago