Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
6
votes
1answer
487 views

When do I have to use load() on collection

I can meet many different approaches when using collections in Magento 2. Rarely, but sometimes I see that functions load() is used. Although without it there is no problem with accessing collection ...
6
votes
3answers
3k views

magento 1.9: How to load customers by mobile number [duplicate]

I want to load customer and get his data from telephone number we have load() methods, to load customer by id as well as we have loadByEmail() to load customer by Email but i want to load customer by ...
6
votes
2answers
4k views

Get Website ID from Website Name

As the title says. I don't want the ID of the current website, I want the ID of any website by supplying only that websites name. I have this code: $siteModel = Mage::getResourceModel( 'core/...
6
votes
1answer
3k views

Magento aggregate and between collections?

1) How to write the below SQL query in Magento collection : SELECT * FROM 'table1' WHERE active=0 AND '2014-07-08' between 'not_available_from_date' and 'not_available_to_date' 2) Also how to write ...
6
votes
2answers
249 views

Empty Collection :: CollectionFactory Approach and getCollection approach both give empty result

Magento 2.3.1 Php7.2 Ubuntu 18.04 I have created a table in my database using db_schema.xml and then populated that table with sql insert commands directly in mysql workbench. My model code is &...
6
votes
3answers
1k views

Magento getFirstItem and getLastItem not working on collection

My code is as below but it won't work with loading first or last item. $shipidarr[0] = 100007536; $shipModel = Mage::getModel('orderstatus/orderstatus')->getCollection(); $shipModel->...
6
votes
1answer
4k views

$item->getSku() and $item->getProduct()->getSku() return different values. Why?

Edit: originally this question was just about sales/order objects but I've found an identical problem with sales/quote objects too, so I'm editing it to include that. I also added a TL;DR at the ...
6
votes
2answers
707 views

Product collection by non-existing images

I want to create a collection of all the products without a image and set them do the status "disabled". Because i use a automatic import script there are some products that HAD images before, but ...
6
votes
3answers
2k views

Product load event - regardless of context

Is there a single event that I can create an observer for that gets fired when a product is loaded either using getModel or through a collection? The exact use case i have is that i have a custom ...
6
votes
3answers
5k views

Magento 2 - Layered Navigation for Custom Product Collection

I created a CMS page for products that contain a certain attribute (On Sale Items). I extended the ListProduct class and added filters to the product collection to achieve the desired results. (...
6
votes
1answer
1k views

Magento2.2 getCollection from Factory deprecated

I get in my editor (PhPStorm) on getCollection the message that it is deprecated. In my controller i got the function public function __construct( Registry $registry, ...
6
votes
2answers
2k views

Magento 2 get out of stock products in collection

I am trying to get all the products from the collection(both in stock and out of stock) but with no luck at all. The setting on admin needs to hide the out of stock products from frontend but I want ...
6
votes
1answer
518 views

How can I get only the Store View attributes, without the inherited Global data? I only need the diffs

I'm using the internal Magento APIs to get the product data on a store view level. I only want to get the values that are on that store view level, not the global values that in inherits. But it ...
5
votes
4answers
6k views

Fetch value from collection without foreach loop

I have a custom collection $someCollection = Mage::getModel('mymodule/mymodel')->getCollection() ->addFieldToSelect('some_field') ->...
5
votes
3answers
3k views

How can I load the product collection without some products?

Actually, I want to load the product collection except for some products. I have the product ids that I don't want in the collection. For example, the product ids that I don't want in the product ...
5
votes
1answer
2k views

Find value in comma separated string column through query

I have a field inside a table that contains a string made of the country codes:IT,GB,US,DU,... and I need to check if the customer's country (GB,IT,..) is inside this string. I know I can use ...
5
votes
5answers
9k views

Magento : Filter Collection by Attribute that Doesn't Exist or Null or another condition

I have created a new product eav attribute, assume it is created correctly. Now I write something in this attribute in some products (5 for example), and I delete it from some of them (4). So this ...
5
votes
5answers
4k views

Magento 2 - Limit reviews shown on product page

I'm looking for some help with limiting the review list on the product page to 5 reviews at a time. I'm using Magento 2.0.7 and Porto 2.2.1 I found some suggestions on here but they were for Magento ...
5
votes
3answers
16k views

Magento collection where (a AND b) OR (c and d) [duplicate]

I have a collection $c. If I write $c->addFieldToFilter('id',array(1,2,3,4)) ->addFieldToFilter('sku',array('a','b','c','d')); The resulting SQL WHERE-part will be: WHERE (((id = '1') OR ...
5
votes
2answers
5k views

Get a Magento product collection without sub-products of configurable products

I want to get a list of all products available in my Magento installation. Currently I am using the following call to filter out enabled products and limit the result set to those products which are ...
5
votes
3answers
8k views

Magento grid default filter condition exclude certain field value

I have a custom admin grid that shows grid data from a custom table. One of the fields in this custom table is "status" which is added to the grid with the following values and function. $this->...
5
votes
2answers
357 views

convert datatype varchar to in magento collection

i have magento collection Mage::getResourceModel('customizebundles/customizebundles_collection') ->distinct(true)->addFieldToSelect('validity') ...
5
votes
1answer
3k views

Filter products by website using AND

In a multistore setup, I need to find products that are assigned to website A and website B. The product collection has a addWebsiteFilter() method but unfortunately it doesn't serve this purpose, as ...
5
votes
2answers
2k views

How to get all values of a given custom attribute?

I have a custom product attribute test_id which is a text field. I want to get all the values assigned to this attribute within a given product collection. I found the following way of doing it. But ...
5
votes
2answers
5k views

Get all item-Ids from a Collection

I found out how to get the first item from a collection: $pageId = Mage::getModel('cms/page')->getCollection() ->addFieldToFilter('identifier', 'your name in the pages') -&...
5
votes
1answer
22k views

Magento join collection query

I have this line: $collection->getSelect()->join( 'sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id', array('telephone','city','postcode','...
5
votes
1answer
4k views

Filter product collection by sku or name

I have a variable which containing value to filter both name or sku, i tried to filter the product collection using this variable like this: $queryName = 'bat'; $category = $this->_categoryFactory-...
5
votes
2answers
5k views

Retrieve all customers data

I want to retrieve all customer data including the address information, customer custom attributes, and customer profile information. Right now i'm using customer model like this: $collections = Mage:...
5
votes
1answer
2k views

magento2 how to sort order of product by price

It my code when I sort product by price but result not show $collection = $this->_productCollectionFactory->create(); $collection->addAttributeToSelect('*'); $collection->setOrder('price',...
5
votes
1answer
1k views

Using observer, how to get the current pager with loaded product collection

Using an observer how can i get the current pager block with its loaded product collection on a category page? I want to check the total number of pages on a category page before it is loaded.
5
votes
2answers
1k views

Join 3 tables in Magento 2

I am new to magento 2, And want to join 4 tables. TABLE 1) market_p_userdata (columns -> seller_id, image) TABLE 2) market_product (columns -> seller_id, magepro_id) TABLE 3) ...
5
votes
2answers
439 views

filtering product collection does not work with command

I face a problem with a collection. I have fresh products that need to be taken out from store 3 days before the expiration date. I created a command that is called by a cron. I've constructed it like ...
5
votes
1answer
3k views

Magento Case Sensitive addFieldToFilter search result

How to get case sensitive search result using addFieldToFilter() of collection object in magento. I want to get search result based on case sensitive search results. Like ABCDE12 is not equal to ...
5
votes
1answer
6k views

Understanding setSelect()->join Need to join two custom collections

I am confused understanding the correct usage of $collection->getSelect()->join(... to bring two custom model resources together. I tried following other examples using the getSelect method. I ...
5
votes
1answer
2k views

How to use NOT BETWEEN SQL with magento collection

Here is my sql query select * from my_table where status = 1 and CURDATE() NOT BETWEEN start_date and end_date I tried the following code but it is giving me wrong answer when both dates are NULL or ...
5
votes
1answer
909 views

Magento Collection Cache

By best practice collections are typically instantiated in a Block. Best practice also dictates that a Block should set a cache tag and lifetime to take advantage of the Block caching mechanism. ...
5
votes
1answer
811 views

Join Collection With Country Table

I have stored country id in my custom table. How to join the my custom collection with country collection to get a Country Name. I have tried below code but its not working : $collection = Mage::...
5
votes
3answers
3k views

Group and/or product collection select

Is it possible to group and/or together when creating a product collection I have 2 attributes size and color. I want to find products that have the following: Size = 10 and Color = red or Size = ...
5
votes
3answers
1k views

Incorrect product count in layered navigation after overriding list product collection

I have customized(override) product list collection getProductCollection and filtered collection as required. public function getProductCollection() { if (isset($this->...
5
votes
1answer
2k views

Magento checking order updated_at using Magento date and time

we are trying to filter out orders that were created longer than 60 minutes ago with status pending. We are having some problems with the date/time functions We tried: - date('Y-m-d H:m:s') and ...
5
votes
1answer
274 views

How is Varien_Db_Adapter_Pdo_Mysql::orderRand() optimized?

Magento comes with a method to randomly "order" collections: $collection->getSelect()->orderRand(); It takes an optional parameter $field, that is eventually used in ...
5
votes
2answers
2k views

How can Set filter collection in custom model by product id magento 2

I want to filter collection in my custom model by product id to load the filter data value in admin grid. My Model:- Vender\Modulename\Model\Outofstock namespace Vender\Modulename\Model; class ...
5
votes
0answers
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 ...
5
votes
1answer
2k views

Grid pagination does not work in magento

Pagination is not working in my grid. All records are being shown on same page. All though Pagination is being shown at the top but all pages shows same records. Here is the code-- protected ...
5
votes
1answer
2k views

FishPig Attribute Splash Pages Extension Bugs [closed]

I'm evaluating the FishPig Attribute Splash Pages extension for a client, and I've run into a few bugs. I've got support requests into the extension vendor, but since it's a free extension I figured ...
4
votes
3answers
15k views

addFieldToFilter() with OR Condition in magento2

$collectionData = $this->_productCollectionFactory->create()->addAttributeToSelect('*') ->addFieldToFilter(['attribute1', 'attribute2'], [ ['in' => $attribute1], ...