![magento getdata select magento getdata select](https://image.slidesharecdn.com/cqrsandeventsourcingigor-180712184008/95/cqrs-and-eventsourcing-in-magento2-by-examples-of-msi-31-638.jpg)
$collection->setPageSize(50)->load() 4 – Set Limit Product Collection with Current Page $collection = $this->productCollectionFactory->create() $collection->setOrder('sku', 'DESC') 3 – Set Limit Product Collection $collection = $this->productCollectionFactory->create() $collection->getSelect->order('sku', 'DESC') $collection->setOrder('sku', 'ASC') 2 – Order by DESC $collection = $this->productCollectionFactory->create() Or $collection = $this->productCollectionFactory->create() $collection->getSelect->order('sku', 'ASC') 1 – Order by ASC $collection = $this->productCollectionFactory->create() Just like filters, there are multiple ways to sort your product collection. $collection->addAttributeToFilter('description', ) Sort Product Collection
![magento getdata select magento getdata select](https://i.stack.imgur.com/ShJt2.png)
$collection->addAttributeToFilter('description', ) 12 – Not NULL $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('entity_id', ]) 11 – NULL $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('entity_id', ]) 10 – Not in Array $collection = $this->productCollectionFactory->create()
![magento getdata select magento getdata select](https://i.stack.imgur.com/7nksc.png)
$collection->addAttributeToFilter('sku', ) 9 – In Array $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('sku', ) 8 – Not Like $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('price', ) 7 – Like $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('price', ) 6 – Less than Equal to $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('price', ) 5 – Less than $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('price', ) 4 – Greater than Equal to $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('status', ) 3 – Greater than $collection = $this->productCollectionFactory->create() $collection->addAttributeToFilter('status', ) 2 – Is Not Equal to $collection = $this->productCollectionFactory->create() 1 – Is Equal to $collection = $this->productCollectionFactory->create() Let’s look at each of them one by one below. There are multiple filters you can use for product collection. Return $collection Filter Product Collection $collection->addWebsiteFilter($websiteIds) Return $collection Get Product Collection by Website IDs $website_ids = Get Product Collection by Store ID $storeid = 1
#Magento getdata select code#
NOTE: Please change the code as per your requirement to getProductCollection() function.
![magento getdata select magento getdata select](https://aureatelabs.com/wp-content/uploads/How-to-create-a-custom-widget-in-magento-2-blog-banner-2000x654.jpg)
$collection = $this->productCollectionFactory->create() $this->categoryFactory = $categoryFactory Load Product Collection: productCollectionFactory = $productCollectionFactory In this tutorial, we are going to share the steps to get product collection with all of the above conditions. Now, you can get product collection details using many different conditions such as: This is because product collection is now often required in many different filters as well as requirements.įor those who don’t know, getting product collection in Magento 2 is simply means showing the items in your Magento 2 store when you run the command. The product collection is becoming more and more important in Magento 2.