Questions tagged [collection]

Questions related to Magento collections

0
votes
1answer
353 views

Collection loads wrong data?

I'm using Magento CE 1.7. I want to add the customer telephone number to the Abandoned Cart grid (Reports->Shopping Carts->Abandoned Carts). I have overridden the block ...
9
votes
5answers
15k views

How to log SQL query of the collection?

I want to log the SQL query for a custom collection. I tried the following code. But did not work. Any suggestions will be appreciated. Mage::log($collection->getSelect(),null,'test.log',true);
18
votes
2answers
71k views

How to get attribute “option label/attribute text” having “attribute value” (option_id)?

Suppose I have an attribute that is a collection of option (dropdown/multiselect). I can retrieve the attribute value for a given product: $store_id = [something]; $productId = [something]; // this ...
3
votes
3answers
1k 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 ...
2
votes
3answers
1k views

Ordering a catalog/product collection by sales data

I have a 'catalog/product' collection which is being filtered by product attributes, but I need to order this collection so that the most popular (sales OR views) come first. Is there a way to do ...
4
votes
3answers
3k views

Apply an extra filter in view

I am trying to add additional filters to a collection after the collection seems to of been generated. In catalogue product list.phtml there is the following line of code: $_productCollection = $this-...
0
votes
2answers
1k views

Data added to Collection with a Join is not showing up?

require_once('../app/Mage.php'); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $collection = Mage::getModel('sales/order')->getCollection() ->...
3
votes
1answer
4k views

Conditional join in magento collection

I am working in magento and now i face problem in getting my info.I created collection to fetch data , but now i want to check some value if exist i want to add new inner join to that collection.I try ...
3
votes
3answers
28k views

Filter product collection by custom attribute

I'm filtering a product collection by the custom attribute ean with the following code $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('name')...
2
votes
3answers
5k views

How do you deal with 61 tables join limit when building magento collection?

Mysql has known limitation of 61 tables to join, how do you overcome that when you have more than 61 attributes to join in magento collection?
2
votes
4answers
3k views

Add invoice status to order grid

We try to add the invoice status column to the sales order grid. We added the code beneath to the prepareCollection function: $collection->getSelect()->join('sales_flat_invoice', 'main_table....
1
vote
2answers
6k views

Trying to filter by 'In Stock' or 'Out of Stock' on product admin grid

I have successfully been able to get whether a product is 'In Stock' or 'Out of Stock' in the Magento admin product grid using an observer in the way set out below. However when I try to filter by 'In ...
0
votes
3answers
8k views

addAttributeToFilter with OR and BETWEEN

I'm adding a couple of filters with addAttributeToFilter. I have the fields "year", "year_from", "year_to". I either want to match the year exactly to the "year" attribute or make a "between" by using ...
6
votes
3answers
6k views

Reload collection after count()

I'm working with a Magento flat collection I want to do this: $collection = 'load a certain collection'; $collection->'addsomefilters'; if (count($collection) == 1) { //add some additional ...
7
votes
5answers
34k views

Filter product collection by multiple categories?

I have this snippet of code that gets the most recently added products: $_productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect('*') ...
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 ...
0
votes
1answer
3k views

getSelect Question

Why cant I do the following: $this->getSelect() ->columns( array( 'ordered_qty' => 'COUNT(DISTINCT main_table.entity_id)', '...
2
votes
1answer
2k views

Can not override Sales Resource Model Collection class

I am trying to override Mage_Sales_Model_Resource_Order_Collection My custom module's config: <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <...
3
votes
4answers
9k views

Subquery in a collection

I am trying to do a query of the form: SELECT TableA.id, ( SELECT MAX(TableB.qty) FROM TableB WHERE TableB.parent_id=TableA.id ) FROM TableA the important thing being that the select ...
1
vote
2answers
375 views

serious need of explanation with addSaleableFilterToCollection

I have spent days looking for a simple tutorial about adding filters to a product collection. If anyone has a link to a good tutorial or explantion I would really appreciate it. I found a Magento ...
0
votes
2answers
4k views

How to display various special “sale items” pages?

We have various sale products for limited times. How best to display these so that it's easy to end old sales and start new ones? I was thinking of creating a CMS Page "Sale Products." If the CMS ...
3
votes
2answers
864 views

Can't load all products in Indexcontroller

I have a simple Indexcontroller. When I use this: $collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*'); ...
1
vote
2answers
1k views

Product Collections: Get ALL products even though “Show products that are out of stock” set to NO?

I’d like to list products using Product Collections that list ALL products regardless is_salable or in_stock are false. Is there a way I can disable all is_salable or in_stock checks for Mage::...
3
votes
1answer
2k views

Magento Model Filter by Category Returns No Products

I'm using Magento EE Lite (1.11.02) and I'm trying to load a collection of products by one single category. The following code functions as you would expect: public function getProductList() { $...
7
votes
3answers
17k views

How to add dynamic field in magento collection?

I have created one magento collection like this to calculate distance from lat long. $collection = Mage::getModel('module/module')->getCollection()->addFieldToFilter('status',1); $...
2
votes
2answers
12k views

Add pagination to any block's collection

I have a number of collections which have blocks that output the contents to frontend routes (My Account, frontend features). I have need to paginate some of these. I know that pagination methods ...
1
vote
1answer
13k views

How to filter product collection by attribute's admin option values?

I am currently developing a product configurator. I am submitting a form which sends the admin option values of my custom attributes via POST to a controller action. If I use the current store's ...
2
votes
4answers
5k views

getGalleryImages returning NULL in Magento homepage

We've extended a homepage slider for a client so that they can feature products in this space. As part of this, there are three image slots where we wish to get the products' main image and then two ...
0
votes
1answer
584 views

addFieldToFilter doesn't return the right product for selected attribute values

I am currently programming a product configurator module for Magento. Everything is working fine so far besides the core functionality: choosing the right product from the database for the selected ...
18
votes
7answers
97k views

Get product collection from a category id

I am trying to get a collection of products from a category id. A few things I have tried are in the block : $category = Mage::getModel('catalog/category')->load(123) ->...
0
votes
1answer
3k views

Magento collection issues, methods not working filters not applied etc

Trying to create a couple of quick extensions, one to display a list of best sellers and one to display a list of items on promotion. I want both of these modules to filter by a given cateogry id if ...
18
votes
4answers
4k views

Issue using “having” in Magento collection

I am trying to build a custom collection for a grid in Magento admin module. I have created a new collection method called "addAttributeHaving" which just does the following: public function ...
4
votes
3answers
429 views

Associating Categories with Additional Collections Other Than Products

I've got a decent understanding of the basics of eav and adding additional attributes to categories, products and other entities however I'd like to be able to form a one to many relationship between ...
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
5k views

How do I get the minimal price of a grouped product from a product collection?

I'm loading all products using the product collection resource model. $_categoryId = $this->getCategoryId(); $_productCollection = Mage::getResourceModel('catalog/product_collection') -&...
1
vote
2answers
2k views

Get collection of products of all stores

It is possible to get in only one collection the list of products from all stores (with different translations of the products attributes)? Thanks for help
1
vote
2answers
4k views

Collections _init() function

I have the following collection that helps me implement a custom report: class VMR_Customreports_Model_Resource_Productsordered_Collection extends Mage_Reports_Model_Resource_Order_Collection { ...
0
votes
3answers
367 views

Collection fails when using a more restricted admin user

I have the following collection which helps implement a custom report. <?php class VMR_Customreports_Model_Resource_Productsordered_Collection extends ...
15
votes
4answers
23k views

Magento - custom (non eav) model, load by multiple fields

I have a custom model and resource model. I want to load a single instance of the model using more than 1 field. The model has the following fields: id tag_name custom_name group_name I want to ...
2
votes
1answer
4k views

Downloading order details through Mage::getModel('sales/order')

I am trying to download order details (email + name) from my stores. We have a multi-store. The problem that I have is that when I run this code on STORE 1 or STORE 2 - both result in the full ...
29
votes
1answer
27k views

About Collection Model and Resource Model

I am bit confused about using resource model and collection model. Sometimes when I see examples for loading products using specific attributes, in some examples, they use collection model and ...
0
votes
1answer
325 views

Add a product collection to customer entity type

I would like to allow a logged in user to select his or her favorite products. This list should be maintained from a new account page to be created following Alan Storm his article: http://alanstorm....
2
votes
1answer
759 views

Error using a custom collection for a report

this is a hard question to ask but I am trying to write a reporting module, following: http://www.summasolutions.net/blogposts/custom-reports-magento. I got that module to work on my install, but ...
1
vote
1answer
398 views

How Do I Create a Derived Collection

I am trying to follow what "uguptu" is recommending here: http://www.magentocommerce.com/boards/viewthread/225234/ In particular, I am trying to run my own highly specific query on the sales/order ...
16
votes
4answers
18k views

Add Column to a grid (observer) - Column ‘store_id’ in where clause is ambiguous issue

I'm adding a column to the order grid using observer approach: On the event -> sales_order_grid_collection_load_before I'm adding a join to the collection On the event -> ...
78
votes
6answers
66k views

Difference between getSize() and count() on collection

I have heard many times that they both are the same. But I am facing a weird issue, in the product collection of CatalogSearch module, count() is returning correct product count while getSize() is ...
12
votes
2answers
6k views

How to clone the collection in Magento?

I have one collection in a method where I want to perform two different operations on this collection. So, I want two separate copies of same collection, and then assign one of the two collections to ...
2
votes
3answers
4k views

Best Practice: How to add a column to a backend grid ?

Usually we need to add to the Order Grid some column, so let take this as example. There are 3 ways to do that: Rewrite the grid block in our custom module Use an observer on the event ...
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 ...
1
vote
2answers
5k views

Magento Error: Item (Mage_Sales_Model_Order) with the same id “1457” already exist

$items = Mage::getModel('sales/order')->getCollection(); $items->getSelect()->joinLeft('sales_flat_order_item', 'main_table.entity_id = sales_flat_order_item.order_id', array('name')...