Questions tagged [collection]
Questions related to Magento collections
1,659
questions
0
votes
0
answers
11
views
How do I add a custom filter to layered navigation?
I need to add a new filter to this menu
Filter items should be active categories that are not in the menu. I plan to get them this way:
public function getCategoryCollection()
{
$...
0
votes
0
answers
10
views
Magento 2 Graphql: custom filter products not working
I want to add a custom filter (Stock status filter) to products like this one but it's not working.
How to filter product collection with default graphql products query in Magento 2
I used XDebug to ...
1
vote
1
answer
46
views
Magento 2 : Get collection of based on field
Here is the collection I have as an output :
Array
(
[0] => Array
(
[item_id] => 1
[rma_id] => 1
[product_sku] => 24-MB02
[...
0
votes
1
answer
46
views
Magento2 collection not get set
I have added following code to change the collection. The issue is that when I print the sql query then I am getting correct result(in mysql ) but after that when I print getData on collection then ...
0
votes
0
answers
51
views
Product Collection With Duplicates (On Purpose) For Admin Grid How?
I need to load a product collection that has repeated products in it. I get this error when trying to load a product collection with repeated products:
Item (Magento\Catalog\Model\Product\Interceptor) ...
0
votes
1
answer
35
views
Product collection join with custom table undefined column
I am working with some product collection join with custom table, I've a custom product attribute, need to add a join condition with the product custom attribute with the custom table attribute.
The ...
0
votes
1
answer
21
views
How to get all Products of all Websites/Stores?
I tried getting all products of all websites via the ProductCollection like this:
$stores = $this->storeManager->getStores();
foreach ($stores as $store) {
try {
...
0
votes
0
answers
37
views
How to update table with model collection
I am trying to update the customer_entity table. But I am doing a left join with customer_address_entity.
I want to update the group_id only when store_id matches my customer variable.
Is this ...
1
vote
0
answers
85
views
How to set an Active filter as default and clear it if we needed in admin UI component grid
I have tried 3 different ways to set a default filtering option(set entity value as current customer entity value) to my custom module's grid.
1.using _renderFiltersBefore()
protected function ...
0
votes
1
answer
19
views
Where should I connect model-data-access?
I am building a custom feature to create lists of favourite products.
For this purpose I have created 2 models: The actual list-entity and a model representing information about a single product.
For ...
0
votes
2
answers
69
views
How can I add virtual column to collection?
I have a output structure of $collection like this:
I have array with sample data:
$arr = [
'id_1' => 10,
'id_2' => 30,
'id_3' => 20
]
I need add $arr to above collection and ...
0
votes
2
answers
65
views
Convert Array to Magento2 Collection
I am converting an Array to Magento2 Collection
$items = $this->getItems();
$collection = $this->collectionFactory->create();
foreach ($items as $item) {
$...
0
votes
1
answer
28
views
Database loading Product Collection slow (Minutes)
I've got some third party code here that loads a larger product collection. It takes around 9 minutes to load on decent hardware. We have some 150000 SKU in the database.
Collection:
SQL is:
SELECT ...
0
votes
1
answer
18
views
difference between collection and repository in magento 2
I am not understanding the concept
difference between collection and repository in magento2 and which is better to use.
your help will be able to appreciate.
0
votes
0
answers
22
views
Magento 2 - Get random results with Elasticsuit Catalog Fulltext Product Collection
I am using a Magesuite module to get a product collection, and among other things I want to randomly select a certain number of products, fitting of course some criteria set with filters.
The ...
0
votes
1
answer
23
views
Extending custom interface and data model
I have successfully created a custom interface.
My model: app/code/Vendor/Samples/Model/Orders.php
class Orders extends \Magento\Framework\Model\AbstractModel implements OrdersInterface
{
...
0
votes
1
answer
18
views
Magento2: How to add data in child table?
I have a custom module with named A and db tab is z ok.
now question is my:
How to add child table? which is already I have done with PK and FK key constrains.
How to add data in created child table ...
0
votes
0
answers
28
views
Sort order collection based on a custom product attribute
I am trying to sort an order collection (\Magento\Sales\Model\ResourceModel\Order\CollectionFactory) based on custom product attribute data for the product items in the order. It is ok just to sort ...
0
votes
3
answers
69
views
Collection does not return the intended results
I am working with the collection from a module trying to return specific information. The database has several columns but I only want 2: "region_id" & "default_name". But, ...
0
votes
1
answer
31
views
How to get custom attribute value in after product collection load in Observer
I want to get multiple select type custom attribute values in product collection observer,
I have tried with some events catalog_block_product_list_collection, ...
0
votes
0
answers
5
views
Filter admin listing collection
I have a custom entity listed by ui component. By default it loads the entire collection as shown in every tutorial as the virtual type is just an alias for the current collection.
<type name="...
0
votes
0
answers
24
views
Join a field to customer collection and filter on joined attribute? Attribute Name is Invalid Error
Would like to add a last order date field to a customer collection and have done so like below which seems to work:
$collection = $this->_customerFactory->create()->getCollection()
...
0
votes
0
answers
37
views
Magento 2 - Get order collection of current month and placed by new and older customer
I want to get the two order collections by new and older customers for the current month.
Please suggest the proper way, I just want the count of orders, Not need all the details of an order.
Thanks ...
0
votes
1
answer
21
views
Magento 2 Product grid collection filtering on programmatic Qty column values
I am programatically updating the qty column values for configurable products.
Sadly, the grid filter for this column doesn't work with new values.
The underlying catalog product collection joins with ...
0
votes
0
answers
109
views
Magento 2 - Extending cataloginventory_stock_item table
I want to extend the cataloginventory_stock_item with one more column, so that I would be able to show this data in a Catalog Products grid.
I've read that in order to properly extend the core Magento ...
0
votes
2
answers
138
views
Magento 2.4, How to load multiple category data by array of category ids?
In Magento 2.4, I need to load multiple category data. How to load multiple category data by array of category ids?
0
votes
0
answers
28
views
Retrieving product collection with all possible data in one call
I'm building a custom API endpoint that produces a product data dataset for a custom front-end application. All works fine, but I want to optimize the code because I still have multiple database ...
1
vote
1
answer
461
views
Magento 2: Graphql Custom collection data returns null
I'm creating Graphql for my custom module, but after
setting an endpoint and writing a query for it, does not return
any data.
Below are the files I have created for Graphql,
MyVendor/RMAModule/etc/...
0
votes
1
answer
24
views
How Can get the collection catalog_product_entity_tier_price
I want to get the collection of this table how can I do it???
catalog_product_entity_tier_price
0
votes
0
answers
8
views
magento 2.4 create a new object from joining collections
I need to show a product list filtered by some customer' and products' data. There are a couple of ways I was able to achieve this:
By calling each collection separately
$customerId = 1;
$...
1
vote
2
answers
156
views
Filter product collection for only products that have the image
I need to remove products from the collection that have no image. Even if they have the placeholder image I want them to be invisible.
The module code I use is this
<?php
namespace Smartwave\...
0
votes
1
answer
98
views
How to get the size of a collection without loading the full collection in Magento 2
I need to check the number of items in a collection without loading the full collection (as it has over 1.5 million items and causes memory issues).
Is there an efficient way to go about this?
0
votes
2
answers
107
views
Apply "OR" condition in Order Collection in Magento 2.4.3
How to apply "OR" Condition on Order Collection ??
Example:-
I want to filter order collection on these 4 date on order collection.
November 27, 2020
November 29, 2019
November 23, 2018
...
0
votes
1
answer
163
views
Proper way to mock a collection
I've asked this once already here: How to properly use getCollectionMock
But that was for a different reason, and in the meantime the Magento\Framework\TestFramework\Unit\Helper\ObjectManager is ...
0
votes
0
answers
44
views
How to get the attribute options on category page header as list in magento 2
I want to show all available options of attribute size in Magento 2 as a list on the category page.
This will show only the available product size, which has stock like Magento 2 layered navigation.
...
0
votes
0
answers
58
views
Magento 2 UI Component grid collection filter
I want to filter grid collection based on Role Permission that which website is assigned to the admin role.
<argument name="data" xsi:type="array">
<item ...
0
votes
1
answer
80
views
Magento 2 CategoryFactory exclude current product from collection
I am using an extension auto-selecting related products from the same category. However, I want to exclude the current product from that list which is not really working.
protected $_categoryFactory;
...
0
votes
1
answer
713
views
Magento 2: Get Product Collection With Multiple SKUs Filter
I'm trying to get product collection with multiple skus filter, don't know what I'm missing or doing wrong:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$...
0
votes
0
answers
17
views
Best Practice: Load Objects vs Join Tables?
I'm working on a Magento2 module where I need to collect order data for, let's say 1 - 20 orders.
At this point I wonder if it's:
A good approach to collect the order ids of the required orders and ...
0
votes
1
answer
52
views
Get Latest Entry For Duplicate Rows In Collection
I currently have a logs table which has the following rows which use the same order_id:
log_id
order_id
user
action
2410
1001318004
test1
Declined
2409
1001318004
test1
Declined
Inside my app/code/...
0
votes
0
answers
78
views
How to get data from Catalog_product_entity_int Via Product Collection?
I am trying to get the result of this query
select entity_id, value
from catalog_product_entity_int
where attribute_id = 191
AND value = 3;
is it possible to get the results of a query like this ...
0
votes
0
answers
14
views
Using layer navigation : filter breaks current localisation
Here are some specs :
Magento 2.4.2
Argento Home Theme (Swissup)
Localization : fr_FR
Store code url : none (so the fr codde isn't in the url)
On a category page, using the layer navigation for ...
0
votes
1
answer
37
views
Magento2 Product Collection Observer only changes one page at a time
In ListProduct block Magento is using initializeProductCollection() to initialize the collection.
While initializing it dispatches event catalog_block_product_list_collection as follows.
$this->...
0
votes
0
answers
25
views
Magento 2: Custom Product List Not Rendering
I'm using Magento 2.3.4, I have a page to view all sellers product list, but when I hit button to display product list, It shows a page like this:
I checked exception.log and found this error:
main....
1
vote
2
answers
178
views
magento 2 how to get cms blocks toOptionArray
<?php
namespace [Vendor\Module]\Model\System\Config;
use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
use Magento\Framework\Data\OptionSourceInterface;
class CmsBlocks implements ...
0
votes
2
answers
41
views
Magento 2 applying filters to collection reflects in all phtml
I have applied a filter in a PHTML that loads in headers. The filter is below.
In Constructor:
\Magento\Catalog\Model\ResourceModel\Category\Collection $collection
Block Code:
public function ...
0
votes
0
answers
27
views
How to create Admin grid of Category same as Product Grid?
I want to display Admin Grid for categories same as Product Grid without using UI Component. I am trying to get Collection of category using below code in _prepareCollection method inside Grid.php of ...
0
votes
1
answer
46
views
how do I retrieve a list of order states
I'm looking for a way to fetch all possible order states in Magento 2. I found a way to fetch all Order Statuses but there doesn't seem to be a collection for order states.
Any ideas on how to ...
0
votes
0
answers
504
views
How to use custom collection class as data provider in Magento 2 for grid?
I have added a custom data provider in Magento 2. I can see the data in grid. Though when I try to export the data in csv format, it says
Error: Call to a member function setCurrentPage() on null
...
0
votes
0
answers
10
views
Magento 2 | Enable filters on collection factory programmatically
In my phtml file that I recalled in a cms page I took the entire collection of products, filtered it and finally recalled it.
Everything works fine but I can't get the navigation filters like they are ...