Can anybody please put some light on the need of the method “getTypeInstance()”, which can be use by any product object?
Also what are the pros & cons of using this method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The getTypeInstance allows you to retrieve an object that describes the type of the product, where type is the internal magento type. So, you can use this method to determine if a products is a simple product, a bundled product, a configurable product, etc.
You can then use these objects to determine information about a product that’s specific to it’s type. For example, if you call this method on a bundled product object, you’ll get an object whose class is
This class has a number of methods on it, which are specifically designed to deal with bundled products. For example, you have the
getWeightmethodThis method has specific rules for determining the weight of a bundled product.
Then, in the
catalog/productModel (Mage_Catalog_Model_Product), you can see thatgetWeightjust wraps a calls to the type’sgetWeightThe is a prime example of Object Oriented Programming in action.
So, end of the day? If you don’t know why you’d need to use this method, you don’t need to use this method.