Set custom page title on home in magento - magento

I am showing only a single product on home page. I want to show the product name in page title. How can I do this?

You have multiple ways of doing this:
In your module's layout xml file (located at app/design/frontend/[package]/[theme]/layout/{your_file_name}.xml):
<reference name="head">
<action method="setTitle"><title>Title text here</title></action>
</reference>
The bad thing here is that you can't set tittle "on the fly".
In your block file (_prepareLayout() method is a good place):
public function _prepareLayout()
{
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->setTitle('Title text here');
return parent::_prepareLayout();
}
Anywhere else:
Mage::app()->getLayout()->getBlock('head')->setTitle('Title text here');
Useful link - Layouts, Blocks and Templates

Related

Magento - Set Category meta title, keywords and description

I have a category for shoes on my website. The meta title,description and keywords that I give under Catalog/Category for that category are not reflected. This is not specific to a category , I'm just quoting shoes as an example.
I dont want to use settitle,setkeyword,setdescription on layout files to set the above. Why is the default magento functionality not working.
It'd be great help if you could point out the area where the default values are applied.
For category layouts in the default magento theme, the area where the meta tags are set is :
//file: app/code/core/Mage/Catalog/Block/Category/view.php
//class: Mage_Catalog_Block_Category_View
//function: protected function _prepareLayout()
//...
$category = $this->getCurrentCategory();
if ($title = $category->getMetaTitle()) {
$headBlock->setTitle($title);
}
if ($description = $category->getMetaDescription()) {
$headBlock->setDescription($description);
}
if ($keywords = $category->getMetaKeywords()) {
$headBlock->setKeywords($keywords);
}
//...
So I think the questions to ask yourself are why is $category->getMetaTitle() falsey or what, later on in the layout, is overwriting $category->getMetaTitle() or does my theme rewrite the function Mage_Catalog_Block_Category_View::_prepareLayout().
You may want to search all your .xml files for code like this:
<reference name="head">
<action method="setTitle" translate="title" module="catalog"><title>Site Map</title></action>
</reference>
Because any module can change the meta tags using XML.

How to set active menu links under 'My Account' in Magento 2 frontend Customer Section

I've got a custom module extending the customer account section. I've added a new link called 'My Uploads'. This link appears at the bottom of the My Account links sidebar. On the index page, the 'My Uploads' link is bolded and not selectable. However on my child pages none of the links are bolded or selectable. I am searching how to keep the same link functionality in my custom module (i.e. all parent and child pages show the same sidebar link as active.) _SetActiveMenu appears to only be a method accessible in admin controllers so I really don't know any way to do this. Anyone have any clues?
If I am not mistaken, you want to add a link in Customers "My Account" Sidebar. So, navigation.php which is available in /app/code/local/themename/customer/block/account/navigation.php controling those links. There are few function inside the file, some of them :
public function isActive($link)
{
if (empty($this->_activeLink)) {
$this->_activeLink = $this->getAction()->getFullActionName('/');
}
if ($this->_completePath($link->getPath()) == $this->_activeLink) {
return true;
}
return false;
}
public function setActive($path)
{
$this->_activeLink = $this->_completePath($path);
return $this;
}
You can do it within your layout.
Example for a link named 'changepassword':
<mycompany_changepassword_index_index translate="label">
<label>Change Password Page</label>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/form_edit" name="mycompany_changepassword" template="mycompany/changepassword.phtml">
<reference name="customer_account_navigation">
<action method="setActive"><path>changepassword</path></action>
</reference>
</block>
</reference>
</mycompany_changepassword_index_index>

How to Change page Title of Magento Module?

I have successfully install magento, but site title remain magento, I try many times but did not change that title?and did not change thing under the widget? so what is the procedures?
you can do it via layout files:
<reference name="head">
<action method="setTitle" translate="title"><title>Your Title</title></action>
</reference>
or via code by accessing head block element and calling setTitle('your title') method on it
$this->getLayout()->getBlock('head')->setTitle('your title');
grep for more references:
grep '>setTitle(' app/code/ -rsn
Put this function in Block page of that Module
public function _prepareLayout()
{
$this->pageConfig->getTitle()->set(__('Your Page Title'));
return parent::_prepareLayout();
}

Display Tiered Pricing on the Cart page

If Im on this page:
http:///checkout/cart/
With products in my cart I would like to display the tiered pricing, the same that is shown on the item page, if available.
My attempt was add
<checkout_cart_index>
<block type="catalog/product_view" name="product.tierprices" as="tierprices" template="catalog/product/view/tierprices.phtml"/>
</checkout_cart_index>
to my xml file and add
<?php echo $this->getChildHtml('tierprices') ?>
to
\app\design\frontend\enterprise\<mytemplate>\template\checkout\cart\item\default.phtml
Doesn’t do anything - any further suggestions?
It seems impossible to easily change layout. You need to modify item renderer and add tier price displaying manually. To fetch list of available tier prices you need to get price model. You can get it from product model
$product->getPriceModel()
or if don't have product model try the following code
Mage::getSingleton('catalog/product_type')->priceFactory($productTypeId)
Quote item contains product type information.
When you have price model just call method getTierPrice() to get all tier prices as array.
$priceModel->getTierPrice()
You could edit the .phtml file and adding the $this->getTierPrices($_product);//or$this->getTierPrices($_item); if you simply want to display the tier prices of products.
Do note that the getTierPrices() only works when being on the product list or product view page, so you would need to copy the getTierPrices() method that can be found inside the List.php to your custom module.
This should give you an idea what needs to be done.
layout file
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_cart_index>
<reference name="additional.product.info">
<block type="LokeyCoding_Cart/TierPrice" name="additional.product.info.tierprice" />
</reference>
</checkout_cart_index>
</version>
block file
<?php
class LokeyCoding_Cart_Block_TierPrice extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$parent = $this->getParentBlock();
if ($parent) {
$item = $parent->getItem();
if ($item instanceof Mage_Sales_Model_Quote_Item) {
return $item->getProduct()->getTierPriceHtml();
}
}
return '';
}
}

Add a link to Magento's My Account Page Conditionally

I would like to create a link on the My Account page that only get displays under certain conditions.
Right now I have the link display all the time by adding the following entry to my layout XML file:
<customer_account>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="nie"><name>nie</name><path>nie</path><label>NIE Admin</label></action>
</reference>
</customer_account>
I am assuming there is a way to code this so that it only displays under certain circumstances.
The cart & checkout links already do something similar so their method can be copied.
Create a block. It won't be displaying directly so can be descended from the boring Mage_Core_Block_Abstract.
Give it a method where the conditional logic will go.
public function addNieLink()
{
if (($parentBlock = $this->getParentBlock()) && (CONDITION-GOES-HERE)) {
$parentBlock->addLink($this->_('NIE Admin'), 'nie', $this->_('NIE Admin'), true, array(), 50, null, 'class="top-link-cart"');
// see Mage_Page_Block_Template_Links::addLink()
}
}
protected function _prepareLayout()
{
// Add the special link automatically
$this->addNieLink();
return parent::_prepareLayout();
}
Put your check in place of CONDITION-GOES-HERE.
Add your block to the links block.
<customer_account>
<reference name="customer_account_navigation">
<block type="yourmodule/link" name="yourmodule.link" />
</reference>
</customer_account>
(Correct the block type here to your newly created link block)
The important bit is it calls getParentBlock() to find out where the link is to go.

Resources