Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
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
24 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
24 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
24 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
18 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
52 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
81 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
21 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
52 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
42 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
9 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
29 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
56 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
18 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
21 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
12 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
47 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
44 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
68 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
20 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
49 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
36 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
34 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
40 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
522 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
20 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
16 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
48 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
21 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
23 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->...
0
votes
1answer
33 views

How to modify a protected variable $items in magento collection

for some reasons I need to alter the $_items array from the class Magento\Framework\Data\Collection That variable is set as protected, so as,if I try to do something like this $this->_collection-&...
0
votes
1answer
37 views

I have no idea why my Subscriber Collection Factory is not working

I have no idea why my Subscriber Collection Factory is not working. Below is my code. Wish someone can help me to fix my problem. I believe something wrong with my setup of CollectionFactory use ...
0
votes
0answers
8 views

Load latest widget per type

I've created programmaticaly a Widget. Then I've created the widget in the backend (widget 2 => Marketing). Based on my user attribute, the widget should switch between 2 and 3 (which I have not ...
0
votes
3answers
47 views

I have below sql query, how do I turn this to Magento get data method to retrieve data?

I have below sql query, how do I turn this to Magento get data method (collection?) to retrieve data (not using ObjectManager)? Please help. public function getNewCustomer() { $objectManager = \...
0
votes
1answer
29 views

How to get subscribers collection in Magento 2.3

I'm trying to get the collection of subscribers but can't find how to do it in Magento 2, the ones I found were about 1.9. Is there a way to get it just like the users? I've tried <?php namespace ...
0
votes
0answers
64 views

How can I write custom query in magento in magento 2 format?

// SQL QUERY SELECT*, ( ACOS( COS( RADIANS( $clat ) )* COS( RADIANS( lat ) )* COS( RADIANS( lng ) - RADIANS( $clng )) +SIN( RADIANS( $clat ) )* SIN( RADIANS( lat ) ))* 6371) AS distance_in_km FROM ...
0
votes
0answers
80 views

Custom module column in sales order grid with select filter in magento 2

I have a custom module with the columns id, order_id & reason. Now I want to add the reason value in the order grid with the select filter. Reasons are listed in the other table of the custom ...
2
votes
0answers
126 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 ...
0
votes
2answers
67 views

Magento 2 - How to properly load quote model by quote id?

I used to load the quote like this: $quote = $this->quoteModel->load($quoteId); But now I get a warning in PhpStorm saying that this method is deprecated: Deprecated: 100.1.0 because entities ...
0
votes
0answers
20 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
2 3 4 5
33