Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions related to Magento product collections.

1
vote
1answer
17 views

Magento 2, filter product collection by sku while preserving the given array sequence

Using below code, collection is filtered. If $productSkus array is like Array ( [0] => 5714156000153 [1] => 8690604469871 [2] => 6412616365413 ) after filtering I see the collection is in ...
2
votes
1answer
24 views

Show only products on a new category page which have a certain product attribute enabled

I want to create a new category page which shows all products which have a certain product attribute (speed_delivery) set to yes. I was thinking about to create an empty category, catch its product ...
0
votes
0answers
16 views

Magento 2 - Apply filter on Product collection

Is there any common event or plugin to apply the filter to product collection which includes product list page, related products list as well as upsell and cross-sell product list? If no, then how ...
0
votes
1answer
32 views

Products Collections not loading using block in cms magento 2?

app\code\Namespace\Module\Block <?php namespace Namespace\Module\Block; class Catproduct extends \Magento\Framework\View\Element\Template { protected $_storeManager; ...
0
votes
1answer
32 views

Collection get items return null

I tried to get all products sku, that started at $params['sku'] My controller: <?php namespace Aty\TestTask\Controller\Index; use Magento\Framework\App\Action\Context; class GetProductAjax ...
0
votes
3answers
44 views

How to prevent memory consumption during collection enumeration?

In the following script: $pageSize = 1000; $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addWebsiteFilter($website->getId()) ->...
0
votes
1answer
15 views

Magento 2 Get product collection filter by atributes does not give the exact match

I have created a filter to get product bellow is an examples: $filter = array( array('attribute' => 'color', 'eq' => '2'),//id of option array('attribute' => 'size', 'eq' => '5'),// ...
0
votes
0answers
29 views

Magento 2.2 - Layer navigation with custom product collection not working

I want custom product collection with layer navigation in custom page. I have checked many links already and followed with below link, Layered navigation for custom collection on custom page - ...
0
votes
1answer
36 views

Magento 2 Join Product Collection with Custom CollectionFactory

In Magento 2.2.5, I have Custom Model Collection (followed this tutorial). In that I want to add the Product Collection into this custom collection by default. How to achieve this.
0
votes
1answer
61 views

M2 Include disabled products in product list widget collection

I'm not sure if this is an m2 2.2 bug or just due the way I'm trying to filter the collection, but I can't seem to include disabled products in my product list collection. I've tried a few different ...
1
vote
2answers
16 views

Magento 2: Get disabled products for a category in a collection programatically

I want to get disabled products for a category in product collection programatically in Magento 2.2.5. I am using following code: public function __construct( \Magento\Catalog\Api\...
2
votes
1answer
23 views

visibility attribute value is not rendering from product collection in magento 2

We need to display the visibility of the product in category page, but currently we are not able to fetch its value from product object. We tried with $_attributeLabel = $_product->getResource()-&...
1
vote
2answers
54 views

How to Shuffle Product Collection in Magento 2?

I am getting products collection form multiple categories. I want to shuffle products everytime when function getProductCollection() is called. My function is: public function getProductCollection($...
1
vote
1answer
52 views

Magento2: How to get product collection which cart rules apply on this?

I have added cart rules on some product. I want to display the message on the free product which has rules applied. How to get product collection which cart rules apply on this? My Magento version ...
4
votes
1answer
26 views

Is it possible in Magento 2 to load content in between products?

I'm wondering if it is possible at all to load some content (different per page) in between the product collection. I've made a module injecting some content that I enter in the backend, but obviously ...
1
vote
0answers
38 views

While sorting my product collection automatically shuffeling

For Magento 2.2 I'm using:- $categoryId=185; $ct = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); $collections = $ct->getProductCollection() ...
2
votes
1answer
29 views

Group Collection to Filter Unique Products Based on a Specific Attribute

Scenario: A store catalog is populated with configurable products each having several children with different sizes and colors. As the goal is to show the different color variations, only the ...
2
votes
1answer
33 views

How to get product collection with both in stock and out of stock products in Magento 2.1

I'm using below code to get the product collection <?php namespace Vendor\Module\Block\Product; use Magento\Framework\View\Element\Template; use Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
97 views

Show all products on one page in Magento 2

I need a page where all products should be displayed. All products from all categories, also including filters by attributes. I have tried to use the following block {{block type="catalog/...
0
votes
2answers
41 views

Magento2: How to get product collection by parent-category-id and sub-category-id?

How to get product by parent-category-id and sub-category-id? Magento 2.0
0
votes
1answer
23 views

Can I call addFieldToFilter via di.xml? / Set a global filter on product collection

I am working with vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php which extends the \Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
44 views

In Magento 2.2.5 load product by id is not working

In Magento 2.2.5 load product by id is not working. I tried the below solutions: Sol 1: $product_id=20; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $...
0
votes
2answers
19 views

how to remove white space from product name during custom product collection?

I am getting stuck with white space in set order during product collection in magento 2. I want to get product details with ascending order via name but name has white space. I have removed white ...
0
votes
0answers
104 views

Magento 2 : collection filter error : Exception #0 (RuntimeException): Illegal state

I am having problem with collection filter I am using event catalog_product_collection_apply_limitations_after to add collection limitations In the observer i am using below code to apply filter. ...
0
votes
1answer
38 views

Get collection of filtered products (layered navigation)

I am trying to get a collection of products according to filters applied in layered navigation. I thought, that layer model's getProductCollection will do it for me, but as long as i see, it ...
2
votes
1answer
54 views

Product Collection Factory not returning products that are Not Visible Individually

Using the below code or equivelant I want to get all products regardless of visiblity or status etc. This however does not seem to return products that are "Not Visible Individually". $category = $...
0
votes
0answers
23 views

what is feasible getCollection with product_id filter or load for getting attribute values in magento 2

I can get product-data (like an attribute) via the load() method, but I would like to do the same thing, only filtering the collection with product_id like addFieldToFilter() and using ...
0
votes
0answers
31 views

Magento 2 how to run reindex for single product or some cart line products

Is there any way in magento to achieve to reindex only single product or some items. I have a inventory existing /update call on product page load and cart page load. Right now doing indexing for ...
2
votes
1answer
113 views

Magento 2 : Is there a way to query products using Custom Attributes in Rest API Call?

I have a custom attribute setup for Books called isbn_13 Now I try to find the products using the isbn_13 values but unable to filter the results based on this. Is there any way to do this? Update: ...
0
votes
0answers
37 views

Calling getCollection in phtml is empty

In Magento 2.2.5, I am setting the Block for phtml using below code: <?xml version="1.0" encoding="UTF-8"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" ...
0
votes
1answer
68 views

Magento 2.2.5 get the product collection without Stock data

I am using Magento 2.2.5. In that, I am creating the products using the below code. $product = $this->objectManager->create ( 'Magento\Catalog\Model\Product' )->load ( $productId ); $product-...
1
vote
1answer
22 views

How do I update products without resetting attributes to default values

I have a script that updates stock and price but it seems to save all attributes with a default value back to the default. The collection is loaded like this: $productsCollection = Mage::getModel('...
2
votes
0answers
55 views

What is the use of load() method in collection?

CASE productCollectionFactory load function gives data in query but not in object $collection = $this->_productCollectionFactory->create() ->addAttributeToFilter('status', ...
1
vote
0answers
22 views

productCollectionFactory load function gives data in query but not in object

I have created a collection factory $collection = $this->_productCollectionFactory->create() ->addAttributeToFilter('status', '1') ->addAttributeToFilter('featured'...
1
vote
0answers
23 views

Not getting Specific field value using Get method even its exists in collection and also in collection getData magento 2

This is my code: $collection = $this->_productCollectionFactory->create() $collection->addAttributeToSelect('*')->load(); I am Not getting Specific field value using Get method even its ...
0
votes
1answer
25 views

Load catalog displaying values from 2 stores at the same time

I searched for a similar question, but didn't find any suitable answer. I have a multi-store Magento and I simply want to load my catalog seeing some attributes values of the admin/global store view ...
0
votes
1answer
116 views

Custom sort order for loaded collection?

I have a product collection created by Magento for the category product list. I then pass some information about this collection to an external method that returns the entity IDs in a specific sort ...
0
votes
0answers
60 views

Override Toolbar.php having issue for catalog page magento2

I have done the following: registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, '...
2
votes
2answers
60 views

Add group prices to product collections

Is there a method to add group prices (for one or more customer groups) to product collections? Actually I have this ... /** @var Mage_Catalog_Model_Resource_Product_Collection $products */ $...
0
votes
0answers
49 views

Two categories are loading every available product in category

Most of my categories are working fine and only loading 12 products per page. Two of my categories are loading in every product assigned to those categories causing a very high page load time. The ...
0
votes
0answers
7 views

Magento get a product collection in an arbitrary order for Product List Page for default sort order in Magento2

I want to show default product list page with my arbitrary entity_id for products, Like the default collection will show with entity_id 3,15,9,12,6 etc as the default product is sorted by Name.
1
vote
0answers
25 views

Magento 2: Custom product collection with layered navigation [duplicate]

How can we load custom product collection with layered navigation? Same like search result page but with custom product collection. I have checked here Magento 2 - Layered Navigation for Custom ...
2
votes
3answers
393 views

Incorrect product count in layered navigation after overriding list product collection

I have customized(override) product list collection getProductCollection and filtered collection as required. public function getProductCollection() { if (isset($this->...
0
votes
0answers
14 views

Filter _productCollection of complete website from home page

I am creating a small extension with a basic purpose. Filter products based on custom attribute based on user input in a pop-up. I am able to do this on the product page, ListProduct ( category page ...
1
vote
1answer
34 views

What is the role of the `load()` method in the collection class?

In Magento\Framework\Data\Collection there is a method getFirstItem which calls $this->load() public function getFirstItem() { $this->load(); ...} load method from the same class: /** * ...
1
vote
2answers
747 views

Magento 2 Filter Product Collection by Multiple Attributes

In Magento 2.2.2, How Can Filter Product Collection by Multiple Attributes. I have the attribute_code with array values. attribute_code: my_attribute_code attribute_code values: Array ( [0] =>...
0
votes
0answers
59 views

Magento more than 61 product attribute database tables in join query

I'm using product feed extension and when I try to generate feed It throws me below error SQLSTATE [HY000]: General error: 1116 Too many tables; MySQL can only use 61 tables in a join, query was: ...
0
votes
0answers
34 views

Filter category products

I'm trying to filter the category page to show only products with images, just like this. but it seems nearly impossible because there's no real collection but instead it maps to the Magento\...
0
votes
2answers
93 views

Magento 2.2 - Load eav attribute data for every product on collection load

I've created a multiselect custom eav attribute based on a flat table, so I used a dataSource, for a product everything is working fine, API (SOAP & REST), display on the product page etc but I'd ...
0
votes
1answer
93 views

How to get quantity of products sold?

I need to get the quantity of products sold on my report module. Actually I'm only getting the ordered quantity, but I need to get the quantity of all finished orders. Here is my actual code: public ...