4

I wanted to create the meta title of product in the format of

Product Name - Category (Brand) - Company Name

I need this to be created programatically and not by updating from backend or csv.

Can anybody suggest me ?

4 Answers 4

2

You can set the page title using setTitle() method in controller.

To set title from controller, use setTitle() method between $this->loadLayout(); and $this->renderLayout();

For example:

If you are on product page and want to set title like "Product Name - Category (Brand) - Company Name", then get values of Product Name, Category (Brand) and Company Name, combine values in one variable (say $myTitle) and then use code like below:

$this->getLayout()->getBlock('head')->setTitle($this->__($myTitle));

Complete code would lok like below:

$this->loadLayout();
...
$this->getLayout()->getBlock('head')->setTitle($this->__($myTitle));
$this->renderLayout();

Please let me know if you have any query.

0
1

For company name you can create product attribute. Define an observer add below code to config.xml of your module.

    <frontend>
        <events>
            <catalog_controller_product_view>
                <observers>
                    <productchange>
                        <class>Namespace_Modulename_Model_Observer</class>
                        <method>AddMetaTagName</method>
                    </productchange>
                </observers>
            </catalog_controller_product_view>
        </events>
    </frontend>

Add observer include below code in it

class Namespace_Modulename_Model_Observer{
    public function AddMetaTagName($observer)
    {

     if ($product_id = Mage::registry('current_product')->getId()) {            
          $product = Mage::getModel('catalog/product')->load($product_id);
          $productName = $product->getName();
          //$companyName = $product->getComapnyName();
          $categoryName = Mage::registry('current_category')->getName();
          $product->setMetaTitle($productName."-".$categoryName);
      }
    }
}

It is working fine for me see in below image. Here product name is test and category name is cat-1

enter image description here

0

You can place catalog_product_save_after observer withing adminhtml tag of your module config.xml and save the meta detail of the product

<?xml version="1.0"?>
<config>
    ...
    <adminhtml>
    ...
    <events>
        <catalog_product_save_after>
            <observers>
                <product_save_after_observer>
                    <class>StackOverflow_CustomModule_Model_Observer</class>
                    <method>productSaveAfter</method>
                </product_save_after_observer>
            </observers>
        </catalog_product_save_after>
    </events>
    ...
    </adminhtml>
    ...
</config>

With the help of this event you can update the meta title of any product as you want.

0

I think for your requirement there is a free extension avaliable you can download and configure as per your requirement.

this extension fits perfectly on your requiremnt as it allows you to use category and product attribute in your meta detail

https://www.magentocommerce.com/magento-connect/simple-seo-for-set-dynamic-meta-data-for-category-and-product-and-meta-title-for-cms-page.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.