How to display breadcrumbs on Magento Sitemap - magento

Is there a way to get breadcrumbs to appear on the top of my sitemap page?
I want my breadcrumbs to display on ALL pages, and these are the only pages I can't get them to display on.
I added this to the top of the display container file and its not working... Any ideas?
<?php echo $this->getLayout()->getBlock("breadcrumbs")->toHtml()?>

You need also add actual crumbs to the list by calling addCrumb() function. It is defined in Mage_Page_Block_Html_Breadcrumbs class. You can achieve like this:
<?php
echo $this->getLayout()->getBlock("breadcrumbs")->
->addCrumb('CrumbName', array('label' => 'this will appear as link text', 'title' => 'title attribute of link', 'link' => 'url to the page')
->toHtml()
?>
You can also do this in xml config file. In catalog.xml catalog_seo_sitemap handler do the following changes:
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb"><crumbName>Name</crumbName><crumbInfo><label>Test</label><title>Test</title><link>/test.html</link></crumbInfo></action>
</block>
</reference>

Related

Magento 1.9.2.1: Color, size attribute of product not showing on onepage checkout

Recently I have added attributes to the product color and size. (configurable products)
When we add to cart, and go to view cart then we see the products with attributes color and size.
I added shopping cart block in onepage checkout in app/design/frontend/smartwave/porto/layout/iwd_opc.xml
<reference name="content">
<block type="checkout/cart" name="checkout.cart" template="checkout/cart.phtml">
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
<block type="checkout/cart_sidebar" name="checkout.cart.sidebar" as="sidebar" template="checkout/cart/sidebar.phtml"/>
</block>
</reference>
I get the following page after adding shopping cart layout to onepage cart
Now I am stuck here, how should I get the attributes name here?
I have set attributes to be visible on frontend from backend as well.
Code to display products in the cart is on app/design/frontend/smartwave/porto/template/checkout/cart.phtml
<?php foreach($this->getItems() as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
Logic of the code is written over here: app/code/core/Mage/Checkout/Block
public function getItems()
{
if ($this->getCustomItems()) {
return $this->getCustomItems();
}
return parent::getItems();
}
Another way of displaying the products to the cart is: But I dont want to use this code to display the list in the cart:
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
$productName = $item->getProduct()->getName();
$productPrice = $item->getProduct()->getPrice();
echo "Name: ".$productName." Price: ".$productPrice;
}
I have also tried to add attributes in xml file
app/code/core/Mage/Sales/etc/config.xml
<item>
<product_attributes>
<color/>
<size/>
<condition/>
<sku/>
<type_id/>
<name/>
<status/>
<visibility/>
<price/>
<weight/>
<url_path/>
<url_key/>
<thumbnail/>
<small_image/>
<tax_class_id/>
<special_from_date/>
<special_to_date/>
<special_price/>
<cost/>
<is_recurring/>
<recurring_profile/>
<gift_message_available/>
<msrp_enabled/>
<msrp/>
<msrp_display_actual_price_type/>
</product_attributes>
</item>
So I have just copied the block to the onepage checkout page, but I am not able to understand that why the onepage checkout page is not showing product's size and color ("/onepage/") and it is strange that color and sizes can be seen on checkout page ("checkout/cart/")
Thanks in advance
I believe you have not added itemrendere in your layout. Basically cart items are listed using checkout/cart/item/default.phtml.
I will suggest to look over checkout.xml layout file and copy the whole layout <reference name="content"> node into your iwd and then start removing the template includes which you do not require.
Another method is using layout updates which will extend your iwd layout to checkout_cart. Which will do same thing above. You need to use <remove name=""> tag to remove extra cart includes from your iwd handle.
Finally I found the solution with the help of Blastfreak
Include following lines in app/design/frontend/smartwave/porto/layout/iwd_opc.xml
<reference name="content">
<block type="checkout/cart" name="checkout.cart" template="checkout/cart.phtml">
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
<block type="checkout/cart_sidebar" name="checkout.cart.sidebar" as="sidebar" template="checkout/cart/sidebar.phtml"/>
<action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/item/default.phtml</template></action>
<action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/item/default.phtml</template></action>
</block>
</reference>
Output page:

magento layered navigation on home page - filtered items have wrong urls, causes 404

After a lot of searching, I finally found a solution to add Layered navigation to the Magento Home Page. At first glance, it was working properly with filtered results as expected.
However, there is a catch as the URLs for the filtered results all have an added 'root-catalog' in their urls. This causes a 404 - however, if I take out the 'root-catalog' the urls are working fine.
What am I missing? Please help!
Help is appreciated in advance!
Code to add layered navigation to home page:
<reference name="left">
<block type="catalog/navigation" name="catalog.cat.leftnav" before="sidenav.left" template="catalog/navigation/left.phtml"/>
<block type="catalog/layer_view" name="catalog.leftnav" after="catalog.cat.leftnav" template="catalog/layer/view.phtml"/>
<action method="unsetChild"><alias>right.reports.product.viewed</alias></action>
<action method="unsetChild"><alias>right.reports.product.compared</alias></action>
</reference>
<reference name="content">
<block type="catalog/product_list" name="product_home" template="catalog/product/list.phtml">
<action method="setCategoryId">[b]<category_id>3</category_id>[/b]</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>
Layered navigation needs a category on which to base to get products, sub categories on which to filter, etc. On the homepage then, it takes the root category by default, and the corresponding product collection acts like it would do on other "common" category pages : it uses URL rewrites linking to the current category.
To prevent current category to be used in product URL, you can rewrite the layer model by copying the file app/code/core/Mage/Catalog/Model/Layer.php to app/code/local/Mage/Catalog/Model/, and changing the prepareProductCollection($collection) in it with something like this :
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents();
if ($this->getCurrentCategory()->getId() == $this->getCurrentStore()->getRootCategoryId()) {
$collection->addUrlRewrite(0);
} else {
$collection->addUrlRewrite($this->getCurrentCategory()->getId());
}
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return $this;
}

Passing variable to Magento widget

I'm trying to pass a variable using setData to a box containing a widget with this:
$this->getChild('my_box')->setData('myvar', '123');
echo $this->getChildHtml('my_box');
or this:
echo $this->getChild('my_box')->setData('myvar', '123')->toHtml();
The "my_box" is the block linked with the widget, it's positioned in the footer and defined in local.xml:
<reference name="footer">
<block type="core/text_list" name="my_box" as="my_box" translate="label">
<label>My Box</label>
</block>
</reference>
But if I try to retrieve the value in the widget with any of these methods:
echo $this->getData('myvar');
echo $this->getMyVar();
echo $this->myvar;
there is no return value, any suggestion?
Outside of a rewrite, "core/text_list" is an instance of Mage_Core_Block_Text_List (link) and would not have a template for you to call your code.
You can verify that the basic functionality is working, though:
$my_box = $this->getChild('my_box')->setData('myvar','123'); //if no error, my_box exists!
echo get_class($my_box); //Mage_Core_Block_Text_List
var_dump($my_box->debug()); //array() including 'myvar' => '123'
echo $my_box->getData('myvar')` //correct
echo $my_box->myvar //works, but unconventional
echo $my_box->getMyVar() //will not access the property you set; rather...
echo $my_box->getMyvar() //will work
For other fun, you can set properties via layout XML:
<reference name="footer">
<block type="core/text_list" name="my_box" as="my_box" translate="label">
<label>My Box</label>
<action method="setMyvar">
<arbitrary>123</arbitrary>
</action>
<!-- or <action method="setDatar">
<name>myvar</name>
<val>123</arbitrary>
</action> -->
</block>
</reference>
Also, do be aware the the footer block is permanently cached in the block_html cache by default.

Specific category layout update, custom product collection - missing toolbar?

In local.xml, I created a layout update so I can display a custom filtered product collection.
This is in local.xml:
<CATEGORY_7>
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/cashcrop.phtml">
<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>
<action method="setColumnCount"><columns>4</columns></action>
</block>
</block>
</CATEGORY_7>
The template file is a copy of list.phtml, but modified to filter the collection:
<?php
$_productCollection = Mage::getModel('catalog/product')->getCollection();
//$_productCollection=$this->getLoadedProductCollection();
$_productCollection
->addAttributeToSelect('*')
//->addAttributeToFilter('status', 1)
//->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('randament', array('in' => array(101, 102)))
->load()
;
$this->setCollection($_productCollection);
$_helper = $this->helper('catalog/output');
?>
This works, I get 105 products in the collection. The problem is the toolbar - it is not being shown. Has anyone any idea why the toolbar is not shown? (I know this <?php echo $this->getToolbarHtml(); ?> return an empty string, but I don't understand why.
Any help appreciated.
Cheers,
Michael.
You don't need to re-initialize everything. Try this and see if it works:
<CATEGORY_7>
<reference name="product_list">
<action method="setTemplate">
<tpl>catalog/product/cashcrop.phtml</tpl>
</action>
</reference>
</CATEGORY_7>
Also, I would be wary of using auto-increment data in scripts or layout files. I'd be inclined to put this in the layout update for the category in the DB. May not be a concern for your environment, but the 7 is an arbitrary feature from the storage backend as opposed to something that is more meaningful, such as the category name.
Actually, I figured it out myself. Overriding the template is fine, and it's enough if placed in the category's Custom Layout Update section; no need to place it in local.xml.
The trouble is with the _beforeHtml() function in Mage/Catalog/Block/Product/List.php, where the toolbar is being initialized by the blocks' _getProductCollection() function which always returns an empty collection, because it tries to obtain the current category's product collection.
So as a quick and dirty fix, I simply copied the code from _beforeHtml() function, and inserted it directly in my cashcrop.phtml template. The top of the template looks like this now:
<?php
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToSelect('*')
->addAttributeToFilter('randament', array('in' => array(101, 102)))
->addAttributeToFilter('inflorire', array('in' => array(97)))
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);
$_helper = $this->helper('catalog/output');
$toolbar = $this->getToolbarBlock();
$collection = $_productCollection;
// use sortable parameters
if ($orders = $this->getAvailableOrders()) {
$toolbar->setAvailableOrders($orders);
}
if ($sort = $this->getSortBy()) {
$toolbar->setDefaultOrder($sort);
}
if ($dir = $this->getDefaultDirection()) {
$toolbar->setDefaultDirection($dir);
}
if ($modes = $this->getModes()) {
$toolbar->setModes($modes);
}
// set collection to toolbar and apply sort
$toolbar->setCollection($_productCollection);
$this->setChild('toolbar', $toolbar);
Mage::dispatchEvent('catalog_block_product_list_collection', array(
'collection' => $_productCollection
));
$_productCollection->load();
?>
I am aware this may not be the ideal solution, but it's working. If anyone else has a better solution, I would love to hear about it.
Cheers,
Michael.

Add a calendar in Magento frontend

How can I add a calendar popup in the Magento frontend for a custom form?
Just add this code in your indexAction():
$this->loadLayout();
$blockCal = $this->getLayout()->createBlock(
'Mage_Core_Block_Html_Calendar',
'html_calendar',
array('template' => 'page/js/calendar.phtml')
);
$this->getLayout()->getBlock('content')->append($blockCal);
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->addJs('calendar/calendar.js');
$headBlock->addJs('calendar/lang/calendar-en.js');
$headBlock->addJs('calendar/calendar-setup.js');
you can also define it in a layout file like this:
<reference name="head">
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>

Resources