Questions tagged [collection]

Questions related to Magento collections

In general, magento collections are classes that contain a list of other objects (Varien_Data_Collection).

Varien_Data_Collection has two direct child classes, Varien_Data_Collection_Filesystem (used to scan directories on the file system) and Varien_Data_Collection_Db (used to load objects from the database)

The database collections are extended by Mage_Core_Model_Resource_Db_Collection_Abstract that handles standard Magento models and Mage_Eav_Model_Entity_Collection_Abstract that handles EAV models.

Related tags:

  • for questions related to collection sorting.
  • for filtering collections questions.
  • for pagination related questions.
1534 questions
17
votes
2 answers

Difference Between setData() and addData()

What's the difference between setData() and addData()? Is there a connection if I update a product or set a new one?
user1240207
  • 1,339
  • 2
  • 15
  • 34
12
votes
2 answers

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 original collection again and return it. To make…
MagExt
  • 1,833
  • 2
  • 16
  • 24
8
votes
2 answers

addAttributeToSelect not working with core/resource_iterator?

public function run() { $products = Mage::getModel('catalog/product') ->getCollection() ->addFinalPrice() ->addAttributeToSelect('name') Mage::getSingleton('core/resource_iterator') …
PiTheNumber
  • 3,234
  • 10
  • 47
  • 70
4
votes
3 answers

How to get visitor log (customer) collection

I'm looking to load the log/customer collection and am running into some issues. When using Mage::getModel('log/customer')->load(1); the appropriate data is returned but if I try to load the collection, it just returns false. Here is what was…
pzirkind
  • 2,906
  • 1
  • 30
  • 41
3
votes
4 answers

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 clause has a subquery. My question is, how would…
user2045
  • 831
  • 3
  • 16
  • 29
2
votes
1 answer

Magento 2: Remove Duplicates From The Collection

I have a custom model with three fields, i.e id, city and region. How can I remove duplicates from the region column when querying the table? How can I group all the cities under the same region? I have pasted the response from the model…
Tebby
  • 23
  • 3
2
votes
2 answers

addAttributeToFilter with dropdown values

Given a dropdown attribute such as color: color: Red Green Blue When loading a product collection how can i load the collection based on either red, blue or green values without knowing the actual option ids? For…
Marty Wallace
  • 5,631
  • 13
  • 65
  • 90
2
votes
1 answer

How to get first item of Varien_Data_Tree_Node_Collection

I am not being able to figure out how to get the first item in this type of collection: Varien_Data_Tree_Node_Collection without knowing the key, is this possible?
Marty Wallace
  • 5,631
  • 13
  • 65
  • 90
2
votes
1 answer

How do you iterate the resultset of a join?

I'm working with custom models in Magento, I need to populate a grid and in order to do that I need to join 2 tables, I used collections and the SQL seems to be right as a vardump will print the expected query, but I don't know how to access to the…
isJustMe
  • 265
  • 3
  • 11
1
vote
1 answer

Item with the same id already exist

Argh! This is the error message: Item (My_returns_model) with the same id "913" already exist I need to not use GROUP BY because I am using a paginated grid. Here is my code: $collection = Mage::getModel('pvxcloudbridge/returns')->getCollection() …
beingalex
  • 727
  • 2
  • 11
  • 25
1
vote
1 answer

Get products which do not have any custom option

i have to get the products which do not contain any custom option, but not using has_options flag. The aim of doing this if the products do not contain any option, i have to set has_options to 0 progmatically(may be through magmi). Is there any…
hkguile
  • 2,221
  • 5
  • 45
  • 85
1
vote
2 answers

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 { public function __construct() { …
user2045
  • 831
  • 3
  • 16
  • 29
1
vote
1 answer

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 model. I would like to derive my own collection…
user2045
  • 831
  • 3
  • 16
  • 29
1
vote
3 answers

Get product count of Parent Category

Trying to get the product count of a category which also counts the products in its children. Currently, I have: $categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('*') …
123TFO
  • 109
  • 3
  • 12
0
votes
1 answer

Product collection based on the total sales of a product within a period

What I need is the logic for creating a product collection based on the total sales of a product within a period. So if a product costs 10 $ and I sold 540 I want the sorting to be based on the total sale 5400. EDITED & SOLVED: What I have so far is…
Bernhard Prange
  • 677
  • 4
  • 19
1
2