Questions tagged [product-collection]

Questions related to Magento product collections.

197 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
15
votes
4answers
5k views

Magento 2 - Render custom product collection via list.phtml

The product grid of a category page (frontend) is rendered via layout in catalog_category_view.xml. Lets say I have a custom product collection (which I got via ProductRepositoryInterface::getList(...
12
votes
1answer
885 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
389 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
56 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
70 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
289 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
157 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
4k 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
24 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
22 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
26 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
269 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 ...
2
votes
1answer
38 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
41 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
1answer
577 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. ...
2
votes
1answer
206 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
298 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
125 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
543 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
400 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
599 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
252 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
750 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
116 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
642 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
1answer
39 views

How to get Product id from specific Product Catalog Rule?

I created a widget which is a display product section for a specific catalog price rule selected by admin. Ex: Admin select 20% off on pants from backend & '10' will be limit of displaying ...
1
vote
1answer
27 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
19 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
22 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
19 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
80 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
37 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
35 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
23 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
36 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
153 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
123 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
27 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
76 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
vote
1answer
250 views

Magento 1.9 - Product collection sort by price not working fine

This is my product collection. $collectionWithRank = Mage::getResourceModel('catalog/product_collection') ->addCategoryFilter($cat_data) ->addAttributeToSelect('*') ->...
1
vote
0answers
59 views

Magento 2 : Modify loaded product collection

Can we modify loaded product collection in list.phtml file ? And if it is achievable then how can we modify it ?
1
vote
1answer
173 views

Magento 2 collection loop issue

<?php try { require __DIR__ . '/app/bootstrap.php'; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; exit(1); } $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $...
1
vote
1answer
37 views

Magento 1.9 collection multi conditions

I read many posts and articles but still didn't find a solution. I would like to filter my product collection with this condition: ... WHERE ('supplier_id' = 1 AND 'product_type' = 'first_type') ...
1
vote
1answer
410 views

How to get related product collection in block

I use this way to get related product collection /** * Prepare and return product collection * * @return \Magento\Catalog\Model\ResourceModel\Product\Collection */ public function ...
1
vote
0answers
15 views

Can we show different add-ons and upsell product in per website by passing the same SKU?

Currently if we add upsell/add-on products to default it wont let you to change it on each store view. All the upsell and add-ons will be the exact same as default. Is it possible to change upsell/...
1
vote
1answer
462 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 ...
1
vote
2answers
322 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\...