Questions tagged [collection]

Questions related to Magento collections

313 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
1answer
518 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 ...
5
votes
2answers
2k views

How can Set filter collection in custom model by product id magento 2

I want to filter collection in my custom model by product id to load the filter data value in admin grid. My Model:- Vender\Modulename\Model\Outofstock namespace Vender\Modulename\Model; class ...
5
votes
0answers
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 ...
5
votes
1answer
2k views

Grid pagination does not work in magento

Pagination is not working in my grid. All records are being shown on same page. All though Pagination is being shown at the top but all pages shows same records. Here is the code-- protected ...
4
votes
1answer
281 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,...
4
votes
1answer
511 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 | ...
4
votes
0answers
88 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 ...
4
votes
0answers
149 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('...
4
votes
0answers
380 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 ...
4
votes
1answer
994 views

How set order with custom field column magento 2

I want to setOrder with custom field column in get list product. I override toolbar.php but it's not working di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
4
votes
0answers
161 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 ...
4
votes
2answers
387 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 ...
3
votes
2answers
70 views

collection, get product image

Sorry for my English I have this code $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('short_description') ->...
3
votes
0answers
37 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->...
3
votes
0answers
229 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 ...
3
votes
0answers
226 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 ...
3
votes
0answers
59 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 ...
3
votes
1answer
395 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']); $...
3
votes
1answer
542 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\...
3
votes
0answers
401 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 ...
3
votes
0answers
390 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? ...
2
votes
0answers
23 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 ...
2
votes
0answers
43 views

How to filter collection for json data field in magento2?

Have any function or way we can directly filter json data in magento2? like: brand: {"product":"test","purchase":"500"} if i want to filter more than purchased 500 times in magento2 have any easy ...
2
votes
0answers
73 views

Function removeAttributeSearch

I have a code: $productCollectionClone = $productCollection->getCollectionClone(); $collection = $productCollectionClone->removeAttributeSearch($attribute->getAttributeCode()); Anyone can ...
2
votes
0answers
10 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 ...
2
votes
1answer
26 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 ...
2
votes
1answer
30 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 ...
2
votes
0answers
194 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/...
2
votes
1answer
207 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 ?
2
votes
1answer
115 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?
2
votes
0answers
155 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\...
2
votes
0answers
36 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. ...
2
votes
1answer
308 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 ...
2
votes
0answers
89 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 ...
2
votes
0answers
540 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. ...
2
votes
0answers
270 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 => [ ...
2
votes
0answers
1k 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 ...
2
votes
0answers
273 views

Join table to get the detail of customer, customer ordered item, and the item product

i'm following this tutorial to create the grid for custom report, and to get the collection there's a function which accept the from date and to date like this: public function setDateRange($from, $...
2
votes
0answers
64 views

Magento2 Custom Module Backend - Pass ID FK from GridView Master to GridView Details

I have to pass a FK parameter from GridView Master to GridView Details. GridView Master (GVM): GridView Details (GVD): PROBLEM: After click on 'Questions' on GVM for ID = 22, in GVD is showed all ...
2
votes
0answers
232 views

convert direct sql to collection in magento 2

How we can convert direct SQL query to collection ? SELECT wk_mpauction_winner_data.auction_id, wk_mpauction_winner_data.customer_id, quote_item.created_at AS quote_item_date ,sales_order_item....
2
votes
0answers
576 views

How to sort products by bestsellers (e.g. by sales) in Magento 2

these days I've faced a problem: I needed to to sort products by sales. So, first of all I decided to add this field to collection of products and the order it using method $collection->setOrder(). ...
2
votes
1answer
197 views

how to append variable in LIKE in SQL Query

I have a SQL query where I want to append $customerID, how to achieve that? > SELECT `e`.*, `at_assigned_campus_manager`.`value` AS > `assigned_campus_manager`, `at_physical_verify`.`value` ...
2
votes
0answers
629 views

Layered Navigation on Custom Product Collection Page

I am developing module "Shop By Brand". So on the Brand details page it's displaying Brand details with Product Collection related to brand. All things are working except "Layered" navigation. I have ...
2
votes
1answer
72 views

how can i add a two year filter to my reports in magento 1.9

I want to add a two year interval filter to customer order by report grid ,but I have no idea about this.Anyone who have tried it please find me a way ,thanks in advance. I found to add code here in ...
2
votes
2answers
343 views

How to add column for total orders in customer grid in magento and filter it?

I am trying to add a total orders of particular customer column in customer grid. It is added successfully but How can I filter it? Code is : protected function _prepareCollection() { $...
2
votes
0answers
230 views

Pre filter datasource for Magento 2 custom grid

I have 2 grid that i want to use in my custom module, the first grid have actions column that have link to access the second grid, the problem is i want to load data in second grid (listingproduct) ...
2
votes
0answers
106 views

Change the sitemap.xml size limit in magento 1.x.x

It seems that Magento 1.x.x. generated sitemap.xml is limited to 10MB. Is there any way to change the limit? I do know that I'll need to split the generated sitemap into smaller chunks after that to ...
2
votes
0answers
94 views

Filter collection in listing Magento 2

I want to add in layered navigation filter by stock. Example: filter by Product in stock Product out of stock Which block or model i must to rewrite?
2
votes
0answers
3k 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\...
2
votes
0answers
43 views

Media image cron upload is failing to upload any images to my simple products

Front image should only load for configs and this works fine. Simples should load front and back and all other angles. It looks for F (front) and B (back), sets those to 1 or 2, everything else is ...