All Questions
Tagged with collection magento2
180 questions with no upvoted or accepted answers
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-...
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 ...
4
votes
1
answer
689
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
2
answers
2k
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
0
answers
204
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
0
answers
193
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 ...
3
votes
0
answers
280
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 ...
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->...
3
votes
0
answers
639
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
0
answers
443
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\...
3
votes
0
answers
469
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
0
answers
120
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
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 ...
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\...
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 ...
3
votes
0
answers
633
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?
...
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\...
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
<...
3
votes
1
answer
2k
views
Magento2 how to override collection
I want to build a grid that show information from "directory_country_region" table but show only for "country_id" with id = "TH".
I'm using UI component & Magento\...
2
votes
0
answers
110
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 ...
2
votes
1
answer
1k
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\...
2
votes
0
answers
316
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 ...
2
votes
0
answers
407
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 ...
2
votes
1
answer
128
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();
$...
2
votes
0
answers
163
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 ...
2
votes
0
answers
486
views
Function removeAttributeSearch
I have a code:
$productCollectionClone = $productCollection->getCollectionClone();
$collection = $productCollectionClone->removeAttributeSearch($attribute->getAttributeCode());
Anyone can ...
2
votes
1
answer
496
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-...
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 ...
2
votes
0
answers
655
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
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;
...
2
votes
1
answer
432
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
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. ...
2
votes
1
answer
2k
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
0
answers
169
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
3
answers
8k
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($...
2
votes
0
answers
629
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
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]=> ...
2
votes
0
answers
612
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->...
2
votes
1
answer
2k
views
Magento 2.2 : Search Functionality/Layered Navigation on a Custom Product Collection?
I use a custom product collection which is used on all category view pages (basically, instead of using Magento's collection, I wrote my own module with the custom collection to implement a cookie-...
2
votes
0
answers
819
views
How to change the category collection before load?
I'm trying to figure out how to change the category collection before load.
To be more specific, I've created a category 'Sales'. The category is empty with no products. I want to automatically add ...
2
votes
0
answers
97
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
2
answers
98
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 ...
2
votes
4
answers
3k
views
Magento 2: add fields to products collection
Ok so I'm trying to implement a simple export to CSV massaction on the Magento 2 Catalog products grid.
I've successfully created the mass action item, as well as the admin controller.
I am able to ...
1
vote
0
answers
168
views
Magento 2: How create ui grid filter for null values in specific column
I have a column "purchase_point" in my table. It has 3 values android, ios, and null.
I need to display it in the ui grid. For the null value, I need to display 'web'. I am using the below ...
1
vote
0
answers
396
views
Magento 2 override resource model collection not working
I want to override Magento Reports module and it's not working. here's my code :
di.xml
<preference for="Magento\Reports\Model\ResourceModel\Report\Collection" type="SZK\Shamsi\Model\...
1
vote
0
answers
453
views
does not extend \Magento\Framework\DataObject custom Model
Here's my code
when I try to make the collection with my custom model I have this error
In Collection.php line 612:
Easysoft\Logistic\Model\Tracking does not extend \Magento\Framework\DataObject
app/...
1
vote
0
answers
68
views
Memory leak when using OrderItemCollection
I'm trying to execute some backend logic via ajax that requires using the Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory collection factory.
When I use ->getColumnValues('<some ...
1
vote
0
answers
92
views
Magento 2.3.5 : How to remove specific product from recently viewed product list
I have display recently viewed product slider on product page using Magento default widget. But, I want to remove product from recent viewed product collection.
How to remove that?
Any help would be ...
1
vote
1
answer
3k
views
Magento 2: Product collection filter with custom attributes with like
I am using magento 2.3.3 i have custom module in that i am using search when any one search i am filter products name like it is working fine but now i want add extra attributes.I have created product ...
1
vote
1
answer
275
views
Magento 2 print phtml product collection
When I try to get product list in a controller for a ajax module like this :
echo $this->layoutFactory->create()
->createBlock('\Magento\Catalog\Block\Product\ListProduct')
...