Questions tagged [product-collection]

Questions related to Magento product collections.

Filter by
Sorted by
Tagged with
0
votes
1answer
57 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
378 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
324 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\...
0
votes
1answer
330 views

Pagination in Custom Collection magento 2

I am retrieving data from third party as an object, I am forcefully converting an object into array and collection. I want to apply pagination with the data, I tried using core pagination logic and ...
0
votes
0answers
144 views

Magento 2: load product collection of another website

Magento 2.2.9: I have a multiwebsite-setup. Site 1 is a normal webshop. Site 2 is a satellite page that links to site 1. So I would like to create a product collection from site 1 starting like this: ...
0
votes
0answers
281 views

Magento 2 - How to use mysql find_in_set?

In Magento 2, I try to use find_in_set mysql function but without success. I try this : $result->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$sort_order)."')"); But it give me ...
1
vote
1answer
25 views

Out of stock products: why do they appear in Collection::getAllIds and not in Collection::getItems

Im trying to get all products in a collection: out of stock and products in stock. So what I did is: /** @var $collection \Magentp\Catalog\Model\ResourceModel\Product\Collection */ $collection = $...
0
votes
1answer
14 views

Can't find category_ids in of each product in product collection

How can we include category_ids in product collection getData? Join field didn't work for me. For example, look at the below code Mage::getModel('catalog/product')->getCollection() -&...
1
vote
1answer
42 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 ...
0
votes
0answers
201 views

Get order Collection of last 14 days based on product collection

I have already product collection which fetches product based on category id, now I want to fetch only products which are ordered from last 14 days from above condition Any SOlution? public function ...
0
votes
1answer
88 views

Magento 2.3.2 sort collection by stock availability

I want every collection with 0 stock to get moved to the bottom (last position) I've tried using a plugin. My di.xml <type name="Magento\Catalog\Model\Layer"> <plugin name="...
1
vote
1answer
526 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: ...
0
votes
0answers
138 views

Wrong store_id in product collection

I need to cycle products collection for each store. But the method $collection->addStoreFilter($store) seems to not work properly. I also tried to $collection->setStore and setStoreId. The problem ...
0
votes
1answer
121 views

data patch changes does not affect database

I have created Data Patch, debugged it and everything works as expected, products are removed from the collection but after running setup upgrade changes are not made in the database, what can be ...
1
vote
0answers
307 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: {...
0
votes
2answers
41 views

magento 2 unable to get product Ids in foreach loop

I am trying to get all product ids of multi-select attribute "filter_type" ids($optionData) are assigned. But I am unable to get them as its only works first time. In second and other loop I am not ...
0
votes
2answers
1k views

Get all visible products whose Quantity greater than 0 in Magento2

I have written a product collection to get all products whose quantity is greater than 0. Here is my code for the collection <?php $websiteId = $this->storeManager->getStore()->...
0
votes
0answers
47 views

Most view product collection with Filter Magento 2.3.3

Here, product_type is my custom product attribute. This is custom script for getting most view product collection and working well <?php use Magento\Framework\App\Bootstrap; require ...
3
votes
3answers
4k views

Magento2.3 - get product collection in stock only

Magento 2 get product collection with filter stock get only in stock product in the collection See below code $collection = $this->_productCollectionFactory->create(); $collection->...
0
votes
0answers
1k views

Slick slider with ajax not appending in slider

I am trying to follow this answer but for me its not working perfectly I created custom phtml & block which will show the product slick slider, till time is working perfectly, but after the use ...
3
votes
8answers
1k views

Magento2: I want to show featured product on top of the category and search result

I have yes/no type product attribute. If this featured attribute is yes for any products, those product will show top(first featured product showing in category page then rest of the products are ...
1
vote
0answers
134 views

Magento 2: Add extension attributes to product collection

I have added extension attribute to Magento\Catalog\Api\Data\ProductInterface using extension_attrributes.xml and its getting reflected when I get product(s) using ProductRepository's get, getList and ...
3
votes
1answer
394 views

How to get in stock product collection by category id in Magento 2.3.3?

I'm using Magento 2.3.3 with multiple websites store that uses different multiple stock sources(multi inventory) and I tried to retrieve product collection by category id like this: public function ...
1
vote
1answer
470 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
147 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
2answers
1k views

Get products collection by store id in magento2

How get product collection by store id I tried below code $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager->create('Magento\Catalog\Model\...
1
vote
0answers
26 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
57 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.
0
votes
0answers
41 views

Display product collection without limit in Magento 1

I created a custom module that redirects your homepage to a landing page (CMS Page) that is a campaign page, for example, black friday. I've created a new layout for the page, layout that uses a ...
0
votes
1answer
829 views

Magento 2.3: How to filter product collection by stock status

Having trouble figuring out how to filter a product collection by in stock / out of stock status. My goal is to get all out of stock products that also match some other filters: public function ...
0
votes
0answers
29 views

Special Products Collection

I've been trying to get a special price collection of products for Magento 2 but I keep on failing. I've got the following example that works(almost): protected function ...
0
votes
1answer
107 views

magento getProductCollection add random order and exclude a product id only from output

I want to get random product from category id which is working find but i want to exclude a particluar product id from out and show output in random order Below is my code , please help me with way ...
0
votes
4answers
505 views

How to filter product by specific attribute in Magento 2?

I want to filter a collection of products by product (brand) attribute, thanks
2
votes
2answers
144 views

Magento 2.3.2 Collection foreach didn't get disabled product

I am using Magento 2.3.2. I am filtering collection if product ids found in array. before foreach if I am printing collection I am getting data. But in foreach I am not getting any data. $productIds ...
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 ...
3
votes
1answer
780 views

Magento2 - catalog product listing collection sort by price with dynamic price calculation

product price is calculated dynamically based on certain conditions. while sorting with price it takes only default price not dynamically calculated price. the same issue with the price filter. I can ...
4
votes
3answers
1k views

Magento 2.3.3 addAttributeToFilter is_saleable attribute no longer supported

After upgrading to Magento 2.3.3 product collections filtering with the is_saleable attribute no longer appears to work and the following error is seen in templates calling the collection : The "...
0
votes
2answers
2k views

How to get product collection in controller in Magento2

I am creating a new module in magento2 and in controller file, I try to get product collection in controller index.php file so how can I get product collection in Magento 2. so give me suggestion to ...
0
votes
2answers
2k views

Magento 2: Sort Product Collection by date added to category

From a category page, I grab the product collection from the category object like so $productCollection = $category->getProductCollection()->addAttributeToSelect('*'); However, the results are ...
0
votes
2answers
235 views

Why product collection model don't show real Sql query?

I want to understand how M2 loads products EAV attributes, so I wrote the following code: $productCollection = $this->productCollection->addFilter('entity_id', 7) ->...
0
votes
0answers
37 views

Magento2 - hide special price products

I would like to hide any products with a 'special price' from the main catalogue to only show them on a custom 'sale' page. I could probably do this in M1 but I do not know what the general approach ...
0
votes
3answers
32 views

Magento 2 addAttributeToFilter not adding to SQL

I'm trying to get a list of products with a custom attribute set a certain way. Right now only one product should be returned, however it's returning the whole catalog. It seems like my added ...
1
vote
0answers
43 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
1answer
790 views

Magento 2 Custom Product Collection Size Problem after Removing Products from Collection

In Category list view I want to create a custom collection where some products are not shown OR the entire collection is re-sorted. To test this I created an observer for the event ...
1
vote
2answers
659 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....
2
votes
2answers
45 views

Product collection retrieval N at a time (paginated)

I want to retrieve all the products. But would like to limit it to say 100 at a time to avoid too much memory usage. I have the collection factory injected in the constructor as \Magento\Catalog\...
0
votes
1answer
96 views

Magento 2: Display out of stock items in the end in API

I am using a headless magento 2 approach for my store. I have made an API which accepts parameters like: category_slug, sort_by, sort_order, page_size, current_page and returns the products ...
0
votes
0answers
216 views

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.attribute_set_id'

I am trying to Filter the products based on vendorid with attribute_set_id. if i use print_r in the collection i am getting the result like below $objectManager = \Magento\Framework\App\...
0
votes
1answer
100 views

List all Products and change price, quantity and one custom attribute

We're a very small store and have to sell some of our products online. Magento is our system of choice. Right now we're still using Magento 1. For our shop we have the possibility to list all products ...
0
votes
1answer
910 views

Magento2: Error: Call to undefined method addViewsCount()

I have got the error below: Error: Call to undefined method Magento\Catalog\Model\ResourceModel\Product\Collection\Interceptor::addViewsCount() <?php namespace Vendor\Mostviewed\Block; class ...

1
2
3 4 5
14