Posted by: james | September 24, 2009

Mage Search

Create Form_Search.xml in modules directory.

app/etc/modules/Form_Search
<?xml version=”1.0″ ?>
<config>
<modules>
<form_search>
<active>true</active>
<codePool>local</codePool>
</form_search>
</modules>
</config>

Now go to local and in that form and in that search and in that etc and create config.xml

app/code/local/form/search/etc/config.xml
<?xml version=”1.0″?>
<config>
<modules>
<form_search>

<version>0.1.0</version>        </form_search>
</modules>
<admin>
<routers>
<search>
<use>admin</use>
<args>
<module>form_search</module>                <frontName>search</frontName>

</args>
</search>
</routers>
</admin>
<global>
<blocks>
<search><class>form_search_Block</class>
</search>
<catalog>
<rewrite>
<product_view>form_search_Block_Product_View</product_view>
</rewrite>
</catalog>

</blocks>
<models>
<search>
<class>form_search_Model</class>
</search> </models>
<helpers>
<search><class>form_search_Helper</class></search>
</helpers>
</global> <adminhtml>
<acl>
<resources>
<admin>

<children>
<system>

<children>
<config>

<children>

<search translate=”title” module=”search”>                                        <title>search Section</title>                                    <sort_order>60</sort_order>

</search>
</children>

</config>
</children>
</system>
</children></admin>
</resources>
</acl>
</adminhtml>
</config>

now create system.xml in etc folder

local/Form/search/etc/system.xml

<?xml version=”1.0″?>
<config>
<sections>
<search translate=”label” module=”search”>
<class>separator-top</class>
<label>search</label>
<tab>catalog</tab>

<frontend_type>text</frontend_type>
<sort_order>45</sort_order>            <show_in_default>1</show_in_default>            <show_in_website>1</show_in_website>            <show_in_store>1</show_in_store>
<groups>
<frontend translate=”label”>
<label>Search Engine optimization</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<meta_title translate=”label”>
<label>Meta Title</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_title>
<meta_title_check translate=”label”>
<label>Meta Title Enable</label>
<frontend_type>select</frontend_type>
<source_model>search/system_config_source_yesno</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_title_check>
<meta_desc translate=”label”>
<label>Meta Description</label>
<frontend_type>text</frontend_type>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_desc>
<meta_desc_check translate=”label”>
<label>Meta Description Enable</label>
<frontend_type>select</frontend_type>
<source_model>search/system_config_source_yesno</source_model>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_desc_check>
<meta_keyword translate=”label”>
<label>Meta Keyword</label>
<frontend_type>text</frontend_type>
<sort_order>5</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_keyword>
<meta_keyword_check translate=”label”>
<label>Meta Keyword Enable</label>
<frontend_type>select</frontend_type>
<source_model>search/system_config_source_yesno</source_model>
<sort_order>6</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</meta_keyword_check>
</fields>
</frontend>
</groups>
</search>
</sections>
</config>

now create data.php in helper directory..

local/form/search/helper/data.php
<?php
class form_search_Helper_Data extends Mage_Core_Helper_Abstract
{

}
?>

now create view.php in block and in product directory..

local/form/search/block/product/view.php
<?php

class  Form_search_Block_Product_View extends Mage_Catalog_Block_Product_View
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if ($headBlock = $this->getLayout()->getBlock(‘head’)) {
if(Mage::getStoreConfig(‘search/frontend/meta_title_check’) == 1)
{
$title = Mage::getStoreConfig(‘search/frontend/meta_title’);
$pattern = ‘/\{([^\{\}]*)\}/’;
preg_match_all($pattern, $title, $matches);
$start = “”;
foreach($matches[1] as $match)
{
$type = Mage::registry(‘product’)->getResource()->getAttribute($match)->getFrontendInput();
if($type == “select” || $type == “multiselect”)
{
$value = Mage::registry(‘product’)->getAttributeText($match);
}
else
{
$value = Mage::registry(‘product’)->getData($match);
}
$replace = “{“.$match.”}”;
$title = str_replace($replace,$value,$title);
}
$headBlock->setTitle($title);
}

if(Mage::getStoreConfig(‘search/frontend/meta_desc_check’) == 1)
{
$title2 = Mage::getStoreConfig(‘search/frontend/meta_desc’);
$pattern = ‘/\{([^\{\}]*)\}/’;
preg_match_all($pattern, $title2, $matches);
$start = “”;
foreach($matches[1] as $match)
{
$type = Mage::registry(‘product’)->getResource()->getAttribute($match)->getFrontendInput();
if($type == “select” || $type == “multiselect”)
{
$value = Mage::registry(‘product’)->getAttributeText($match);
}
else
{
$value = Mage::registry(‘product’)->getData($match);
}
$replace = “{“.$match.”}”;
$title2 = str_replace($replace,$value,$title2);
}
$headBlock->setDescription($title2);
}

if(Mage::getStoreConfig(‘search/frontend/meta_keyword_check’) == 1)
{
$title1 = Mage::getStoreConfig(‘search/frontend/meta_keyword’);
$pattern = ‘/\{([^\{\}]*)\}/’;
preg_match_all($pattern, $title1, $matches);
$start = “”;
foreach($matches[1] as $match)
{
$type = Mage::registry(‘product’)->getResource()->getAttribute($match)->getFrontendInput();
if($type == “select” || $type == “multiselect”)
{
$value = Mage::registry(‘product’)->getAttributeText($match);
}
else
{
$value = Mage::registry(‘product’)->getData($match);
}
$replace = “{“.$match.”}”;
$title1 = str_replace($replace,$value,$title1);
}
$headBlock->setKeywords($title1);
}
}
}
}

now to create yesno.php in model in source, path is as under..

local/form/search/Model/system/config/source/yesno.php
<?php

class  Form_search_Model_System_Config_Source_Yesno extends Mage_Core_Model_Config_Data
{

public function toOptionArray()
{
return array(
array(‘value’=>1, ‘label’=>Mage::helper(‘adminhtml’)->__(‘Yes’)),
array(‘value’=>0, ‘label’=>Mage::helper(‘adminhtml’)->__(‘No’)),
);
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: