Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
3
votes
1answer
2k views

How to retrieve a customer by phone number?

I need to retrieve the customer object belonging to a certain (mobile) phone number. How can I do this in Magento? And how can I get a customer by phone number when a phone number was entered by end ...
3
votes
1answer
16k views

Product collection filter by stores

How do I filter a product collection so that it includes only products in store 2 that are not in store 3. It can include any other stores as long it is in store 2 but not in store 3. product->...
3
votes
3answers
643 views

Is It Possible to Print the Current Collection's ORDER BY information?

I've created a custom sort module that I'm attempting to debug. I'm curious if it is possible to display this information somewhere in my catalog pages (e.g. app/code/design/package/theme/template/...
3
votes
2answers
1k views

What is different between getCollection(); and $product->getData();

What is different between getCollection(); and $product->getData(); $products_collection = Mage::getModel('catalog/product') **getCollection(); ->addAttributeToSelect('*') ->addFieldToFilter('...
3
votes
3answers
2k views

Random products from same category with parent category fill up

I would like to do following on 1.9.0.1: Getting 12 random upsell-products from same category as current product. They have to be saleable. They shouldnt be in related-products already. They shouldnt ...
3
votes
2answers
2k views

Passing an array from block file to template file

I have a collection of Dealer Stores. I have implemented a function that calculates the distance of all stores from the location of the customer and i have an array of respective distances. I have ...
3
votes
3answers
2k views

Observer for Admin Order Grid

I would like to restrict order based on an Admin user. So for example the admin user would have an attribute that is assigned to a certain region (Group of Zipcodes). When the user logs in they could ...
3
votes
2answers
3k views

Magento Collection Loading Prematurely

I am pretty new to Magento, and am creating a module to integrate third party reviews with a website I am developing. It's all going well, but I've hit a snag, and I'm at a bit of a loose end with ...
3
votes
3answers
938 views

Magento2 Alternate of Method getCollection() which is deprecated

I have checked the similar post: Magento2.2 getCollection from Factory deprecated But I still don't find the answer of it. I am calling getCollection() function, and PHPStorm saying that this ...
3
votes
1answer
6k views

Magento2: Convert DataObject/Array into magento2 Collection?

How to convert the Data object into Magento2 Collection ? In Mage1 we could do as below.. Mage1: $collection = new Varien_Data_Collection(); foreach ($items as $item) { $...
3
votes
1answer
3k views

Magento2 custom collection invalid method exception

I made a custom CRUD Module and when i call the collection without the addFieldToFilter function everything works fine but when i try to filter the collection i get the exception 1 exception(s): ...
3
votes
1answer
5k views

Magento2 - Custom product attribute in product collection

I've created a new product attribute 'brand'. This attribute is within my default attribute set. Now I'm trying to get all brands from a product collection within a category. I'm fetching the product ...
3
votes
2answers
2k views

Convert SQL Select to Magento getCollection statement

I have a complex sql select query that I want to load as collection so as to display the data in a custom grid but I'm not able to convert the query into Magento's equivalent getCollection statement. ...
3
votes
1answer
4k views

Get all active store views domains

How could I get all active domains of current Magento Store? For active store view I can use: $this->getRequest()->getHttpHost() which gives me "www.example.com". But I wan't an array of all ...
3
votes
2answers
8k views

Create magento pagination in custom product collection inside phtml file

First of all, i didn't create custom module to handle this product collection, so, i just put model inside phtml file, i know it's bad implementation, i'm new in magento and i have to do small ...
3
votes
2answers
219 views

UI component Filter with category collection Magento2

I am implementing Grid for categories collection using UI component. I have used the following code Vendor/Module/view/adminhtml/layout/vendor_index_index.xml <body> <...
3
votes
2answers
349 views

Order Items Collection in Order Detail Page

This snapshot of order detail page. I Just want to known that which file or function call for setting this collection in this page. I want to just get Selected (Filter Row) Items Order.
3
votes
2answers
435 views

Magento2 Collection Multiple Columns as OR

I want to do something very simple, have a collection that returns all customers that have a certain string in their name or email. Based on how you can use in, I thought I would be able to do ...
3
votes
1answer
2k views

how to generate and get the coupon code?

$generator = Mage::getModel('salesrule/coupon_massgenerator'); $data = array( 'uses_per_customer' => 1, 'uses_per_coupon' => 1, 'qty' => 1, //...
3
votes
3answers
2k views

Magento Category collection missing custom attributes

I am currently developing for a shop that doesn't use the product page. On every category with sub categories the sub categories are shown until there are no more sub categories, then the products in ...
3
votes
3answers
6k views

How to filter product collection with configurable product attributes

Now I'm trying to filter product collections with my configurable product attribute i.e size $collection = Mage::getModel('catalog/product') ->getCollection() ->...
3
votes
2answers
880 views

Filter collection on same attribute with different values

I want to filter collection for same attribute having two either values. example: ->addFieldToFilter('customer_group_id',Mage::getSingleton('customer/session')->getCustomer()->getGroupId(...
3
votes
1answer
345 views

Check which filters have been applied to a collection

Is it possible to check which filters have been applied to a given collection. For example: $collection = Mage::getModel('sales/order')->getCollection(); $collection->addFieldToFilter('state', ...
3
votes
2answers
3k views

Adding a second product grid in category admin for “featured products”

I would like to add a new category products tab on the category admin page with a product grid same as the default category product grid. The only difference is, i need this grid to save selected ...
3
votes
3answers
747 views

Splitting of entity (products, categories etc.) collections into some equal parts?

does anyone have an idea, how can I split one collection of entities in Magento into three equal independent collections? Following example: $_category = Mage::getModel('catalog/category')->load(...
3
votes
2answers
4k views

How to get collection of invoices of a customer?

I am using below code but it is giving error please help. $collection = Mage::getModel("sales/order_invoice")->getCollection()->addFieldToFilter('customer_id',$customerId);
3
votes
1answer
2k views

Magento Sales quote collection error

I am getting sales quote collection with this reference,,but it throws below error. MyCode Mage::log($item_ids); $collection=Mage::getSingleton('sales/quote_item')->getCollection()->...
3
votes
1answer
874 views

How to use addFieldToFilter() in field generated in sql?

If I try to filter a field in the existing table works, but a field generated by max () does not work, even renaming, display the error getBackend(). Examples: observer $collection->getSelect()-...
3
votes
3answers
2k views

Magento 2 : setOrder not working in collection

In my custom collection $career_collection->setOrder('career_id','ASC'); not working. My function is below public function getAllCareers(){ $Careers = $this->_careersFactory->create(); ...
3
votes
2answers
781 views

how to get status of last order id in magento2 sql query?

i want to get last order id along with order status in magneto2, i use this query to extract it but the status is not extracting correct: SELECT max(entity_id) , STATUS FROM sales_order max ...
3
votes
3answers
3k views

Magento 2 : AND condition in addAttributeToFilter not giving desired result

According to answer to this related question the AND condition in addAttributeToFilter is added by adding consecutive addAttributeToFilter so my statement is something like; $_productCollection->...
3
votes
1answer
795 views

Create a collection of products that have a tier price for a particular customer group

I want to create a page or tab within customer dashboards that shows all products that have a tier price for a customer group they are a member of. This will help customers who have contract prices ...
3
votes
2answers
197 views

Magento Order report

I got mail every week order report below is the code <?php include 'app/Mage.php'; ini_set('display_errors', 1); Mage::app(); $ordershippeddays = 7; // number of days you want $fromDate = ...
3
votes
3answers
3k views

Magento resource Collection override

I have been trying to override Magento resource collection class. I have found few solutions but it seems can't get it to work. The class is located in: App/code/core/Mage/Reports/Model/Resource/...
3
votes
1answer
3k views

$product->getFinalPrice() and $product->isSaleable() are very slow when called from a product collection

Loading around 400 products without using $product->getFinalPrice() and $product->isSaleable() usually takes around 2 seconds. When calling them, however, the load times shoot up to around 12 ...
3
votes
1answer
3k views

How to find whether a product attribute is set to “use default value”

If I load a product's data in store view or website scope, every attribute set to "use default value" is populated with that default value. This is fine in most cases, but now I'm trying to find out ...
3
votes
1answer
1k views

Best way to modify product collection on list page

I've a requirement that I've to modify product listing page and hide all configurable products for which if any of the associated product is out of stock. Which is the best place to modify ...
3
votes
1answer
837 views

List categories which contain products with specific product attribute

I'm trying to get a list of categories (ID, Name). However, only categories that contain products with a certain product attribute value can be listed. I've already tried the following; <?php ...
3
votes
2answers
3k views

Magento collection classes confusion

I confused by following collection classes $orders = Mage::getResourceModel('sales/order_item_collection'); $orders = Mage::getResourceModel('sales/order'); $orders = Mage::getResourceModel('sales/...
3
votes
1answer
1k views

Joining address fields to order

I am trying to export orders and address using the following code: $collection = Mage::getModel('sales/order')->getCollection(); $collection->addFieldToFilter('store_id', 3); if (!$...
3
votes
2answers
2k views

How to add a product to a collection by ID

Lets say I have an empty collection and a list of productIDs. I want to populate the collection with products specified by the IDs in the list. How would I do this?
3
votes
1answer
1k views

multiple collections in one admin grid?

Is it possible to have multiple collections in one grid? Suppose if we have grouped data, and we need to display it in multiple dynamic child grids. Suppose data is: firstname lastname city Group 1:...
3
votes
1answer
132 views

How to get in stock product collection by category id in Magento 2.3.3?

I'm using Magento 2.3.3 with multiple websites store that uses different multiple stock sources(multi inventory) and I tried to retrieve product collection by category id like this: public function ...
3
votes
2answers
420 views

Search criteria builder does not filter an “out_of_stock” products

I am using Magento 2.3, Am filtering the product collection using the search criteria builder with a custom attribute as the filter. $filter1 = $this->_filterBuilder->setField('...
3
votes
1answer
1k views

Magento 2 : Is there a way to query products using Custom Attributes in Rest API Call?

I have a custom attribute setup for Books called isbn_13 Now I try to find the products using the isbn_13 values but unable to filter the results based on this. Is there any way to do this? Update: ...
3
votes
2answers
5k views

Get product collection by store ID on Magento 2.2

I want to get all products by store ID, so I'm doing it like this return $this->productCollection->addStoreFilter(27); productCollection is Magento\Catalog\Model\ResourceModel\Product\...
3
votes
1answer
991 views

Magento2: What is the best practice to get collection

I know it is not a good practice to use objectManager to get collection. However, I don't know what is the advantage of using ModelFactory ($this->mymodelFactory->create()->getCollection()) ...
3
votes
2answers
210 views

Getting Orders from Customer

If I have a customer object, what would be the best/fastest way to get a list of orders placed by that customer?
3
votes
1answer
509 views

What is the equivalent of the config node category/collection/attributes in Magento 2 to add an attribute to the category collection

I am porting a Magento 1 module, which adds a custom category attribute, to Magento 2. The product is already created in Magento 2 - but now it does not appear in the inside \Magento\Catalog\Helper\...

1
4 5
6
7 8
31