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 [collection]

Questions related to Magento collections

1
vote
1answer
23 views

Collection not loading in Ui Component Admin Grid - stuck spinning

I have a basic CRUD repository setup, however when I try to go to the Admin Grid UI Component, the spinner just spins and nothing loads. No errors displayed in any of the logs either. When I inspect ...
0
votes
1answer
19 views

Magento2 add custom values in collection->setOrder

I need to add some custom values in setOrder() of a collection, but it is not working. $collection->setOrder("((lat - ".$lat.")*(lat - ".$lat.")) + ((lng - ".$lng.")*(lng - ".$lng."))", 'ASC'); ...
2
votes
2answers
36 views

Get products collection in cronjob

I have a cron file like Col.php. I want to get products collection in my cron file. code in my file: public function execute() { $objectManager = \Magento\Framework\App\ObjectManager::...
1
vote
1answer
21 views

Magento 1.9 : How to apply more than one price range on product collection

I want to apply multiple price ranges on final price of product collection. I have tried below code. $collection->addFinalPrice(); $collection->getSelect() ->where('price_index.final_price &...
3
votes
2answers
37 views

Search criteria builder does not filter an “out_of_stock” products

I am using Magento 2.3, Am filtering the product collection using the search criteria builder with a custom attribute as the filter. $filter1 = $this->_filterBuilder->setField('...
2
votes
1answer
38 views

Sort collection by discount

I want to sort my collection by discount percentage for my sale category, I don't know if it is possible in Magento
0
votes
2answers
25 views

Modify product collection in M2

I am overriding Magento\Catalog\Block\Product\ListProduct In function _getProductCollection I have added some extra code. public function _getProductCollection() { $collection = parent::...
0
votes
1answer
31 views

Not able to save an item magento 2

I have a table which store certain data in database. First i am checking if the content is already there in the database if yes then update it else insert a new data. $sync = $this->...
1
vote
0answers
17 views

Magento 2 searchCriteriaBuilder for multiple collection

I want to create search functionality for customer to search his invoice order etc. For this I'm using searchCriteriaBuilder and \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface ...
0
votes
1answer
34 views

is it possible to filter checkout cart collection magento 2?

Actually i want to filter the checkout cart collection using custom attributes values using this link $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $quoteId = $objectManager-&...
0
votes
0answers
17 views

How to get all categories and products in one collection in magento 2

How to get all categories(with levels) and it's products in one collection in magento 2
0
votes
0answers
20 views

Magento 2.3 collection factory not exist

I use magento 2.3 and I can't see collectionFactory created in generated folder or inject to any class. ModelFactory can create normally. There are my code: Model file: <?php namespace Lights\...
0
votes
1answer
23 views

How to call save method in collection instance

I was appeared Magento 2 Associate developer certification exam, in that I got the below tricky question, but I don't know the concept and answer of the question. can you have an idea regarding the ...
1
vote
1answer
26 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
15 views

How to delete object from collection in magento2

How to remove any object from magento 2 collection. If we have collection of products and we want to delete product which is at first index . how to delete that product without deleting it from ...
0
votes
1answer
30 views

Best seller items in category magento 2

I have used below code to filter products by category id. $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $catalog_ids = 4; $productCollection = $_objectManager- >create('...
0
votes
2answers
53 views

Filter sales/order collection according to country

I would like to filter out my home country (GB or United Kingdom) from the following sales/order collection. How can this be done? $orders = Mage::getModel('sales/order')->getCollection() ...
0
votes
0answers
9 views

Set a permanent limit on returned rows in grid

I have created a grid extending Mage_Adminhtml_Block_Widget_Grid. Within _prepareCollection I'm doing this: $collection->getSelect()->limit(10); But as soon the reset filter button is clicked ...
0
votes
2answers
46 views

Magento2: get latest Best seller collection

I am fetching Bestsellers like this: protected $_collectionFactory; \Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory, $this->_collectionFactory = $...
0
votes
2answers
42 views

Get Product Collecton by category with filters in magento 2

I need to filter category product collection with Instock items and only simple products. I have used below code to implement it.But the out of stock products also fetching with the collection. ...
0
votes
1answer
42 views

AND inside OR in where condition in getCollections() [duplicate]

Need to generate the following query with getCollection() however unable to figure it out. (id_path = '12/xyz') OR (request_path = '/abc' AND store_id = '1') Tried the following but I need it the ...
0
votes
0answers
29 views

Best seller collection filter magento2

I am trying to filter Best seller product collection like below. Seems the setOrder is not working. class BestSeller extends \Magento\Framework\View\Element\Template { protected $...
1
vote
1answer
96 views

Magento 2 How to get customer collection from website id?

I want to get collection for customer website wise. I have a website id, and now I want all the customers which belong to that particular website id. I am trying here: using \Magento\Customer\Model\...
0
votes
0answers
46 views

Magento 1.9.4 add custom dropdown field to inventory tab

Currently in magento when you manually change the quantity of a stock managed product in the admin there is no reason assigned to this. So, what I would like to do is add a dropdown field below the ...
0
votes
1answer
39 views

Magento 2 custom module Collection join table _initSelect

My Collection.php .... public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, ...
0
votes
1answer
18 views

Custom attribute saved but not loaded in collection?

I added a custom attribute is_featured to my Magento 1.7 store. Its a yes/no dropdown. I am setting it to yes on storeview level and to no on the standard level. Now I try to load a collection with ...
2
votes
2answers
29 views

addFieldToFilter `OR` condition for customer relationship in Magento 2

I have a custom module to store customer relationship, with database structure like this: |entity_id|first_customer|second_customer| entity_id => the relationship id first_customer => customer ...
0
votes
1answer
15 views

Magento 1.x addFieldToFilter using AND instead of OR (how can I join search using AND)

I am trying to use AND and OR based on user input. OR = success But I an unable to setup AND queries for addFieldToFilter question: how can I add the second (looped filter) using AND to join $...
1
vote
0answers
29 views

Magento 2: Sub category showing product from other sub category

I have a block class that extends \Magento\Catalog\Block\Product\ListProduct and tried to override the list.phtml with exactly the same file (say mylist.phtml), except it is located under my module. ...
1
vote
1answer
90 views

Magento 2: How to add where clause in grid collection

I am working on a module, where I have 2 custom tables. One is of all customer who have added product to First table(one customer can add multiple tables) and that first table is displayed on grid. ...
0
votes
0answers
22 views

How can I use 0 instead of null magento 2 collection?

I have created module to show report in grid. But in collection some fields contains null value how can I change null to 0. <block class="Magento\Backend\Block\Widget\Grid\Column" name="...
0
votes
1answer
104 views

Category collection with filter Magento2

I have created custom Drop down attribute for category with attribute_code is "is_homecategory" Used below methods to create it. Setup/InstallData.php public function install( ...
1
vote
1answer
65 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 ...
0
votes
0answers
30 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
0answers
88 views

Cache a product collection by a key?

I have added a collection to buff out related products with extra "most viewed" products from a products top level category. This is a slow query and takes about 0.2 seconds so was wondering if this ...
1
vote
1answer
25 views

How can i get products from a remote database in real time by filters in Magento 2

This request is for an auto parts store. The products are filtered by car make, model, year, etc. When a client apply a filter I need to make an API call to manufacturer server, get products and ...
1
vote
0answers
69 views

How to sort a collection after load

I have a store collection. And it has the following fields [0] => Array ( [location_id] => 5 [title] => Los Angeles [description] => [status] => 1 ...
1
vote
2answers
128 views

Magento 2, addAttributeToSelect not working with product collection?

I am applying these fillers: $collection->addAttributeToSelect('name'); $collection->addAttributeToSelect('sku'); but every time getting full record as comes form: $collection->...
1
vote
3answers
35 views

Product collection by category id, gives zero products

The following code, returns an empty collection in most categories, even if the category indeed has products: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $...
0
votes
1answer
49 views

Magento 2: Parsing Item information through block

I want to create a phtml file and create a dynamic block with that one to put on CMS pages - Take it as product information blocks where i want to display the product name, the price, the URL - ...
0
votes
3answers
70 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
35 views

Retrieve Compare Items Collection returning zero Items Magento 2

While I am trying to return compare items in custom module phtml file, it is returning zero items but in database table catalog_compare_item showing all the added items to compare. Class Used : ...
0
votes
1answer
19 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
1answer
25 views

What is the role of visibility filter in colections Magento 2?

I am getting Order Items, from order collection by Order ID but as from the attached screen shot (Order 15) I am getting one product data two times. Can any body explain the reason and what will be ...
2
votes
0answers
29 views

Check if 2 dates already exist in collection filtering

i have a custom collection which has database column start_at and end_at in Y-m-d format , i try to do some validation before inserting to database, one of them is make sure the period between ...
1
vote
0answers
180 views

Magento 2 : how can i add my custom filter in custom admin grid

i have created custom admin grid which shows the log of login customer, every time customer login successfully the log will be added in that grid even if same customer, what i want to do is add my ...
1
vote
1answer
21 views

Alter getProduct collection

I need to alter the equivalent of native "getProductCollection", but I don't know how and where to do this. I need the getProductCollection to look like this : public function getProductCollection() ...
1
vote
1answer
86 views

Get all guest & customer email id's in single collection Magento 2

I am trying to list all unique email id's (guest & customers) in admin grid to restrict specific email id to place order. For that, I got an id's from customer collection and order collection. ...
2
votes
1answer
116 views

Magento 2.2.6: Product collection does not apply the filter

EDIT: I have seen that in magento 2 the ListProduct page is cached, for this reason once loaded it does not enter. Is there any way to modify the query returned by ListProduct? I extend the class: ...
0
votes
1answer
93 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.