-
- tman_f

-
Total Posts: 82
Joined: 2008-02-12
|
Hi Guys, I have been searching to find where a product collection gets converted from a result set into instances of Varien_Object just before the the collection gets returned as an ‘object’ collection. I cant seem to find the method and I have been traversing through the class hierarchy for hours now. Does anybody know where this happens? I feel like I keep skipping right over it.
Thanks
|
| |
-
- Posted: April 14 2008
-
| top
-
|
 |
 |
 |
|
|
-
- tman_f

-
Total Posts: 82
Joined: 2008-02-12
|
Also, I seem to have a kink in my logic. I have noticed that the catalog/category model contains the method getProductCollection().
This is the containing code:
public function getProductCollection() { $collection = Mage::getResourceModel('catalog/product_collection');
return $collection; }
This method returns a viable object collection containing instances of Varien_Object. I guess I dont understand how this can be. The model ‘catalog/product_collection’ is a class. We arent telling it to return anything. I dont understand how we could assign a collection to the variable $collection from this class. Yes, the class contains access to the product collection, but somehow by returning this class, the class ‘becomes’ the collection. Could somebody explain how this is happening? Perhaps there is a magic function that I am unaware of.
Thanks
|
| |
-
- Posted: April 14 2008
-
| top
| # 1
-
|
 |
 |
 |
|
|
-
- Magento Core

-
Total Posts: 15
Joined: 2007-07-05
Los Angeles, CA
|
Mage::getResourceModel(’catalog/product_collection’) instantiates a class that eventually extends Varien_Data_Collection which implements built-in PHP interface IteratorAggregate, which makes the object iterable the same as an array by implementing getIterator() method.
|
| |
-
- Posted: April 14 2008
-
| top
| # 2
-
|
 |
 |
 |
|
|
-
- tman_f

-
Total Posts: 82
Joined: 2008-02-12
|
Great post, thanks for the clarification. Now that I understand that, I wonder if you could clarify something else for me. I have noticed that both the category collection and the product collection stem from this object. I have noticed that there is an _init() method that is expecting a parameter of an object type to be passed. This would explain how the collection object would know what type of object the elements are to be.
I am a little confused about where the difference in tables is declared. For instance, the products reside in the catalog_product_entity table and the categories reside in the catalog_category_entity. Is there a parameter or method that tells the class to find records in the appropriate tables?
I would appreciate your input.
Thank you.
|
| |
-
- Posted: April 14 2008
-
| top
| # 3
-
|
 |
 |
 |
|
|
-
- tman_f

-
Total Posts: 82
Joined: 2008-02-12
|
Alright, ignore that last post, I figured it out. To continue the previous notion of Varien_Data_Collection becoming iterable, I have another kink in my logic. So with a little research I understand the IteratorAggregate interface and why it is useful. I am still lacking to make a connection. Is the Varien_Data_Collection class making the connection to the database, or is some other object making the db request, and then making the result set an instance of this class?
Sorry if I am not making any sense, I really want to understand this concept.
Thanks again.
|
| |
-
- Posted: April 16 2008
-
| top
| # 4
-
|
 |
 |
 |
|
|
-
- tman_f

-
Total Posts: 82
Joined: 2008-02-12
|
nevermind, I figured it out.
|
| |
-
- Posted: April 16 2008
-
| top
| # 5
-
|
 |
 |
 |
|
|