Magento For Developers: Varien Data Collections

Commerce Bug is the most essential and compulsory debugging extension for those who use Magento for ecommerce development. No matter if you are starting out with Magento ecommerce development or you are used to it, commerce bug will surely save your time. Any PHP programmer who wishes to gather group of related variables have a single option and that is venerable Array. In PHP array is a general purpose dictionary that combines objects with numeric behaviour. While in other languages the choice is bit difficult.

There are various data structures for you to choose and each offers their own advantages in terms of speed, semantics and storage. With the introduction of PHP 5 the status quo changed as it offers in-built interfaces as well as classes while allowing programmers to create their own data structures. Well they get the opportunity to create array-like objects with methods with specific functionality. Further it is possible to setup rules and allow only certain kinds of objects into your collection. You are offered various different collections by magento. For Magento module development or magento ecommerce development you need to understand the working of these collections.

It starts with creating few new objects. While inheriting models, the object is defined by the varien object which is a common pattern and ensures easy adding of methods and functionalities to the object and avoids the boring pattern of editing every class file. You get magic getter and setters from all the objects that are extended from varien object. The recent version of Magento offers Array style bracket for accessing properties.

Coming to the objects let us add them to collection which is not different from array.

Model Collections: All magnetos' in-built data collection inherit from his object so you can call it that with any product collection you can perform the same sort of tasks. Please note that all data collections by Magento contain lot of complicated logic to handle when to use an index or cache and also the logic for EAV. So many collections by magento have theVarien_Data_Collection_Db class. Also because magento uses Zend database abstraction layer the SELECT is an object. In an EAV collection it is set by default that it does not include all the attributes of an object instead you are supposed to add them by using a method.

Lazy Loading: In PHP while instantiating an object the SQL calls are immediately made during the writing phase. The case is different in magento which uses lazy loading that makes no SQL calls till the client-programmer needs to access the data. It allows safe addition of attributes at a later stage.

Filtering Database Collections: It is an important method where database collection is addFieldToFilter. Two parameters are used here for filtering. First one for filtering attributes and second one for adding skufilter. The second one can also be used to specify the type of filtering.

Other Comparison Operators: For those who want to do something other than equals can use the second parameter which supports an alternate syntax. This array makes the comparison you wish to.

Boolean operators: In some rare moment when you want to only filter a single attribute then these operators can help out. It allows chaining of multiple calls and gives number of queries resulting into production of a clause. For building query you need to pass an array of filter arrays. The best thing would be to assign individual filter arrays to the variables and then assign an array of all filter variables.

No comments:

Post a Comment