Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [product-collection]

Questions related to Magento product collections.

0
votes
0answers
10 views

Swatches inclusion on custom related product template file in Magento 2.3

I am using inclusion on swatches for custom related product template file using the method mentioned on : https://magento.stackexchange.com/a/223599/80609. But i am not able to pass related products, ...
2
votes
1answer
22 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:...
1
vote
3answers
40 views

I need to get product collection by filter multiple category ids in magento 2

I need to get product collection by filter multiple category ids. Here is my code: $catId = [2, 3, 5]; $productcollection = $objectmanager->create('\Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
25 views

How to get product collection based on custom price attribute in Magento 2?

I am using Magento 2.2.2 I have created one attribute "Retail Price". Input type for this attribute is "Price". I have added values in some products for this attribute. Now I want to load product ...
0
votes
0answers
18 views

Get number of pages in Oberver Magento 2

I have an Observer and I must get the number of pages (I need to know if there is > 1 page) in it. I tried on both collection and pager but no success : public function __construct( \Magento\...
0
votes
2answers
46 views

Magento 2 addAttributeToFilter not working

In product collection addAttributeToFilter is not working if we assing attribute value in only store view. But if we assing in default and store view than it working fine. anyone have idea why it is ...
3
votes
1answer
48 views

Magento 2 override product collection

I need to override protected function _productLimitationPrice($joinLeft = false) in magento 2 which is located at public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection....
2
votes
1answer
26 views

Magento 2 - Multiple collection on same block

I have a block where I want 3 different collections with different category filters. I have created collection object in constructor like this: protected $collection; public function __construct( ...
1
vote
1answer
19 views

getProductCollection count after updating filters

I wrote a little piece of code that shows me the amount of products in a category. However, after applying filters through one of the Amasty extensions, the count is incorrect and stays at the ...
2
votes
1answer
21 views

How to get Latest Products Collection in my costum Module Magento 2

I want to get Collection of Latest Products in Magento 2 i have some restriction Without using Object Manager Without using API i have searched on internet found these two methods but i have to ...
0
votes
0answers
18 views

Magento 2.3 custom conditions for attribute filter using addAttributeToFilter

In Magento 2.3 I need to filter the collection as per below scenario. I have L, W and H attributes for products And user input is "X, Y and Z" then the following condition will give the desired ...
3
votes
2answers
127 views

Magento 2 - Get Collection using custom product Ids and also sort them as the same order as product Ids passed

I need to get the collection using custom product Ids but it should sort the collection based on the sequence product Ids given Here is what I am doing now, but it is not sorting in sequence $...
1
vote
1answer
44 views

Magento 2: How to join product collection to custom table?

example: i have a table "table_1" i want to join product collection to get the product data? but I don't know how to join product collection? so everybody can help me pls? List item
1
vote
1answer
36 views

How to add product attribute value in custom collection?

I have a custom table which contains product id, I want to add an extra attribute column. so how can I get dropdown attribute value of the product in my custom table? if the dropdown attribute is not ...
0
votes
1answer
23 views

Magento2: how to develop rest API to get new products

I want to get new product using REST API. I am using below code:- app/code/Myvendor/Mymodule/Api/NewproductInterface.php <?php namespace Myvendor\Mymodule\Api; //use Myvendor\...
2
votes
0answers
27 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 ...
4
votes
1answer
41 views

Filter product collection with source

I'm running on Magento 2.3 with MSI(Multi Source Inventory) setup. I would like to filter product collection with specific source. Like, I've 4 sources for products, source-1,source-2,source-3 and ...
2
votes
1answer
41 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 ...
0
votes
0answers
29 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/...
0
votes
0answers
17 views

Visual merchandiser random product showing : M2

Magento2 Admin Panel > Products > Categories > Select Any category > "Products in category" When i try to load more products from select dropdown, some random products are showing in result ...
0
votes
2answers
46 views

How to pass added custom “key=>value” into getCollection()?

On product lisitng page i want to get one more parameter "latitude" for all product,how can i achieve? Here is my code:- public function setCollection($collection) { $this->...
0
votes
1answer
36 views

How to get the custom attribute of products from the cart?

There is an attribute in the product AllowSameDayDelivery how can I get it out of the product? I got the products ids from the cart, But how do I get the attribute now? <?php namespace Ronis\...
1
vote
0answers
20 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( '...
0
votes
0answers
212 views

Magento merge two collections with different sorting orders

I have one store in Magento 1.9 , There is a listing page with AJAX scroll loading, on first page I am showing 24 products. We are showing products with label In-Stock and Sold Out, In-stock products ...
1
vote
2answers
32 views

Removing a product from the collection on a category

I have a Magento site where I need to remove some products from certain customer groups due to them having a zero price on the products. I have tried catalog_product_collection_load_after event and ...
2
votes
1answer
22 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 ...
1
vote
0answers
21 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 ($...
3
votes
1answer
78 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 (...
0
votes
0answers
32 views

Magento2: Product Collection,product Collection Factory, ProductFactory all returning no products. What could be the reason?

I see errors related to setActive() and 'The requested sku is not assigned to given stock.'. Any of the Product Collection,product Collection Factory, ProductFactory is not returning any product ...
1
vote
2answers
150 views

Magento 2 product custom attribute source_model outerset attribute not showing in product collection and not working in addAttributeToFilter()

I am creating a custom product attribute in Magento 2 by custom module InstallData.php code following <?php namespace Awa\Brand\\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\...
1
vote
1answer
65 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('*') ->...
0
votes
1answer
39 views

How display specific products at top of list on category in magento 2

I want to display featured product of category at top of the product list with all filters, pagination and sorting. For Example: I have an array of ID's that should show first in collection when ...
0
votes
0answers
16 views

Avoid product duplication when trying to save from multiple ways

I am using Magento 2.3 version. I have a case to create the product from two XML when it hits my function. For example, I have two XML: A.XML and B.XML. Both XML will be triggered at a time or ...
1
vote
0answers
42 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 ?
0
votes
2answers
154 views

Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean in

( ! ) Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean in /var/www/html/magento2/ShopQuary/app/code/MagentoCoders/Manufacturer/Controller/Index/Index.php on ...
0
votes
1answer
110 views

Magento 2 : How to get best seller product collection using object manager in home page custom slider?

How to add best seller products in home page custom slider. So, I need a best seller product collection in phtml file.
1
vote
2answers
83 views

Get best seller products

I'm trying to get in the home page 12 bestseller products with this code: $_productCollection = Mage::getResourceModel('reports/product_collection') ...
0
votes
1answer
49 views

Magento 1.9 addAttributeToFilter() returning 0 products

I have the following code where i want product collection filtered with custom attribute. typeid = $data['categoryId']; $pagesize = $data['limit']; $pageno = $data['page']; Mage::app()-&...
2
votes
0answers
33 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 ...
0
votes
0answers
57 views

Ajax call on controller and get collection in grid

I am creating a functionality on my custom phtml. I want simple ajax call on my controller and get product grid in response. to ajax call I used this: require(['jquery'], function($){ $.ajax({ ...
0
votes
1answer
61 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
3answers
71 views

How to get all products with Qty in magento2

I am trying to get all products with it's stock qty in magento2. please let me know if anybody have solution.
1
vote
1answer
28 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') ...
0
votes
1answer
89 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 ...
0
votes
0answers
27 views

magento 2.2 product repository interface returns no collection

I'm trying to get a product collection via ProductRepositoryInterface. The code I'm using is this: $searchCriteria = $this->_searchCriteriaBuilder->create(); $searchResults = $this->...
0
votes
1answer
79 views

How to get Review for products collection magento 2?

Actually i want to get Review Rating and summary count.Please check below code <?php error_reporting(0); use \Magento\Framework\App\Bootstrap; include('../app/bootstrap.php'); $bootstrap = ...
1
vote
2answers
307 views

$this->_checkoutSession->getQuote()->getAllItems() returning an empty array

I am trying to get a collection of all items in the cart for current session but the array is returning [0]. My block: <?php namespace GGG\PaymentMethodsManagment\Block; class GetProductsInCart ...
1
vote
1answer
35 views

Getting a product collection via Cron

I have a cron job set up where I need to get all simple products. This is working perfectly well when I'm running the script manually but when Cron runs it it fails to retrieve the products. I've ...
0
votes
1answer
44 views

Magento 2: Show disabled/out-of-stock products in foreach loop

I am using \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory class to fetch the product collection. Magento version: 2.2.6 I am trying to fetch both enabled & disabled products ...
0
votes
0answers
13 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/...