Magento: Category product design update not applied to search result products - magento

I'm using a design update XML applied to all products under specific categories. The update is applied successfully to those products when browsed to them from those categories, but not when those products are opened from search results. How can I make the design update affect those products when opened from search results?

You need to add a layout handle that you can "grab" for each one of these products and modify the layout through layout xml files.
The key to this process is in the initProductLayout method of Mage_Catalog_Helper_Product_View. This method is where custom layout handles are added based on the product model. You can grab the layout update object from the controller and call addHandle() on it with a string to add that handle. So you'll want to rewrite this method and do something like this:
$update = $controller->getLayout()->getUpdate();
foreach ($product->getCategoryIds() as $categoryId) {
$update->addHandle('PRODUCT_IN_CATEGORY_' . $categoryId);
}
Now, in a layout xml file you can target the <PRODUCT_IN_CATEGORY_##> handle for the ID of your category(ies) and any layout updates you put here will be applied to the product view page no matter how it is accessed.
Depending on the specifics of your installation, it may make more sense to key the handle with some other category identifier, like the name or URL key, instead of the numeric ID. For this, use $product->getCategoryCollection() and iterate through the collection to grab what you need. You may also want to use $product->getAvailableinCategories() if you want to include only category IDs that the product belongs to directly (instead of including categories of higher parentage).

Related

I want to create a category just to show products in a particular attribute

Hope you can help Magento users,
I have a clothing store selling big mens clothing. One of my best categories in my old store was allowing the customer to view all the products in his size in one feed. Whilst I am aware they can choose the top level category (menswear) and use the attributes down the left side to select their own size, I would like to have a specific category for instance (All 3xl products) all ready setup in the mega menu. So far I have been able to set a category up and set a url rewrite to the required url attribute. Works fine but I can not add text at the top of the page (for seo purposes).
I was considering if it is possible to create a static block with only 3xl products in, then I can design the page around the static block?
Depending upon category structure if you are using anchor categories you could create a link directly to an attribute filter.
i.e
I have an attribute called material
and the value of polycarbonate id is "4"
you can append the values of layered navigation/anchor categories to the end of the url
mysite.com/vehicles.html?material=4
Say for example, you have an attribute of "size", with the id of 3xl = "10"
and mens was your anchor category. It would look like
yoursite.com/mens.html?size=10
Then you would just create a simple html link to http://yoursite.com/mens.html?size=10

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.

How to add a filter to magento navigation bar for a custom collection

I've got a page within my magento shop in where I list a collection of products. I joined the product collection with a custom table where some additional attributes are stored.
In the left column (navigation layer) the filters are shown where a selection can be made for a specific manufacturer or a specific category. Now I want to add my own filter on one of the fields from my custom table so that only the fields with a certain (non-negative) value for one of the added attributes will be shown when the filter is selected by the user.
When I try to find information on filters I often see people referring to the product attributes in the backend, however I doubt if it will apply here since it is not a product attribute in the sense of eav but one from my custom table (that is joined on sku). I am looking for an example or strategy on how I can add a filter based on a property in my joined collection.

magento adjust product visible

I have 2 new custom productattributes that enables or disables a product in the category list and product-detail page.Both are dates.
need to calculate if the current date is between the 2 custom dates.
if it is, the product must be enabled.
I can't find a place in the code to enable/disable a product in the category list and detail page. I don't want to fix this in a phtml.
Can somebody help me?
You have to modify two things :
the product collection in order to add the filtering on your two news attributes.. For that, for example, you can implement the event catalog_block_product_list_collection from Mage_Catalog_Block_Product_List (used in product listing and search) where you'll add your filtering with the function $collection->addAttributeToFilter('attribute_code', $condition)
the product page itself. You can add your logic in order to display or not your product by multiple ways.. I would choose to implement the event catalog_product_is_salable_after in order to add your logic here and call $product->isSalable() in the template or controller...

Add search module in category page

I would add the search form in the category pages. The module will make researches in the same category. It's possible?
Add category to Advanced Search. Some pointers here:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/search_and_advanced_search/how_to_add_search_by_category_to_advanced_search
You will probably want to do it in a module rather than in a core hack...
Now put some simple form together inside a phtml file, put the layout xml together to load it on category pages. Set the search to add the current category to the search string that gets sent off to your modified 'Advanced Search'.
As for getting that category, try $this->getCurrentCategory();

Resources