Questions tagged [collection]

Questions related to Magento collections

289 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
1answer
492 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
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
435 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
1answer
843 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
1answer
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 ...
4
votes
0answers
144 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
369 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
63 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
189 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
207 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 foreach to loop through either of the collections the page displays the collection correctly. However, ...
3
votes
0answers
75 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 ...
3
votes
0answers
121 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('...
3
votes
0answers
55 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
0answers
309 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 ...
3
votes
1answer
348 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
480 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
397 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 ...
2
votes
0answers
8 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
25 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
27 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
93 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
171 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
0answers
33 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->...
2
votes
1answer
244 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
67 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
418 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
210 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 ...
2
votes
0answers
246 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
884 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
242 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
63 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
204 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
511 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
192 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
596 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
71 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
318 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
219 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
367 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
100 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
93 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
2k 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 ...
2
votes
0answers
32 views

Move all native magento reviews from my default store 0 to my new store

My script currently works for all stores except the store it's pulling from. I want to pull all reviews from my default store / main store and only push the reviews to my new store with a websiteId = ...
2
votes
1answer
3k 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 <...
2
votes
1answer
597 views

Product filtering with multiple attributes

I want to display all the product with some product attribute features. ie; I have 3 products in kids category with attributes and categories like Category: boy and girl Size: small, medium,large ...
2
votes
1answer
275 views

Supplier is not being shown in Grid Filter in catalog product grid

I have copied file app\code\core\Mage\Adminhtml\Block\Catalog\Product\grid.php to app\code\local\Mage\Adminhtml\Block\Catalog\Product\grid.php and have added some extra column like Special price, ...
2
votes
0answers
115 views

Trouble fetching current product collection for category without limit

Within my templates category list.phtml I need to pull the full product collection without the page limit. To be clear I do not want to impact the toolbar, pagination, or anything else within category ...
2
votes
0answers
177 views

Excluding products from layered nav filters

In my product collection on category list pages I am filtering to exclude products with certain attribute sets: return $this->_productCollection->addAttributeToFilter('attribute_set_id',array ('...