Call-back icon  Sales: Call 800.374.8146 (N America)|757.278.0920 (International)

Magento

Open Source eCommerce Evolved

Magento Forum

   
Product Collection -> Varien_Object
 
tman_f
Sr. Member
 
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

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
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

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magento Core
Magento Team
 
Avatar
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.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
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.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
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.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  82
Joined:  2008-02-12
 

nevermind, I figured it out.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
Sales: Call 800.374.8146 (North America) 757.278.0920 (International)
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
33513 users|411 users currently online|74418 forum posts