Skip to main content

Questions tagged [product-collection]

Questions related to Magento product collections.

Filter by
Sorted by
Tagged with
0 votes
1 answer
20 views

Magento 2 - How to filter on multiselect product attribute with AND condition

I have two custom product attributes. both attribute type is Multiselect. I want a product collection using a filter of both attributes. I have tried with below solution but it not working. $...
Meet's user avatar
  • 25
0 votes
1 answer
35 views

Magento 2 override product list page collection

I am trying to override the product collection of the product list page (category page). (Just for testing locally) I am editing the vendor/magento/module-catalog/Block/Product/ListProduct.php file ...
sulman's user avatar
  • 529
0 votes
0 answers
31 views

Magento 2: Add Product Attribute Filters on Magento 2 Custom Product Collection [duplicate]

I've a custom product collection displayed on a custom page. This part is working fine. Now I want to add the product attribute filter on that page to provide customers to filter the products based on ...
Sumit's user avatar
  • 4,930
0 votes
0 answers
18 views

Filter Product Collection while Using FPC

I'm working on a project right now with about 200k customers that are broken down into 2000 groups. We haven't used customer_group for this because of the large number. But because we have a ...
Gaurav Agrawal's user avatar
0 votes
1 answer
31 views

magento 2 new categroy product missing in category page

I am using magento 2.4.4.p1 upgrade from 2.3 to 2.4.4-p1 i have some products in my site in that few are disabled few are enabled after upgradation i am trying to enable one product it enable but not ...
pavan kumarexinent's user avatar
0 votes
0 answers
24 views

Magento2 product collection returning empty value instead of 0 (zeros)

I built my own product collection which I use for my own shop dashboard. What it should do is for each selected product to go through the last 13 months and show me the amount that was sold. ... ...
TheFrakes's user avatar
  • 347
0 votes
0 answers
15 views

Product list filter by custom attribute

In the code that I'm working has a filter by a custom attribute. When the value is true the product must disappear but there is a bug. When I go to a Product list page (grid) and there is a product ...
Camilo Torres's user avatar
3 votes
0 answers
208 views

Update layer navigation filter with the proper custom collection

Goal : Create a /test/index/index route that will load a product listing page with a custom collection. Expectation : The custom collection printed in listing and the filters must be properly defined ...
Claims's user avatar
  • 1,211
0 votes
0 answers
21 views

Apply a custom collection to the layered navigation filter

By extending Magento\Catalog\Block\Product\ListProduct; and replacing in the layout by my custom block I have been able to apply and load a custom collection in any category. The issue is that the ...
Claims's user avatar
  • 1,211
0 votes
1 answer
567 views

How to load a custom product collection in frontend using smile elasticsuite

Everything is in the question i need to load a custom product collection in frontend using smile elasticsuite. But i can't figure out how to do it. Do you guys have a working example ? "smile/...
Claims's user avatar
  • 1,211
1 vote
1 answer
54 views

How to get product collection unmatch product ids with custom collection ids in magento 2?

I want to get the unmatched product ids of catalog products with a custom module collection product ids. For Example : The catalog product entity table has 12,14,15,16 product ids The custom table ...
Jitendra Patel's user avatar
0 votes
1 answer
121 views

Product Collection Methods: addFieldToSelect() vs. addAttributeSelect()

What is the difference between ->addFieldToSelect('name') and ->addAttributeToSelect('name')?
A. Andersen's user avatar
3 votes
1 answer
638 views

How to get product collection without special price and tier price?

I'm using Magento v2.4, i want to retrieve a product collection that does not have special price (special price is not active or null) and tier price, currently i load the product collection like this:...
blue's user avatar
  • 128
1 vote
0 answers
291 views

How do I include the stock item with the product collection

In magento-1.9 I would call $Products = Mage::getResourceModel('catalog/product_collection'); $products->setFlag('require_stock_items', true); And this would add the StockItem to every product in ...
Richard's user avatar
  • 1,724
0 votes
1 answer
39 views

How to get all Products of all Websites/Stores?

I tried getting all products of all websites via the ProductCollection like this: $stores = $this->storeManager->getStores(); foreach ($stores as $store) { try { ...
Max's user avatar
  • 17
0 votes
0 answers
113 views

How to get child products from Layer Class Magento 2

14219 is the ID of the parent product. 14217, 14218 are the child product ids, I need to get from the Layer which products visibility is VISIBILITY_NOT_VISIBLE , can anyone help? Thanks class Layer ...
Robinio's user avatar
  • 771
1 vote
0 answers
105 views

How to add category filter with OR condition in product collection?

I'm using magento v2.4.1 and i have a custom attribute name landmark, and i want to filter a product collection using landmark attribute and category id using OR condition. Currently i'm doing it like ...
jojo's user avatar
  • 39
2 votes
1 answer
2k views

How to get product collection along with is saleable attribute in Magento 2?

I'm using magento v2.4.1 and I'm extending \Magento\Catalog\Block\Product\ListProduct in my custom module block to load a custom product collection like this: protected function _getProductCollection()...
jojo's user avatar
  • 39
0 votes
0 answers
107 views

Magento 2 - Get random results with Elasticsuit Catalog Fulltext Product Collection

I am using a Magesuite module to get a product collection, and among other things I want to randomly select a certain number of products, fitting of course some criteria set with filters. The ...
Noob Doob's user avatar
  • 127
0 votes
1 answer
241 views

Magento 2 : Get option name rather option id in product collection

Hi I am using below product collection,but it returns option id of attribute in collection my question is how to get option label rather than option id in collection. Is there any way ? Because I am ...
Niraj Patel's user avatar
0 votes
1 answer
534 views

Magento 2 Product grid collection filtering on programmatic Qty column values

I am programatically updating the qty column values for configurable products. Sadly, the grid filter for this column doesn't work with new values. The underlying catalog product collection joins with ...
Johny Boy's user avatar
1 vote
2 answers
826 views

Filter product collection for only products that have the image

I need to remove products from the collection that have no image. Even if they have the placeholder image I want them to be invisible. The module code I use is this <?php namespace Smartwave\...
yavonz15's user avatar
  • 417
4 votes
1 answer
3k views

Custom condition for Elastic search collection in Magento 2

I am trying to add the custom condition for the product collection using the below plugin for elastic search. app/code/Vendor/Module/etc/frontend/di.xml <type name="Magento\Elasticsearch7\...
Manjunath's user avatar
  • 177
1 vote
2 answers
522 views

How to Get Most Viewed Product Collection in Magento 2?

how to get the most viewed product collection in your Magento 2 store? I try with multiple codes but unfortunately, I am not getting any solution. I try to create a MostViewedProducts.php file in the /...
Kuldeep Sharma's user avatar
0 votes
0 answers
640 views

Magento 2.3.2 sort the product collection by attributes

I want to sort the product collection by attributes. I want to apply multiple sorting to the product collection need to sort by NEW, ONSALE, and POSITION For example when going to any listing page ...
Chirag Patel's user avatar
  • 6,156
0 votes
1 answer
399 views

Magento2 Add Custom Sort By Option ( Special Price Low - High)

I Want to Add New Sort By Option Like (Special Price From Low To High). Does any one know how i can do this ?
Sanjay Shiyal's user avatar
0 votes
1 answer
525 views

Magento 2 CategoryFactory exclude current product from collection

I am using an extension auto-selecting related products from the same category. However, I want to exclude the current product from that list which is not really working. protected $_categoryFactory; ...
cookie monster 24534's user avatar
1 vote
1 answer
445 views

Magento2 Product Collection Observer only changes one page at a time

In ListProduct block Magento is using initializeProductCollection() to initialize the collection. While initializing it dispatches event catalog_block_product_list_collection as follows. $this->...
Richard Parnaby-King's user avatar
1 vote
2 answers
2k views

How do I get all products that are displayed on a page?

I am trying to get all the products which are displayed on the current page. The information is used for tracking cookies on the page.ready call. It was possible to get the product from the product ...
Max's user avatar
  • 17
0 votes
2 answers
2k views

How to merge two product collections in Magento2

I need help because I need to combine data from two subjects into one. I have configurable products. I want to download related and upsell products from "parent" and "child". In ...
bambo's user avatar
  • 3
0 votes
2 answers
916 views

How to get all products with attribute data in custom created class

I'm pretty new to Magento, and I are trying to create a module for it, but I'm a little stock now because I'm trying to get all products out there are created in the store there are enabled. I'm ...
ParisNakitaKejser's user avatar
0 votes
1 answer
345 views

How to create product name dynamically?

My product names are created by different values, that are stored in several custom modules. In my list.phtml I create the dynamic product names, that's no problem. But as I want, that the product ...
Dr. Christian Kusche's user avatar
0 votes
1 answer
179 views

How to get custom product attribute from productCollection

I use magento 2.4. I have product collection in catalog view. There I have loop: $_productCollection = $block->getLoadedProductCollection(); . . . <?php /** @var $_product \...
user2217288's user avatar
0 votes
1 answer
149 views

Get the average price for product collection

If there's a way in Magento 2 to get the average price for a product collection. Or should I loop over the collection? Thanks
AboElnouR's user avatar
  • 213
0 votes
1 answer
106 views

Magento 2: After product collection join getting Allowed memory size exhausted error

I am trying to join "catalog_category_product" table custom column to product collection like this, public function beforeSetCollection( \Magento\Catalog\Block\Product\ProductList\...
Pratik Dhamane's user avatar
0 votes
2 answers
870 views

How to filter product collection in such way where I can use having and addfiledtofilter with AND condition?

I am having product collection where I am getting one custom product attribute called "keep_disabled" and another column which was added on runtime which is sum of quantities 'sum_qty'. I ...
Gaurav Harsh's user avatar
3 votes
2 answers
421 views

Syntax error or access violation: 1064 issue , Magento 2

if news_to_date is empty i get syntax error, how can i check if news_to_date is empty or not? Code below, thanks \Magento\Framework\Stdlib\DateTime\DateTime $stdlibDateTime, $currentTime = $this->...
Rub Hayrapetyan's user avatar
0 votes
1 answer
259 views

Magento 2: addAttributeToFilter not working when filtering by ID

Exception #0 (Magento\Framework\Exception\LocalizedException): The "id" attribute name is invalid. Reset the name and try again. Here is my code ... \Magento\Catalog\Model\ResourceModel\...
Robinio's user avatar
  • 771
0 votes
1 answer
1k views

Product collection override but filter not magento in Magento 2.4

I have override vendor/magento/module-catalog/Model/Layer.php for custom product collection but now the layer navigation and product count is working wrong, I checked for Magento\CatalogSearch\Model\...
Yogita's user avatar
  • 784
0 votes
1 answer
662 views

Magento 2 : Add custom field in product collection

How to add custom field in product collection? I want to add discount value field in product collection. When I print product collection, it's output like this : [0] => Array ( [...
Niket's user avatar
  • 157
1 vote
1 answer
768 views

Magento 2 Remove configurable products from product listing page programatically

I am trying to remove configurable products from product collection, as a result products are being filtered correctly but pagination is not working as expected and showing wrong count. For example ...
DEEP JOSHI's user avatar
0 votes
1 answer
176 views

Magento2 Out of Stock Products are not display in category page

i have setup my site on magento 241 and out of stock products are not showing on category page, but it is showing on homepage widget section. i also set display out of stock product options = yes from ...
Sanjay Shiyal's user avatar
0 votes
1 answer
302 views

Optimize Product Collection Filter

I have a Model in my code that creates a custom product collection based on a user search term. That search term should search products and filter it by sku or name... The issue is that it takes too ...
Ricardo M's user avatar
  • 126
0 votes
1 answer
370 views

Magento 2 : Trying to Override ListProduct.php Block File for Custom Product Collection

I am trying to override ListProduct.php Block File Using Preference method But InitialiseProductCollection() being a protected function does not give me result. I need to know how can I override a ...
ravi singh chouhan's user avatar
0 votes
1 answer
38 views

Unique Products in Product Collection Filtered with Category Array in Magento 1.9

I have tried below 3 method but it is not giving correct products as per cateory id array. First Way $_productCollection = Mage::getResourceModel('catalog/product_collection') ->...
Yogita's user avatar
  • 784
2 votes
0 answers
402 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 ...
Abhishek's user avatar
  • 131
1 vote
1 answer
512 views

Adding category filter to loaded product collection?

Magento 2.3.3 This is my code: $_productCollection = $block->getLoadedProductCollection(); $values = [66]; $conditionType = "in"; $_productCollection->addCategoriesFilter([$...
EOB's user avatar
  • 265
0 votes
1 answer
2k views

Magento2: filter product collection by custom attribute

I am using Magento ver. 2.3.6. I want to filter product collection by custom product attribute and I am using below code:- di.xml <?xml version="1.0"?> <config xmlns:xsi="http:/...
Purushotam Sharma's user avatar
0 votes
2 answers
51 views

How to show related products Magento 2.3.5

I want to show related products on product page only from my custom module. I am not sure if I can or is it possible to do it. I am doing a check by if my attribute is enable I will change the outcome ...
Jack Brooks's user avatar
0 votes
1 answer
169 views

Why my Disabled product collection gives empty array in magento 2?

I want to get disabled product id's in my system but it gives me an empty array. Here is screenshot of my products.When i grab disabled product by using this code $updatedproids = []; $...
Prits's user avatar
  • 625

1
2 3 4 5
14