Questions tagged [product-collection]

Questions related to Magento product collections.

Filter by
Sorted by
Tagged with
2
votes
1answer
31 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 /...
0
votes
0answers
30 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 ...
0
votes
1answer
21 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 ?
0
votes
1answer
40 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; ...
0
votes
0answers
23 views

How to get data from Catalog_product_entity_int Via Product Collection?

I am trying to get the result of this query select entity_id, value from catalog_product_entity_int where attribute_id = 191 AND value = 3; is it possible to get the results of a query like this ...
0
votes
1answer
15 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->...
1
vote
2answers
49 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 ...
0
votes
0answers
22 views

Joining product collection with 'sales_order_item' giving same products after adding pagesize and current page

I am getting product collection by category id, after getting collection I'm joining it with the sales_order_item to get the best seller products in desc order and using page size and current page ...
0
votes
0answers
31 views

Custom Module made Pagination disappear?

My custom module is preventing users from seeing specific products when they are not logged in or logged in but don't have access to see them. For category pages I am listening to the ...
0
votes
1answer
28 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 ...
0
votes
0answers
19 views

Product collection search issue

I got two issues in one I can't figure out, any help would be precious. Collection size Product prices I'm trying to analyze the result of a search by word and order by price request. To do such a ...
0
votes
2answers
22 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 ...
0
votes
1answer
53 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 ...
0
votes
0answers
40 views

Filtering product collection by custom attribute by overriding $layer->getProductCollection();

I created a module and a new block so that I can overwrite \Magento\Catalog\Block\Product\ListProduct. My catalog consists of configurable products, and I need to filter based on attributes assigned ...
0
votes
0answers
38 views

Magento 2.4 : override product collection filter not work in layered navigation

I am using magento 2.4 version. I wanna user custom filter in product collection so I override getProductCollection() function in \Magento\Catalog\Model\Layer.php but it filters the product but not ...
0
votes
1answer
28 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 \...
0
votes
1answer
42 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
0
votes
1answer
29 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\...
0
votes
2answers
38 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 ...
0
votes
0answers
34 views

How to filter product collection by price after tax in magento 2.3?

I am trying to apply filter product collection by price range: $productsCollection = $this->_productsCollectionFactory->create(); $collection = $productsCollection->addAttributeToSelect('*'); ...
3
votes
2answers
75 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->...
0
votes
1answer
20 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\...
0
votes
1answer
186 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\...
0
votes
0answers
13 views

magento 2 get folter attributes values in custom api

Hi i created custom API in magento 2 in that i need to implement advance search like store brand,model and year search like this i am able to get brand fileds ` public function getAddtocar($attribute)...
0
votes
1answer
59 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 ( [...
1
vote
1answer
132 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 ...
0
votes
1answer
27 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 ...
0
votes
1answer
79 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 ...
0
votes
0answers
24 views

magento 2 hide out of stock products except when a specific attribute equals yes

I would like to hide out of stock products generally so I've added the option in the store configuration settings. However there are certain products that will be restocked soon. I'd like to keep ...
0
votes
1answer
29 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 ...
0
votes
1answer
34 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') ->...
0
votes
0answers
18 views

How to get the best selling products in a category and sort them from best selling to least selling?

How to get the best selling products in a category and sort them from best selling to least selling? I try get best selling collection like: use Magento\Store\Model\StoreManagerInterface; use Magento\...
0
votes
0answers
25 views

can i use one product collection for multiple attribute filtering?

I have a product collection based on category. Can I use addFieldToFilter (color) for both equal and not equal. Color with given value as one set of collection and color which is not equal to given ...
2
votes
0answers
154 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 ...
1
vote
1answer
47 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([$...
0
votes
1answer
186 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:/...
0
votes
2answers
31 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 ...
0
votes
1answer
94 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 = []; $...
1
vote
1answer
94 views

Unable to get not visible products after applying category filter magento2

I am trying to get Child products from collection after applying category filter but unable to get all products (want to get all products including Not Visible Individually products $...
0
votes
1answer
59 views

How to use orderCollectionFactory and productCollectionFactory together in Model file?

I have created a custom attribute in product and saved a string in that value and I want if some one order those product of same value string i want that collection of product. So, i want to use \...
1
vote
0answers
59 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\...
0
votes
0answers
443 views

How to get Salable Quantity in product collection?

Need to filter product collection by salable qty in frontend in catalog>product>list.phtml. Currently, I am processing the saleable qty inside foreach loop but it takes lot of resources and some ...
2
votes
0answers
130 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() ...
1
vote
1answer
666 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
29 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
2
votes
3answers
947 views

How to get product collection with different page sizes?

I need to get 29 products on page #1 and need to get 26 products from page #2 to the last page number without duplication. I'm setting page size as 29 in the first page and 26 from the second page, ...
3
votes
1answer
603 views

Filter Magento2 Fulltext\Collection by OR condition

How can i filter the Magento2 Fulltext\Collection (Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection) by an OR condition between 2 product attributes, with respecting also the ...
0
votes
1answer
52 views

Can i add product in category page product collection?

Can I add a product in category page product collection? I want to add product #123 in category page product collection but the same product already exists in the collection so it is possible? My ...
2
votes
1answer
338 views

Magento 2.3 product collection->getData get correct answer but foreach or load() not

Same with here : Magento 1: $productCollection->getData() vs foreach ($productCollection as $product), want add more information. Create new product then $productCollection = $objectManager->get(...
0
votes
1answer
279 views

How to join a custom table and show its attribute on Magento 2 rest Api getList() function?

Im creating a custom product Api with searchCriteria from \Magento\Catalog\Model\ResourceModel\Product\Collection And I joined other table to this collection; public function getList(\Magento\...

1
2 3 4 5
14