Questions tagged [product-collection]

Questions related to Magento product collections.

216 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
12
votes
1answer
946 views

Magento2 Custom Layered Navigation

I want to add a layered navigation block for a custom product collection. Is there a way to do that in Magento2 ?
5
votes
0answers
2k views

Proper way to get product collection with store specific values in admin area

For a custom indexer, I need to load a product collection with the attribute values for a given store, while not in a store context. As it has been established in Magento 2: How to Filter a Product ...
4
votes
3answers
2k views

Add Filter to magento 2 category product collection

a similar problem. If i want filter product collection, create plugin for Layer (if use event the result will be the same). The collection is correct and show only 2 products. But the Pagination ...
4
votes
2answers
419 views

Magento getting store bestsellers: configurable products, only from current store

Magento getting store bestsellers: configurable products, only from current store We have tested some bestseller codes like from here and here and here. They all work fine if you only sell simple ...
3
votes
0answers
63 views

List Product Collection into template file in Magento 2

I am loading the Product Collection by calling the ajax request. Here is my code of template file. $('#modifyRecentAddSkus1').on('click',function(){ var skus = $('#skus1').val(); ...
3
votes
2answers
77 views

collection, get product image

Sorry for my English I have this code $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('short_description') ->...
3
votes
1answer
693 views

Magento 2 - How get extension attributes from product collection

I need to get the product collection with all extension attributes, specifically I need then to get the stockItem object with $product->getExtensionAttributes()->getStockItem(). So I have ...
3
votes
1answer
499 views

Product collection sorting broken in Magento 2.3?

I am trying to sort by price on a product collection query, however, it seems sorting by price is reducing the result set to 0... Here is a working query which returns expected number of products (...
3
votes
0answers
159 views

Show all products with layered navigation Magento 2

Now, to be able to show all the products, I have to make 1 main parent category to contain all the product category, but I think it's not the right thing to do. Is there a page to show all the ...
3
votes
4answers
5k views

Get all product information

How to display all Product Information in particular Attribute set like Product name , sku , attributes etc.. It shows Attribute Name & Id but i want all details like Product name , sku , ...
2
votes
0answers
29 views

Magento2 filter products based on location (custom attribute) programmatically

I have a Magento2 Store (v2.4) where I have multiple locations. for (eg. Jaipur, Delhi, Mumbai etc). I have managed locations using custom attribute using multiple dropdown list and assigned it to ...
2
votes
0answers
42 views

How to cache a product collection in Magento 2?

Currently i load a product collection under certain categories, for example: $collection->addCategoriesFilter(array('in' => array('2','4'))); $collection ->addMinimalPrice() ...
2
votes
0answers
25 views

Get all associated categories from product collection

For a custom filter on the product collection i need to be able to get all associated categories from all products from the catalog search result. On top of that, i do not need the actual categories ...
2
votes
0answers
29 views

Magento2: How to implement simple Ajax demo for Product Collection?

I want to display product using ajax method on button click same page. How is it possible in Magento?
2
votes
1answer
35 views

Magento2: unable to override methods in Magento\Catalog\Model\ResourceModel\Product\Collection

I want to override the model class(Magento\Catalog\Model\ResourceModel\Product\Collection.php) Flow the below process to override the addUrlRewrite method but not working. di.xml <config xmlns:...
2
votes
0answers
30 views

Select logic changed with latest versions - product resource collection

While performing an upgrade of a Magento 1 shop, noticed a change in core class Mage_Catalog_Model_Resource_Product_Collection, within method _initSelect The change that has happened is, that ...
2
votes
1answer
109 views

Most viewed products by category not working

I want to add some automated products to the related products and had this working great however suddenly it has become stuck showing the same products. I have used a category Id that I put in the ...
2
votes
0answers
47 views

Products do not appear on list page in magento 2?

I am working on a project where I need to display the list products on list page. I have added the products on local server where I am getting them on front-end. But when I create products on live ...
2
votes
2answers
546 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
1k 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/...
2
votes
1answer
262 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 = $...
2
votes
0answers
373 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', ...
2
votes
0answers
597 views

How to change the category collection before load?

I'm trying to figure out how to change the category collection before load. To be more specific, I've created a category 'Sales'. The category is empty with no products. I want to automatically add ...
2
votes
0answers
134 views

Correct way to use an array of SKUs to filter collection results in M2

Working with Magento EE v2.1.7. I have an arbitrary array of SKUs that I wish to use to filter the products I'm returning on all category pages. I've created a custom module to generate this array ...
2
votes
0answers
731 views

Refresh cached product images programmatically

After flushing image cache, cached product images are rebuild when they are loaded from frontend like from product view page ... I need them restored w/o vistit every page manuall, so how to this in ...
2
votes
0answers
457 views

Magento2: Override Vendor Resource Model _afterLoad method

I am trying to override the _afterLoad methods of the vendor class Magento\Catalog\Model\ResourceModel\Product\Collection unsuccessfully. In my custom module I edited the di.xml in this way <?xml ...
2
votes
0answers
656 views

catalog search result default sortBy by multiple attributes at once

I want to sort my catalog search result by multiple attributes. For default sorting by price I have added below code in xml file : ... <catalogsearch_result_index> <reference name="...
2
votes
0answers
257 views

Filter product collection to include only one parent configurable product

So I'm trying to build a 'Bestseller list' on our homepage. Currently the bestseller list is only showing the top selling simple products. All these simple products are child products of different ...
2
votes
0answers
800 views

Trouble adding filter to product collection via observer

My goal is to filter the category product list by product's first letter. This works on my staging site by implementing the following: /app/code/local/Etre/Alphapagination/etc/config.xml <...
2
votes
0answers
117 views

Trouble fetching current product collection for category without limit

Within my templates category list.phtml I need to pull the full product collection without the page limit. To be clear I do not want to impact the toolbar, pagination, or anything else within category ...
2
votes
1answer
643 views

Upsell Products not visible if it's category and products category are different

Hi i'm having below categories Camera - DSLR - Digital Camers Accessories - Lenses - Memory cards I've added a product from lenses category as a upsell to a product from Digital cameras. but it'...
1
vote
0answers
32 views

Get compare product collection on CMS, Catalog Pages

I have used the below code but that is not working on catalog, cms & product page for me. but for compare page, cart page, and checkout page it's working. $objectManager = \Magento\Framework\...
1
vote
1answer
56 views

Magento 2: Product collection filter with custom attributes with like

I am using magento 2.3.3 i have custom module in that i am using search when any one search i am filter products name like it is working fine but now i want add extra attributes.I have created product ...
1
vote
0answers
24 views

How to get product id's of first page in the second page in magento 2 plp

I need to get first page product id's while calling second page collection in ListProduct.php
1
vote
1answer
27 views

For each Loop Not Print Proper Data

On product listing page I have $_productCollection = $block->getLoadedProductCollection(); if I call getData on $_productCollection I get different array than I get in foreach loop. Does anyone ...
1
vote
1answer
129 views

Magento 2: Filter Product Collection using Category Id always return empty set

I have a parent category with subcateogry that contains a lot of product in it, when i tried to filter the product collection using this parent category id, it always return an empty collection: ...
1
vote
0answers
148 views

Magento 2: How to get related product custom option using graphQl?

I want to get related products with custom option data using GraphQl. I am using the below GraphQl query to get related product custom options data. can anyone help with this? { products(filter: {...
1
vote
1answer
77 views

Magento2: What is difference between ProductFactory and CollectionFactory?

What is the difference between this below code? Class : \Magento\Catalog\Model\ProductFactory Code : $this->productFactory->create()->getCollection(); Class : \Magento\Catalog\...
1
vote
0answers
24 views

Magento 2 collection filter need advies

We have grouped products - rims. Now we want to sell it with tires. Logical is to look up for needed tires and show them, although the problem is if we do that we get results for front and back. but ...
1
vote
0answers
39 views

Magento 2 : Frontend load ajax page custom product collection with search set total items

Facing issue with frontend load ajax page custom product collection with search set total items 1 in Magento 2.
1
vote
0answers
32 views

Join attribute lable in product collection

I'm creating one grid which will have to below columns like SKU,Name and Color (Attribute) So to achieve this We've to join color data to collection for that I've added _initSelect to collection ...
1
vote
2answers
204 views

Some added products in cross sells not visible in frontend Magento 2

I have added few products in cross-sells but some are visible and some are not visible in the UI(frontend). I referred to a Magento bug that only 2 items were visible in the backend https://github....
1
vote
0answers
80 views

How i can work with extension attributes using collection?

Hello i have to add extension attributes to Magento\Catalog\Api\Data\ProductInterface So i added this one to extension_attrributes.xml: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
1
vote
0answers
50 views

Get data from eav instead of flat table

I am trying to get product collection programmatically and product flat table structure is enabled. I don't want to disable product flat table, this will hurt frontend performance. Just for my script ...
1
vote
1answer
24 views

When I use “echo” in vendor methods - products not showing, but work fine without it

I got the next code: public function getProductCollection() { if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) { $collection = $this->...
1
vote
0answers
46 views

Magento 2 Product Collection add array as column for sorting

I've requirement like following. Products price is calculated on the fly and I want price sorting to be proper with it. I've extend the block Magento\Catalog\Block\Product\ListProduct Following is ...
1
vote
0answers
399 views

Magento 2: How to add multiple AND conditions to one single attribute that could be used to join other condition groups?

I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes: $collection->addAttributeToFilter('...
1
vote
0answers
385 views

Magento 2 Add product to product collection

currently i'm working on an extension which show the last products which sold the last 10 day. I got this products with the \Magento\Reports\Model\ResourceModel\Product\Sold\Collection. Vender/Name/...
1
vote
0answers
28 views

Get Top Rated Products and Order by rating

I want to get Top Rated Products collection and sort it by ratings. I'm using the code but not working. $collection->getSelect()->joinLeft( '...
1
vote
0answers
228 views

Sort by Each Price Magento 2 via \Zend_DB_expr

I've had this working previously however seems to be causing me some difficulty now, basically i have a unit of sale attribute that I am using to get an each price from the sale price: if ($...

1
2 3 4 5