Questions tagged [collection]

Questions related to Magento collections

365 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6 votes
1 answer
691 views

How can I get only the Store View attributes, without the inherited Global data? I only need the diffs

I'm using the internal Magento APIs to get the product data on a store view level. I only want to get the values that are on that store view level, not the global values that in inherits. But it ...
Mitch Goldman - londonmitch's user avatar
5 votes
0 answers
1k views

Magento 2 Join other tables using SearchCriteria JoinProcessor

Has anybody been able to join another table using SearchCriteria, JoinProcessor and virtual types. I have read the documentation (https://devdocs.magento.com/guides/v2.3/extension-dev-guide/searching-...
Radu's user avatar
  • 460
5 votes
0 answers
1k views

Magento 2 : How to generate a collection from data models

If I understand correctly, Magento 2 moves more and more to the strict use of data models instead of creating models that are tied-in with their resource models and have all kind of business logic ...
Giel Berkers's user avatar
  • 12.2k
4 votes
1 answer
992 views

getCollection return null on custom model collection Magento 2.3.4

I'm creating a custom module to make a model by using mage2gen, I named this model critic: app/code/Vendor/Module/Model/Critic.php namespace Vendor\Module\Model; use Vendor\Module\Api\Data\...
jojo's user avatar
  • 39
4 votes
1 answer
681 views

loop through 2 collections with in one phtml

I am working on a custom module that is pulling in 2 different collections. When I try to use a for-each to loop through either of the collections the page displays the collection correctly. However,...
Brian's user avatar
  • 51
4 votes
2 answers
1k views

How to use collection factory model in Unit Test magento 2

I have a custom extension with model with structure like this in database: +----------------------------------+ |entity_id | customer_id | balance | +----------------------------------+ | 1 | ...
mileven's user avatar
  • 419
4 votes
0 answers
198 views

How to handle multiple tables with magento 2 repositories?

As we all know, magento 2 suggests using repositories as an additional layer between resource models/collections and the rest of application. It's all pretty straightforward and simple when you use it ...
Luke's user avatar
  • 782
4 votes
0 answers
278 views

Magento API complex filter value from another key value

I have a custom soap api for my magento 1 website, the problem is i dont know what array value to pass as the filters parameter so the parameter will work like this: $collections = Mage::getModel('...
nortonuser 's user avatar
4 votes
0 answers
998 views

Magento 2 : How to Return the Collection from afterload

I have implemented this jquerytokenizer in Ui Component form shown in the below image. It works well , the data is saved accurately- but when I go to edit a saved record this field is empty ...
Verdu's user avatar
  • 1,730
4 votes
0 answers
189 views

Magento 2 addProductsFilter to Stock Item collection

In Magento 1 you were able to add a product filter to a Stock Item collection in the Mage_CatalogInventory_Model_Resource_Stock_Item_Collection class. This functionality appears to be missing along ...
Richard Cripps's user avatar
4 votes
2 answers
500 views

Magento getting store bestsellers: configurable products, only from current store

Magento getting store bestsellers: configurable products, only from current store We have tested some bestseller codes like from here and here and here. They all work fine if you only sell simple ...
snh_nl's user avatar
  • 5,442
3 votes
0 answers
170 views

Update layer navigation filter with the proper custom collection

Goal : Create a /test/index/index route that will load a product listing page with a custom collection. Expectation : The custom collection printed in listing and the filters must be properly defined ...
Claims's user avatar
  • 1,164
3 votes
2 answers
94 views

collection, get product image

Sorry for my English I have this code $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('short_description') ->...
Denis Maksiura's user avatar
3 votes
0 answers
53 views

how to use filters for new collection

I use in my decision the answer that was in this question Magento 2 Custom Collection Everything works fine, but how to filter data when they are searched? My code $collection = $this->...
Denis Maksiura's user avatar
3 votes
0 answers
614 views

Order Collection based on Multiple Select Option Values Magento2

I have a list of products (books) with a custom eav multiple select attribute named 'authors' in magento 2. This attribute is 'visible_on_front' and also 'used_for_sort_by'. I am trying to use that ...
Emanuel's user avatar
  • 33
3 votes
0 answers
425 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\...
the light's user avatar
  • 718
3 votes
0 answers
457 views

Magento 2: Filter by custom product/category attribute returns 0 results

I created a bool (int) attribute with a default value of 0 for both category & product entities. I reindexed, cleared cache, etc... Now, no matter what I do, I can't filter the collection using ...
Pini's user avatar
  • 917
3 votes
0 answers
118 views

Magento 2 : How to get top 10 repeated values in a column using CRUD instead of sql?

I want to get top 10 most repeated values in a column of my table, I can do so using sql but I need to do it using CRUD i.e using collections or model as magento coding standard doesn't allow naked ...
Vivek Kumar's user avatar
  • 5,385
3 votes
0 answers
3k views

Magento 2 filter not working on custom column

Magento 2 Filter is not working. In the below code column created through layout xml are getting filter, but on column created via column class file filter is not working. I have found that one ...
Hitesh Rane's user avatar
3 votes
1 answer
472 views

Getting data from quote items collection issue in M1

This is my collection: $collection = Mage::getModel('checkout/cart')->getQuote()->getItemsCollection() ->addFieldToFilter('product_type', ['eq' => 'bundle']); $...
Attila Naghi's user avatar
  • 4,013
3 votes
1 answer
1k views

Magento 2: performance of getCollection function

I'm currently working on a Magento 2 theme that requires collection statistics to show on the frontend. For example: what are the total number of customers at the moment. I'm using \Magento\Customer\...
Tjitse's user avatar
  • 1,300
3 votes
0 answers
416 views

Magento 2: products collection with multi-selected values of multiple attributes

I have numbers of custom attributes with multiple selected values in magento catalog. I need to filter products by multiple attributes having multiple selected values. eg: Attribute set having a ...
Pankaj Sharma's user avatar
3 votes
0 answers
619 views

Magento 2 How to filter shared wishlist items function?

I want to add a new filter in shared wishlist items. I have used the preference method to override the block method. The problem is that the addFieldToFilter is not working. How can I achieve it? ...
Jancy Abraham's user avatar
3 votes
0 answers
5k views

Magento 2: Duplicate key-sequence unique identity-constraint 'uniqueVirtualType' fatal error while di:compile

When i run php bin/magento setup:di:compile it gives me below error [Magento\Framework\Exception\LocalizedException] Invalid Document Element 'virtualType': Duplicate key-sequence ['Custom\...
Jackson's user avatar
  • 9,909
3 votes
2 answers
5k views

How to add collection filter to gridContainer in Magento 2?

I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case. I'm using gridContainer instead of usual way. Here is my files: layout.xml <...
Toan Nguyen's user avatar
  • 3,049
2 votes
0 answers
83 views

How to stop huge memory consumption when iterating over large amount of orders?

I created a console command to create invoices and shipments for a certain set of orders. The total amount of all affected orders is about 79000. When I execute the command memory consumption is going ...
Daniel's user avatar
  • 2,229
2 votes
1 answer
768 views

Magento 2 - Best way to query data from tables (select with multiple joins)

I'm learning about Collections, Repositories and DTO, and I'm still trying to figure out what's the best way to query a table to fetch data. I also found that we can use \Magento\Framework\App\...
Douglas Vicentini's user avatar
2 votes
1 answer
379 views

Custom Sorting on category page not working in Magento 2.4.2

I have Magento 2.4.2. I have written a custom code to add A-Z & Z-A filters on category page. I have added dependency injection using below code <preference for="Magento\Catalog\Block\...
Nausif's user avatar
  • 1,544
2 votes
0 answers
313 views

Magento 2.4 Custom Filter on product collection, wrong collection size

I created a custom filter to filter products on category pages and in search. Filter itself seems to be correct (two products are visible from origin twelve) but pagination is wrong (total size is ...
barcholt's user avatar
2 votes
0 answers
400 views

Magento2 filter products based on location (custom attribute) programmatically

I have a Magento2 Store (v2.4) where I have multiple locations. for (eg. Jaipur, Delhi, Mumbai etc). I have managed locations using custom attribute using multiple dropdown list and assigned it to ...
Abhishek's user avatar
  • 131
2 votes
1 answer
98 views

Category CollectionFactory issue

Can anyone see what I am doing wrong here. It displays All categories instead of only showing the specific website/store categories. $collection = $this->_categoryCollectionFactory->create(); $...
Paul Donnelly's user avatar
2 votes
0 answers
162 views

Magento 2 get Collection Data From Two different Third Party Module and Merge

I have Two Module "Module A" and "Module B" ,In Module A there is a listing page where data is fetching the table by collection and listing on frontend and same doing Module B. I want to customize ...
akgola's user avatar
  • 2,927
2 votes
0 answers
91 views

Tree categories from products collection

If I have a collection like this: $collection = Mage::getResourceModel('catalog/product') ->getCollection() ->addAttributeToFilter('my_custom_attribbute','my custom value'); What is the ...
BOES's user avatar
  • 210
2 votes
0 answers
34 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 ...
ElFietsbel's user avatar
2 votes
0 answers
468 views

Function removeAttributeSearch

I have a code: $productCollectionClone = $productCollection->getCollectionClone(); $collection = $productCollectionClone->removeAttributeSearch($attribute->getAttributeCode()); Anyone can ...
David Duong's user avatar
2 votes
1 answer
438 views

How i can work with extension attributes using collection?

Hello i have to add extension attributes to Magento\Catalog\Api\Data\ProductInterface So i added this one to extension_attrributes.xml: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
maybe_vp's user avatar
2 votes
0 answers
55 views

How to create a pagination on product page for the reviews

I am trying to create pagination on product page just to keep the review down. I have over 50 reviews for product is there anyway I could limit it to 10. Is there anyway I could follow some codes or ...
Jack Brooks's user avatar
2 votes
1 answer
42 views

Magento catalog price rule

How to get product based on conditions on catalog rule in magento2? By product model products are received but how to apply filter to get only those product based on conditions. Any help will be ...
Aditya Singh's user avatar
2 votes
1 answer
55 views

Difference between $this->getData() or $this->getResource()

In my Collection.php when i get the collection by $this->getData() is give me collection. But it create some other problem for me . Now i use $this->getResource() then problem solved But it ...
HaFiz Umer's user avatar
  • 1,661
2 votes
0 answers
635 views

how to do pagination to display collection at admin panel custom table in magento 2

I'm trying to create a pagination for my collection to display in a .phtml file, but am getting error page Invalid template file: 'Magento_Theme::html/pager.phtml. Here is my code: code/...
Praveen Negimani's user avatar
2 votes
1 answer
542 views

How to filter customer collection with its attribute?

I've bunch of customer attributes, So how can I filter customer collection with its custom attribute ?
anonymous's user avatar
  • 3,732
2 votes
2 answers
1k views

How to update record using multiple conditions in CollectionFactory magento 2

I am trying to update the record but it creates a new record. Collection factory <?php namespace Webkul\Mpquotesystem\Block; use Webkul\Mpquotesystem\Model\ResourceModel\Quoteconversation; ...
prabhakaran7's user avatar
  • 1,087
2 votes
1 answer
431 views

Magento 2 - Display out of stock product for only one category while hiding them in all other category

How to display out of stock products only in one category with "Display Out Of Stock" option "No" in the admin?
Pribhav's user avatar
  • 458
2 votes
0 answers
39 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. ...
user1801605's user avatar
2 votes
1 answer
1k 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 ...
Nismath vi's user avatar
2 votes
0 answers
168 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 ...
blue's user avatar
  • 128
2 votes
3 answers
7k views

How to use addFieldToFilter & addFieldToSelect in magento2

I need to known how to use addFieldToFilter & addFieldToSelect in frontend? And can I use like below $searchQuery = $wholeData["searchQuery"] ?? ""; $searchQuery = trim($...
Ask Xah's user avatar
  • 522
2 votes
0 answers
617 views

Create filter group inside foreach dynamic filters

I'm following this link to create a filter group to be applied to my custom collection. searchCriteria => [ 'filterGroups' => [ 0 => [ 'filters' => [ 0 => [ ...
mileven's user avatar
  • 419
2 votes
3 answers
4k views

Magento:2 How to Image upload in custom module

Image upload working fine in tmp folder, then store in DB. I want to after saving data image stored in the base folder pub/media/events var_dump($data); " ["events_url"]=> array(1) { [0]=> ...
Nitesh Kumar  Singh's user avatar
2 votes
0 answers
598 views

removeItemByKey not working in product collection - Magento 2

I have a product collection (\Magento\Catalog\Model\ResourceModel\Product\Collection $collection), I try to remove some of the item from the collection by using below code. foreach ($collection->...
Bilal Usean's user avatar
  • 9,977

1
2 3 4 5
8