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.

2
votes
1answer
13 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
votes
0answers
15 views

Product attributes deleted after programmatically save

Same problem as here ... Url key disappearing and visibility changing when saving a product from collection Saving product deletes tier price and group price Since years we use Flagbits ...
1
vote
0answers
16 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
30 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
15 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
47 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
35 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
24 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
32 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
48 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
64 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
61 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
47 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
32 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
38 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
30 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, $...
0
votes
3answers
56 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
27 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
37 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
21 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
39 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
1answer
27 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
154 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
29 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
43 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
12 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
138 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 ...
2
votes
2answers
684 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
88 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
93 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
30 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
38 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
51 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
106 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
82 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
32 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
131 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
120 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
65 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
52 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
48 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
133 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
0answers
237 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
29 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
142 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
80 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
3answers
202 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
407 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
159 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