Stack Exchange Network

Stack Exchange network consists of 174 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
1answer
13 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
12 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
31 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 = ...
0
votes
0answers
20 views

How to create layered navigation for custom page in Magento 2?

I want to show layered navigation on custom page where I will show some products. I followed the answer in Layered navigation for custom collection on custom page - magento2 but it is not working.
1
vote
2answers
68 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
27 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
38 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
8 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/...
0
votes
1answer
131 views

Sort product collection by Latitude and Longitude

I need to sort product collection by latitude and longitude in product listing and search page. Explanation: I have two product attributes Latitude and Longitude. All product has single Latitude and ...
1
vote
2answers
251 views

How to get recently viewed products collection of Customer Magento 2?

Magento 2 get recently viewed products collection of Customer (Using customer ID) programmatically I tried this solution But I want recently viewed products collection. I tried below solution too ...
0
votes
1answer
73 views

how to get custom attribute value from bestseller products collections in block magento 2?

Here I am trying to get custom attribute value from bestseller products collections magento 2?? <?php namespace Vendor\Module\Block; class BestSeller extends \Magento\Framework\View\Element\...
1
vote
1answer
41 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 ...
2
votes
1answer
28 views

Show only products on a new category page which have a certain product attribute enabled

I want to create a new category page which shows all products which have a certain product attribute (speed_delivery) set to yes. I was thinking about to create an empty category, catch its product ...
0
votes
0answers
26 views

Magento 2 - Apply filter on Product collection

Is there any common event or plugin to apply the filter to product collection which includes product list page, related products list as well as upsell and cross-sell product list? If no, then how ...
0
votes
1answer
35 views

Products Collections not loading using block in cms magento 2?

app\code\Namespace\Module\Block <?php namespace Namespace\Module\Block; class Catproduct extends \Magento\Framework\View\Element\Template { protected $_storeManager; ...
0
votes
1answer
45 views

Collection get items return null

I tried to get all products sku, that started at $params['sku'] My controller: <?php namespace Aty\TestTask\Controller\Index; use Magento\Framework\App\Action\Context; class GetProductAjax ...
0
votes
3answers
59 views

How to prevent memory consumption during collection enumeration?

In the following script: $pageSize = 1000; $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addWebsiteFilter($website->getId()) ->...
0
votes
1answer
16 views

Magento 2 Get product collection filter by atributes does not give the exact match

I have created a filter to get product bellow is an examples: $filter = array( array('attribute' => 'color', 'eq' => '2'),//id of option array('attribute' => 'size', 'eq' => '5'),// ...
0
votes
0answers
54 views

Magento 2.2 - Layer navigation with custom product collection not working

I want custom product collection with layer navigation in custom page. I have checked many links already and followed with below link, Layered navigation for custom collection on custom page - ...
0
votes
1answer
65 views

Magento 2 Join Product Collection with Custom CollectionFactory

In Magento 2.2.5, I have Custom Model Collection (followed this tutorial). In that I want to add the Product Collection into this custom collection by default. How to achieve this.
0
votes
1answer
62 views

M2 Include disabled products in product list widget collection

I'm not sure if this is an m2 2.2 bug or just due the way I'm trying to filter the collection, but I can't seem to include disabled products in my product list collection. I've tried a few different ...
1
vote
2answers
27 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\...
2
votes
1answer
36 views

visibility attribute value is not rendering from product collection in magento 2

We need to display the visibility of the product in category page, but currently we are not able to fetch its value from product object. We tried with $_attributeLabel = $_product->getResource()-&...
1
vote
2answers
97 views

How to Shuffle Product Collection in Magento 2?

I am getting products collection form multiple categories. I want to shuffle products everytime when function getProductCollection() is called. My function is: public function getProductCollection($...
1
vote
1answer
163 views

Magento2: How to get product collection which cart rules apply on this?

I have added cart rules on some product. I want to display the message on the free product which has rules applied. How to get product collection which cart rules apply on this? My Magento version ...
4
votes
1answer
27 views

Is it possible in Magento 2 to load content in between products?

I'm wondering if it is possible at all to load some content (different per page) in between the product collection. I've made a module injecting some content that I enter in the backend, but obviously ...
1
vote
0answers
94 views

While sorting my product collection automatically shuffeling

For Magento 2.2 I'm using:- $categoryId=185; $ct = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); $collections = $ct->getProductCollection() ...
2
votes
1answer
54 views

Group Collection to Filter Unique Products Based on a Specific Attribute

Scenario: A store catalog is populated with configurable products each having several children with different sizes and colors. As the goal is to show the different color variations, only the ...
2
votes
1answer
66 views

How to get product collection with both in stock and out of stock products in Magento 2.1

I'm using below code to get the product collection <?php namespace Vendor\Module\Block\Product; use Magento\Framework\View\Element\Template; use Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
321 views

Show all products on one page in Magento 2

I need a page where all products should be displayed. All products from all categories, also including filters by attributes. I have tried to use the following block {{block type="catalog/...
0
votes
2answers
95 views

Magento2: How to get product collection by parent-category-id and sub-category-id?

How to get product by parent-category-id and sub-category-id? Magento 2.0
0
votes
1answer
25 views

Can I call addFieldToFilter via di.xml? / Set a global filter on product collection

I am working with vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php which extends the \Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
65 views

In Magento 2.2.5 load product by id is not working

In Magento 2.2.5 load product by id is not working. I tried the below solutions: Sol 1: $product_id=20; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $...
0
votes
2answers
24 views

how to remove white space from product name during custom product collection?

I am getting stuck with white space in set order during product collection in magento 2. I want to get product details with ascending order via name but name has white space. I have removed white ...
0
votes
0answers
165 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. ...
0
votes
1answer
50 views

Get collection of filtered products (layered navigation)

I am trying to get a collection of products according to filters applied in layered navigation. I thought, that layer model's getProductCollection will do it for me, but as long as i see, it ...
2
votes
1answer
82 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 = $...
0
votes
0answers
25 views

what is feasible getCollection with product_id filter or load for getting attribute values in magento 2

I can get product-data (like an attribute) via the load() method, but I would like to do the same thing, only filtering the collection with product_id like addFieldToFilter() and using ...
1
vote
0answers
63 views

Magento 2 how to run reindex for single product or some cart line products

Is there any way in magento to achieve to reindex only single product or some items. I have a inventory existing /update call on product page load and cart page load. Right now doing indexing for ...
2
votes
1answer
194 views

Magento 2 : Is there a way to query products using Custom Attributes in Rest API Call?

I have a custom attribute setup for Books called isbn_13 Now I try to find the products using the isbn_13 values but unable to filter the results based on this. Is there any way to do this? Update: ...
0
votes
0answers
44 views

Calling getCollection in phtml is empty

In Magento 2.2.5, I am setting the Block for phtml using below code: <?xml version="1.0" encoding="UTF-8"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" ...
0
votes
1answer
91 views

Magento 2.2.5 get the product collection without Stock data

I am using Magento 2.2.5. In that, I am creating the products using the below code. $product = $this->objectManager->create ( 'Magento\Catalog\Model\Product' )->load ( $productId ); $product-...
1
vote
1answer
31 views

How do I update products without resetting attributes to default values

I have a script that updates stock and price but it seems to save all attributes with a default value back to the default. The collection is loaded like this: $productsCollection = Mage::getModel('...
2
votes
0answers
68 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', ...
1
vote
0answers
27 views

productCollectionFactory load function gives data in query but not in object

I have created a collection factory $collection = $this->_productCollectionFactory->create() ->addAttributeToFilter('status', '1') ->addAttributeToFilter('featured'...
1
vote
0answers
24 views

Not getting Specific field value using Get method even its exists in collection and also in collection getData magento 2

This is my code: $collection = $this->_productCollectionFactory->create() $collection->addAttributeToSelect('*')->load(); I am Not getting Specific field value using Get method even its ...
0
votes
1answer
31 views

Load catalog displaying values from 2 stores at the same time

I searched for a similar question, but didn't find any suitable answer. I have a multi-store Magento and I simply want to load my catalog seeing some attributes values of the admin/global store view ...
0
votes
1answer
138 views

Custom sort order for loaded collection?

I have a product collection created by Magento for the category product list. I then pass some information about this collection to an external method that returns the entity IDs in a specific sort ...
0
votes
0answers
116 views

Override Toolbar.php having issue for catalog page magento2

I have done the following: registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, '...
2
votes
2answers
96 views

Add group prices to product collections

Is there a method to add group prices (for one or more customer groups) to product collections? Actually I have this ... /** @var Mage_Catalog_Model_Resource_Product_Collection $products */ $...