magento - product model and product_collection items have different properties in flat catalog mode - magento

i just know that if i have a product_collection (for example the collection generated in catalog pages)
//event catalog_product_collecion_after_load
$productCollection = $observer->getEvent()->getCollection();
if i take an item from this collection and i compare it with the relative model
$_product = Mage::getModel('catalog/product')->load($item->getEntityId());
this 2 instace of the same entity have different properties!
I'm working in flat catalog mode.
Why the collection's items are not the same of product models?
I would to know if this is the right behaviour and if is it how to have same properties in both object!
sorry, but magento is very dark :(

Because Mage::getModel('catalog/product')->load($item->getEntityId()); loads all attributes for the product and the collection loads only specified attributes different from situation. You may find (CTRL+F) at app/code/core/Mage/Catalog/etc/config.xml something like attributes then you will see the list of all default loaded attributes for product collection. Also you able to change them in your module or directly in Catalog config.xml. But it's not the best idea to change something at app/code/core/Mage/Catalog/etc/config.xml except for debug

For the catalog_product_collection with flat_mode is more complicated add an attribute to the item's collection.
The attributes that are in product items are the join between catalog_product_flat table and the EAV attribute for product entity.
So, in product model from:
collection we have the attributes joined between catalog_product_flat table and the EAV attribute
getModel('catalog/product') we have all EAV attributes
Over these attributes we will certainly have other attributes, i think added in other point.
Now, which attributes are in catalog_product_flat?
Simple are the attributes you checked as "Used in Product Listing" in magento manage attributes! :)
But in some attributes you can't change this option, depends by kind of type you have select. Atribute type Image hasn't "Used in Product Listing" flag, so you have to modify catalog_eav_attribute if you want the new image in product listing.
Well, i spent 2 days to know this, i hope it will useful for other unlucky magento developer. :)
Magento version 1.5

Related

How to add custom attributes to a specific category in Magento

I need to add some custom attributes to a category in Magento. I only want to use for a special category, not all.
Thanks
Do you mean that you want products in category A have a set of attributes while products in category B have another set of attributes?
If so, you should create a new attribute set in Catalog->Attributes->Manage Attribute Sets, and add all attributes you need for the specific category. And when you create products for this category, just choose the new attribute set.
Well if it is not what you mean, please give more detailed explanation.
Hope it helps

Is it possible to filter related products based on some of it's attributes on the product view page?

I am new to magento and looking for a solution. Is it possible to filter related products based on some of it's attributes on the product view page? I have a product and there are 100s of related products associated with it. I want customers to filter these related products based on their attributes on the product view page itself. Is it possible? Please help me.
Regards, Pallab
The template (Magento 1.9.1.0 version) for this is located in: frontend/your_package/your_theme/template/catalog/product/list/related.phtml template and the Block class associated with this template is: Mage/Catalog/Block/Product/List/Related.php and the method is: protected function _prepareData() where the related products collection is being fetched. You will have to setup your filters as you need, most likely by using JavaScript and finding the products that match the selected (filtered) attributes by the customer.
For more thorough answer, I will need more information about how these filters should look like and work.

How to remove information in Magento catalog, but only for specific product type

I am wondering how can I delete this two divs -
in Magento catalog, but only for specific product type. In short, I would like to have product type which would appear in catalog only with product-image and product-name, without - price, Out of stock, Add to Wishlist, Add to Compare.
It's possible to load different layout updates depending on loaded product type. You can see an example of how it's done in Magento for configurable products here: https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/design/frontend/base/default/layout/catalog.xml#L275-L287
It's possible because view action of product controller makes this to be executed: https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/code/core/Mage/Catalog/Helper/Product/View.php#L59-L60
You can change the design for any product from the admin.
You need to create a separate theme with a different product page which will have only the attributes you would like.
Then you can select the design for that specific product. Please see the screenshot, how you can change design for any product

Display products against attributes in magento

I am working on custom module in magento.
I create two new attributes (combo box) make and location. After that I add values for these attributes using custom code against specific product. Like I add make "Sony" and location is "Australia" against product 1 (1 is id for product).
Now on admin side i want to display this product with attributes values like make is Sony and location is Australia and product is 1.
I found some tables where these values are linked like (catalog_product_entity_int,eav_attribute,eav_attribute_option,eav_attribute_option_value), but I am unable to query such records. The page where I want to display data I have attribute id and attribute code.
Can anyone knows how I can figure it out?
Very simple Dude.
inside your _prepareCollection() method of your custom module grid
Load the product collection and select these two attribute... If there is a need to filter it by these two attributes then do it.

Magento - Product flat functionality with many attributes

So we have over a hundred filterable attributes divided over more than hundred categories (mostly 5-20 per category). The flat table can't contain so many keys so will have to look in the eav table anyway on both product list and product normal page.
Is the flat product of any use now? Can I just as well turn it off and save possible troubles with it?
With filterable attributes you mean, you're using them for layered navigation in catalog and catalogsearch?
If you don't have any other listing where you don't need all your attributes like topsellers etc. I don't know where the product flat table could help you.

Resources