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.

2
votes
1answer
14 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
24 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
25 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
23 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
22 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
17 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
18 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
22 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
24 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
19 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
28 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
18 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
40 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
23 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
28 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
19 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
15 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 ...
1
vote
1answer
29 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
31 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
49 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
20 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('...
1
vote
0answers
37 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
15 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
22 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
22 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
56 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
29 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
42 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
35 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
22 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
224 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
12 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
28 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
417 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
56 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
30 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
55 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
36 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 ...
2
votes
2answers
437 views

Filter on custom product collection

I'm creating a custom brand page in which are listed product with a specific brand. I've created a static page with a 2 column layout, with a left sidebar in which I'm putting filters and the main ...
0
votes
0answers
15 views

Unable to retrieve collection of products using custom text attribute with specific value

On Magento 1.9.3.8 I am trying to retrieve a list of products in cms page that have a specific value in a custom text attribute "group" but for some reason, I get error, "There are no products ...
0
votes
1answer
55 views

How to get ordered quantity from product?

I'm trying to get the ordered quantity from my catalog/product collection, but I'm having this error: Call to undefined method Mage_Catalog_Model_Resource_Product_Collection::addOrderedQty() Here ...
0
votes
2answers
58 views

addFieldtofilter array not reading

I am trying to filter product collection by ids if I use below code, the filter works ok and the product shows. $this->_productCollection ->addFieldToFilter('entity_id',array('in'=&...
2
votes
1answer
28 views

Group and apply 'LIKE' filters to product collection (x AND y AND …) OR (z AND a …)

How to filter product collection as follows WHERE (`att1` LIKE '%val1%' AND `att1` LIKE '%val2%') OR (`att2` LIKE '%val1%' AND `att2` LIKE '%val2%') the number of 'LIKE' statements inside groups ...
0
votes
0answers
11 views

How to display design of product list page on custom page in Magento 2?

I have created a custom phtml file. Now I want to display my collection in same design of product list page. Can anyone help me in this. I am new to design in magento 2.
0
votes
0answers
19 views

Two Product Blocks displaying same result

I have to display new products and featured products on the homepage so I have created two different blocks for this and getting product collection as follows. use Magento\Catalog\Api\...
0
votes
0answers
37 views

Magento 2.2.3 :: ProductCollection Filtering does not work when FPC is enabled

I have a Magento 2.2.3 vehicle parts site which the finished product should allow users to select their vehicle from a dropdown, and then their selected vehicle be stored in a Magento cookie. Then, my ...
1
vote
1answer
78 views

Magento 2.2.3 :: How to check if ProductCollection exists?

Here is my problem: I have a vehicle parts site which lets user select their specific model and be saved via a cookie. Then the whole site will be filtered via my module plugin, where I override “...
0
votes
0answers
18 views

Magento2: What's the right/best way to override the getProductsCollection() on category pages?

My goal: I want to create a special category that will display products by different rules (not by associated products), for example: 'products on sale' / 'new products' / 'products from multiple ...
0
votes
1answer
151 views

Why Magento 2.2.3 returns empty collection?

I don't have any prior experience in this. I want to fetch the products from Database. I am trying from past few hours.But not working. I am using following code. protected $...