Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
6answers
42 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 ...
0
votes
1answer
32 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
6 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
28 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
52 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
16 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
24 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
15 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
20 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
31 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
45 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
33 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 ...
0
votes
0answers
29 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
13 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
33 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
29 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
31 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
31 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
35 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
2answers
284 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
18 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
11 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
31 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
36 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
18 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
21 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
36 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
26 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
34 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
96 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
34 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
18 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 ...
0
votes
0answers
12 views

can't display the product's name after addAttributeToSelect

I have a table and this table will display the product's name, image, sku, category,and stock. when I use $products = $this->_productCollectionFactory->create()->addAttributeToSelect('*')->...
0
votes
0answers
11 views

Collection join to diffrent databases table

My Magento project has 2 connetions: default,whmanager. $joinConditions = 'main_table.product_id = catalog_product_entity.entity_id'; $collection->getSelect()->join( ['...
0
votes
0answers
20 views

Rewriting collection function in Magento 2 - no results are returned?

I am rewriting a Magento 1 function for Magento 2. See 2 comments in the code for details please. This is the Magento 1 version: $this->_optionValueTable = Mage::getSingleton('core/resource')->...
0
votes
1answer
45 views

Magento2: filter product collection by custom attribute

I am using Magento ver. 2.3.6. I want to filter product collection by custom product attribute and I am using below code:- di.xml <?xml version="1.0"?> <config xmlns:xsi="http:/...
0
votes
0answers
11 views

Add boolean value of false/0 where order exists in sales_order but not custom table

The code below I am adding my custom column to the sales_order_grid table. The problem is it only adds the values where order_id in my custom table exists. How can I add the value of false or 0 to ...
0
votes
1answer
28 views

How to filter category with custom attribute Magento 2

I added a custom category attribute type yes/no like this: In eav_attribute table: the problem is when i filter follow this attribute it return empty array: $model = $this->categoryFactory->...
3
votes
1answer
27 views

Magento 2 - How to know all valid attributes to use in addAttributeToSelect?

I often see code like this where the developer just inserts * into addAttributeToSelect("*") instead of selecting only the necessary attributes. public function toOptionArray() { $...
0
votes
0answers
40 views

Using foreach change the position of my product collection

The best way to explain this issue is showing an example: In the product list.phtml I had the following <?php $logger->info($_productCollection->getData()); foreach ($...
0
votes
0answers
21 views

Optimize grid collection for huge data set Magento 2

I am working on creating an admin grid for sales_order_item table. There are probably a hundred million rows in the database and when I use the collection to filter and load data into the grid, it ...
0
votes
3answers
42 views

Magento 2 How to save data to custom column in “admin_user” table

Hi Here I have created a extra column school in the table Admin_user. While I trying to update or save it inside a "PLUGIN" its giving me error. Here is my Plugin code class Adminsave { ...
0
votes
0answers
11 views

I need to get product collection by filter multiple category ids and attributes in magento 2

I need to get product collection by filter multiple category ids and attributes i tried below ways $prodColl = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); ...

1
2 3 4 5
33