Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
0
votes
0answers
6 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 ...
0
votes
0answers
10 views

Magento 2 | Add Filters of Layered Navigation to custom collection

I asked this question because I would like to explain myself better. In my CMS page I have recalled my custom collection in this way: $blockProductColl = $block->getLayout()->createBlock(...
0
votes
0answers
15 views

Add default date from filter to UI Component grid in Magento 2

I have a custom grid created in the backend for a Magento 2.4.1 instance. Everything is working properly (filters, sorting, etc.), but I have one more request that seems to be more complicated. I have ...
0
votes
0answers
27 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\...
0
votes
0answers
22 views

How to get the updated customer record in magento 2

I am trying to fetch the customer record which is updated. Customer update implies both customer entity as well as customer's address. I am relying on the updated_at column which technically says that ...
0
votes
0answers
32 views

Filtering product collection by custom attribute by overriding $layer->getProductCollection();

I created a module and a new block so that I can overwrite \Magento\Catalog\Block\Product\ListProduct. My catalog consists of configurable products, and I need to filter based on attributes assigned ...
0
votes
1answer
14 views

Collection DataProvider - Strange behavior

I've been killing for hours and no result. I don't understand this strange behavior, can anyone please explain this to me? It's unbelievable ... Thanks for All!!! $this->collection = $Collection; $...
2
votes
1answer
27 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\...
0
votes
0answers
18 views

Magento 2 - Pagination not refresh cache

I'm on the category page. When I click on the pagination number, for example the number 2 with the link "www.magento2.com/category?p=2", I see that when clicked the page is never completely ...
0
votes
1answer
36 views

Get the average price for product collection

If there's a way in Magento 2 to get the average price for a product collection. Or should I loop over the collection? Thanks
0
votes
1answer
38 views

How can I insert multiple row at once without for loop using collection in Magento 2?

I want insert multiple record without for loop in Magento 2 my data is as follow, Array ( [0] => Array ( [path] => whatsapp_contact/whatsapp_contact_button_settings/...
0
votes
2answers
26 views

Memory exhaust when using custom module collection

I'm trying to create a custom module with the usual model, resourcemodel and collection. My problem is that whenever I try to use the collection, magento runs out of memory. The collection only has ...
0
votes
0answers
35 views

Collection getSize() returns weird data [duplicate]

Well, here is getSize() definition inside AbstractDb class public function getSize() { if ($this->_totalRecords === null) { $sql = $this->getSelectCountSql(); ...
0
votes
1answer
27 views

Magento 2 | Exclude duplicate Item ID from a collection before foreach

When I foreach my collection filtered by tier price, qty and customer group I get the error: "Item (Magento \ Catalog \ Model \ Product \ Interceptor) with the same ID already exists". This ...
0
votes
1answer
28 views

Magento 2 | Item with the same ID already exists when join tables

In my class I have filtered my collection by tier price and quantity. If I put the display of only 3 products the code works, while if I set the display for all products I get this problem: Item (...
0
votes
1answer
23 views

Magento 2 | Join table catalog_product_entity_tier_price to collection

I'm trying to filter my product collection by tier price. I currently have this code but it doesn't work and it returns error: protected $_productCollectionFactory; public function ...
0
votes
2answers
164 views

Magento 2.4.1 Layered navigation with custom product collection

I want to override category product collection on the category product page in front-end. I want to show collection according to attribute set. After customize collection layered navigation product ...
0
votes
1answer
21 views

SQL Syntax error when getting collection on listing

I've created my own module for managing leaflets in home page and i wanted to have a listing with existing leaflets. I've created UI_Component for listing (by Magicento) but when I go to listing page ...
1
vote
1answer
83 views

Why does it matter in which order I add attributes to a filter?

Compare this code $productIdQuery = $this->productCollectionFactory->create() ->addAttributeToSelect('customer_group') ->addAttributeToFilter([ ['attribute' ...
0
votes
1answer
28 views

Get specific columns from Left Join

I am trying to join two tables like below $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $collection = $objectManager->get('Advance\Module\Model\Method') ->...
0
votes
2answers
24 views

Magento 2 - How to get Addresses collection

In Magento 2, I try to get addresses collection from table 'customer_address_entity', filter by updated_at field. I know I can get addresses for customer with this : $customer = $this->...
1
vote
6answers
58 views

Filter collection with OR of AND condition

I want to filter a product collection with pairs of attributes match. For example get product collection which has (brand="Toyota" AND color="Red") OR (brand="Ford" AND ...
1
vote
1answer
54 views

How to add columns to customer address grid in admin?

I have to add two fields to the customer's address grid, for this I have to add a left join to the Magento collection. I have created the following custom module: Vendor/Module/registration.php <?...
0
votes
0answers
10 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/...
0
votes
1answer
30 views

How to set the conditions for displaying of the related-products

Overriding related-product collection. My aim is to set limit for related product display. Related-products are not displayed if there are less than 10 products, the maximum number of products that ...
1
vote
2answers
58 views

Magento 2 Remove configurable products from product listing page programatically

I am trying to remove configurable products from product collection, as a result products are being filtered correctly but pagination is not working as expected and showing wrong count. For example ...
0
votes
0answers
19 views

Not able to add filters on getItemsCollection in admin order page

I am implementing a feature, where I need to filter the order item list in order admin page. I have checked and found the list is getting from method getItemsCollection(). But when I am trying to ...
0
votes
1answer
25 views

How to find what collection used in particular section in magento 2

I want to get particular section collection which is already rendered in Magento 2 website I need collection for my another phtml file, how to get the collection?
0
votes
0answers
16 views

How to use 2 models in layout folder in xml that should show in inside view show.phtml file. Please tell how the controller is linked with block

How to use 2 models in layout folder in xml that should show in inside view show.phtml file. Please tell how the controller is linked with block. And how a layout file is linked with the controller ...
0
votes
1answer
22 views

Magento 2 order by product options

I am getting product options by using below code. $customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product); Now I want to sort them in ...
0
votes
1answer
13 views

Show Categories Filter with Custom Attribute

I have to get the list of categories those have a specific attribute assigned, So to achieve this i have created a custom attribute boolean type like this: public function install(...
1
vote
1answer
32 views

How to add AND OR AND conditions in a product collection?

ORIGINAL POST Comment ajouter des conditions ET OU ET dans une collection de produits? comment pourrais filtrer une collection de produit par: (attribut A : condition A And attribut A : condition B) ...
0
votes
1answer
49 views

Optimize Product Collection Filter

I have a Model in my code that creates a custom product collection based on a user search term. That search term should search products and filter it by sku or name... The issue is that it takes too ...
0
votes
1answer
65 views

Magento 2: Sort category page collection by custom attribute

I need to sort the product collection in category page by a custom attribute inventory_status. The attribute is of type int. I need to add the sort with the existing sorting applied. For example, if ...
1
vote
0answers
90 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 ...
0
votes
0answers
23 views

Store Filter on Category Collection Not Working

Have just noticed that a function is pulling categories from any store. I used the below setStore() method thinking this would limit the scope of categories returned to just the current store however ...
1
vote
2answers
91 views

Magento 2 : How to get category data by category id?

I have product object & i get category ids using $category_id = $product->getCategoryIds(); I need the collection for the category ids which i get in $category_id What will be the best & ...
0
votes
0answers
30 views

Why code different behaviour of Scheduled cron and command in Magento2

Following code I'm using for low stock mail for store wise in daily. $collection = $this->lowStockFactory->create() ->joinAttribute('name', 'catalog_product/name', 'entity_id',...
0
votes
0answers
43 views

Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory not work in observer

$category = $this->categoryFactory->create()->load($categoryId); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $collection = $objectManager->create('Magento\...
1
vote
1answer
36 views

What is the difference between Collection & Repository & Factory classes?

I am trying to understand when to is use which according to the best practice. for exg. To get some data like (product,customer) what should be used Collection ? To set some data into product etc what ...
0
votes
0answers
7 views

Magento 2 getSelect with columns only showing one record in admin grid

I have a collection like below. protected function _initSelect() { $this->addFilterToMap('entity_id', 'main_table.entity_id'); $this->addFilterToMap('increment_id', 'main_table....
0
votes
2answers
48 views

Get order collection past one hour completed orders magento 2

How to add filter last past one-hour completed orders collection in Magento 2? $searchCriteria = $this->searchCriteriaBuilder ->addFilter('is_process', $isprocess) ->...
1
vote
1answer
697 views

Magneto 2.4.1 Collection: __construct() must implement interface Magento\Framework\DB\Adapter\AdapterInterface

I have a custom module with a few tables. I have the model, resource model and collection classes in place. If I try to access the contents of the table, I am getting this error Type Error occurred ...
0
votes
0answers
24 views

How can I customize the filter of the product grid on the admin side in order to filter by RANGE

hope you are all good and in great shape. TLDR: How can I filter my product grid on the admin side using a WEIGHT RANGE? I am a newbie in Magento and I have been doing some progress over the last ...
0
votes
0answers
14 views

Magento 2 Admin grid requires setup:upgrade for changes

I have an admin grid with a custom collection but changing database name requires setup:upgrade and setup:di:compile for changing in admin grid.
0
votes
0answers
19 views

Cannot Assign Param Value in Model Collection. Magento 2

I'm currently Facing a really strange Issue I'm applying filter on my custom table data in grid by adding function Vendor/Module/Model/ResourceModel/Withdrawal/Grid/Collection.php protected function ...
0
votes
1answer
32 views

Unique Products in Product Collection Filtered with Category Array in Magento 1.9

I have tried below 3 method but it is not giving correct products as per cateory id array. First Way $_productCollection = Mage::getResourceModel('catalog/product_collection') ->...
0
votes
1answer
58 views

Magento 2.4: How to get the Invoice Collection of Logged In Customers?

I have to show the invoice collection of logged-in customers in the frontend. I have referred this link how to get current login customer invoice list and shipments in magento 2? invoice-list-and-...
0
votes
1answer
25 views

How do I change this sql query to Magento2 filter collection method?

I have below query SELECT * FROM newsletter_subscriber WHERE change_status_at >= (NOW() - INTERVAL 10 DAY); How do I make it works with below? public function getSubscriberStatus() { ...
0
votes
0answers
26 views

Product collection and Product Repository return different results

I am a little confused about the difference between getting products by Collection and use de Repository. Right now, in one project, if I run this code: $collection = $this->_productModel->...

1
2 3 4 5
33