Magento creating a custom template from backend category layout - magento

I need to create a custom template with products categories. Which means under one category limited number of related products should be displayed. Under another category that category related products should be displayed. Also there should be a label which display those category names. As well as I need to add a link to view more products.
I am doing this through category layout (backend). I added the below code and tried.
<reference name="header">
<block type="core/template" name="header_nav" as="headerNav" template="page/html/headernav.phtml">
</block>
</reference>
<reference name="content">
<block type="catalog/product_list" name="product_list_flowers" template="catalog/product/list.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list" name="product_list_cakes" template="catalog/product/list.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
Category products are displaying. But this is not limiting the number of products. Also the header is not displaying. And I cannot add a link to this page.
Can anyone please help me on this. Thank You.

To be able to set limitation on Product Collection (since this differs from category to category in your case), find below the implementation:
<reference name="content">
<block type="catalog/product_list_flowers" name="product_list_flowers" template="catalog/product/list/flowers.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list_cakes" name="product_list_cakes" template="catalog/product/list/cakes.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
The above code will continue to display 4 columns with products.
Create block files (If this differs from category to category)
app/code/local/Namespace/Module/Block/Catalog/Product/List/Flowers.php
app/code/local/Namespace/Module/Block/Catalog/Product/List/Cakes.php
Override List.php (If all the categories require same limitation of products)
app/code/local/Namespace/Module/Block/Catalog/Product/List.php
 
<reference name="content">
<block type="catalog/product_list" name="product_list_flowers" template="catalog/product/list/flowers.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list" name="product_list_cakes" template="catalog/product/list/cakes.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
Below line no: 87, In this public function _getProductCollection()
...
$this->_productCollection = $layer->getProductCollection();
$this->_productCollection->setPageSize(10); //this will display only 10 products
...
Let me know if I was able to understand it correctly.
Happy Coding...

Related

Magento - Add a static block to the left column

How would I go about adding a static block on my left column on the category pages?
I would like the static block to go underneath the main column so that it looks like this: http://imgur.com/iopEesf
Thank-you.
override catalog.xml layout file in your template.
in and
<catalog_category_layered>
<reference name="left">
<block type="cms/block" name="block-name">
<action method="setBlockId"><block_id>block_id</block_id></action>
</block>
</reference>
</catalog_category_layered>
<catalog_category_default>
<reference name="left">
<block type="cms/block" name="block-name">
<action method="setBlockId"><block_id>block_id</block_id></action>
</block>
</reference>
</catalog_category_default>

CMS page with layered navigation not working

I've added a CMS page wich shows all the products listed under the "All Products" category by creating a CMS page with a "two column with left sidebar" layout, and in the content tabs, I've added the following code:
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
I was reading about it and the layered navigation should be showing already. However, I've set "Is anchor" to yes, but it doesn't work. I can't make it to appear. What am I missing here? Is there a better way to create this catalog page?
Thanks in advance.
To display layered navigation on cms page you have to set root category to Is Anchor=Yes.
Please check the below link for calling layer navigation in CMS Page
http://www.webdesign-gm.co.uk/news/web-design/magento-web-design/layered-navigation-on-home-page-or-any-cms-page-magento.php
Or you can try this Design tab->Page Layout->Layout Update XML:
<reference name="left">
<!-- Layered Navigation Block -->
<block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml" >
<action method="setCategoryId"><category_id>40</category_id></action>
</block>
</reference>
<reference name="content">
<block type="catalog/product_list" name="home" template="catalog/product/list.phtml">
<!-- Product List View -->
<action method="setCategoryId"><category_id>40</category_id></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
Open CMS->Pages->[your page] in Magento Admin Panel.
Add the following layout instructions to Design tab->Page Layout->Layout Update XML
<block type="catalog/product_list" name="product_list"
template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>3</category_id></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar"
template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend">
<layout>empty</layout>
<count>6</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>one_column</layout>
<count>5</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>two_columns_left</layout>
<count>4</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>two_columns_right</layout>
<count>4</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>three_columns</layout>
<count>3</count>
</action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
<block type="catalog/layer_view" name="cms_layer" as="cms_layer" before="-">
<action method="setCategoryId"><category_id>3</category_id></action>
</block>
Also insert ID of desired category in 3 (2 times).
Open desired category of your store through Catalog->Manage Categories. Make sure that Is Anchor=Yes on Display Settings tab.
One possible reason layered navigation does not show is because you also need to configure your attributes to show in layered navigation.

Add block using Custom Layout Updates to category

I am trying use the Custom Layout Update field of a category to add something to the left sidebar for just this category but can't quite get it to work. I had it working before so I know I can do it but then my client accidentally deleted the category.
This works, so I know I have the ability to add something - but I don't want a static block:
<reference name="left">
<block type="cms/block" name="Designer Sidebar" before="-">
<action method="setBlockId"><block_id>designer_sidebar</block_id></action>
</block>
</reference>
I want to include a phtml file from my theme folder and trying this, but can't get it to output anything:
<reference name="left">
<block type="cms/block" name="Designer Sidebar" before="-" template="catalog/category/view_sidebar.phtml" />
</reference>
<reference name="left">
<block type="core/template" name="Designer Sidebar" template="catalog/category/view_sidebar.phtml"/>
</reference>

Display Products on Home Page with Pagination in Magento

I am new to magento.
I am creating a products page which will contain large number of products.
I am trying to display them on my CMS page, But i am able to show only 20 records per page. I just want to show pagination, So that user can navigate through the products easily.
I have searched over the net and found this code and updated in Layout Update XML
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>2</category_id></action>
</block>
</reference>
But it's not working.
Are there any default paging mechanisms in Magento?
i found the solution for my question
here Layout Update XML
<reference name="content">
<block type="catalog/product_list" name="home" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>2</category_id></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name><count>5</count></action>
</block>
</reference>
just change category id you want to paginate.

Edit category lay-out, but apply parts to products

I've got a custom category view.phtml for this category:
http://www.touchfix.nl/onderdelen
The sub-categories use their parent's XML-update, which is:
<reference name="catalog_category_default">
<reference name="content">
<remove name="category.products" />
<block type="catalog/category_view" name="alphabase.parts" template="catalog/category/view.parts.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.parts.phtml"></block>
</block>
</reference>
</reference>
<reference name="right">
<remove name="cms_waaromkiezen" />
<block type="cms/block" name="block_speerpunten_onderdelen">
<action method="setBlockId"><block_id>block_speerpunten_onderdelen</block_id></action>
</block>
</reference>
<reference name="head">
<action method="addCss"><stylesheet>css/categoryblocks.css</stylesheet></action>
</reference>
I want to achieve that the changes to "right" are also applied to products in these categories.
But when I apply these changes to products too in category settings, the "content" reference screws up my page and it returns a blank page.
How can I reference the catalog_category view, so that the "content" update is only done when in category view and not in product view?
catalog_category_default isn't a reference, it's a handle
have you tried changing to:
<catalog_category_default>
I managed to do the trick with the following:
<reference name="content">
<reference name="category.products">
<action method="setTemplate"><template>catalog/category/view.repair.phtml</template></action>
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/list.repair.phtml</template></action>
</reference>
</reference>
</reference>
<reference name="right">
<remove name="cms_waaromkiezen" />
<block type="cms/block" name="block_speerpunten_reparatie">
<action method="setBlockId"><block_id>block_speerpunten_reparatie</block_id></action>
</block>
</reference>
<reference name="head">
<action method="addCss"><stylesheet>css/categoryblocks.css</stylesheet></action>
</reference>
The difference was not to delete the blocks and add new ones with the correct template, but to change the template files of the corresponding items. I can now also refer to the product view block with <reference name="product.info">, which will be my next step.

Resources