vishnu gupta
vishnu gupta

Reputation: 1

In magento how can I show different-different list.phtml and view.phtml for different -different categories?

I want to show different -different list.phtml and view.phtml for different-different categories .

My code is:

<CATEGORY_4>
    <reference name="product_list">
    <action method="setTemplate"><name>catalog/product/list_new.phtml</name></action>
</reference>
</CATEGORY_4>

Upvotes: 0

Views: 3998

Answers (3)

joseantgv
joseantgv

Reputation: 2023

With method:

<reference name="product.info">
    <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>

product layout is only applied when you visit product from the category page where you have defined it. If you visit product from homepage, for example, it's not applied. What I have done to apply layout to all products that belong to a defined category is to rewrite function getDesignSettings() from Mage_Catalog_Model_Design:

public function getDesignSettings($object)
{
    if ($object instanceof Mage_Catalog_Model_Product) {
        $customCat = 'XX';
        $productCats = $object->getAvailableInCategories();

        if (in_array($customCat, $productCats))
            $currentCategory = Mage::getModel('catalog/category')->load($customCat);
        else
            $currentCategory = $object->getCategory();
    } else {
        $currentCategory = $object;
    }

    $category = null;
    if ($currentCategory) {
        $category = $currentCategory->getParentDesignCategory($currentCategory);
    }

    if ($object instanceof Mage_Catalog_Model_Product) {
        if ($category && $category->getCustomApplyToProducts()) {
            return $this->_mergeSettings($this->_extractSettings($category), $this->_extractSettings($object));
        } else {
            return $this->_extractSettings($object);
        }
    } else {
         return $this->_extractSettings($category);
    }
}

Upvotes: 0

user3044352
user3044352

Reputation:

Thanks for the post. i just used this one

<reference name="product.info">
    <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>

and it's working fine. but if i set one product in multiple categories so it's not handle the layout. it's call same file "your-view-filename.phtml". even i go through from both categories.

Upvotes: 0

James
James

Reputation: 4580

Your code will help you use different list.phtml for different categories. To use different view.phtml for different category products, you will have to set different attribute attribute sets and assign different templates for different attributes set. Check this link to how to do it Magento: template based on attribute set

OR

If both the category page and product view page use the same page layout,for eg: category page and product view page uses 1column.phtml page layout, you can use different list.phtml and view.phtml for different categories by following these steps.

  1. In the admin panel goto Catalog > Manage categories
  2. Select the category for which you want to change the list.phtml
  3. Select "Custom Design" tab.
  4. Set "Use parent category settings" to No and "Apply to products" to Yes.
  5. Add this in the "Custom Layout Update" section
  <reference name="product_list">
       <action method="setTemplate"><name>catalog/product/your-list-filename.phtml</name></action>
  </reference>
  <reference name="product.info">
        <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template></action>
  </reference>

Repeat this for all the categories that you want to change.

Upvotes: 6

Related Questions