Magento – How to add meta tag. meta description, meta kywords in custom module of admin panel

custom-optionsmagento-1.9meta-tags

I have created the custom module. but at the time of creating seller, I want an additional text box to add meta tag. meta description, meta keywords same like "add product" form in Magento admin panel.

Indexcontroller.php

 public function createPostAction() {
    $session = Mage::getSingleton('customer/session');
    if ($session->isLoggedIn()) {
        $this->_redirect('demoreq/seller/dashboard');
        return;
    }

    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost();

        /* save a customer */
        $customer = Mage::getModel("customer/customer");
        $confirmkey = $customer->getRandomConfirmationKey();

        $customer->setWebsiteId(Mage::app()->getWebsite()->getId())
                ->setStore(Mage::app()->getStore())
                ->setFirstname($data['firstname'])
                ->setLastname($data['lastname'])
                ->setEmail($data['email'])
                ->setPassword($data['password'])
                ->setGroupId(6)
                ->setConfirmation($confirmkey);

        try {
            $customer->save();
            $customer->sendNewAccountEmail(
                    'confirmation', Mage::getUrl('demoreq/seller/login'), Mage::app()->getStore()->getId()
            );

            /* save a seller */
            $seller = Mage::getModel('demoreq/seller');
            $data['customerid'] = $customer->getId();
            $lastid = Mage::getModel('demoreq/seller')->getCollection()->getLastItem()->getSellerid();
            ++$lastid;
            $vendorid = "GIS" . str_pad($lastid, 3, "0", STR_PAD_LEFT);
            $data['vendor_code'] = $vendorid;
            Mage::getModel('demoreq/seller')->setData($data)->save();
            $session->setData('sellerdata', '');
            Mage::getSingleton('core/session')->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link.'));

            //send confirm message
            $url = "http://167.114.117.218/rest/services/sendSMS/sendGroupSms?AUTH_KEY=edc6dda5c95eb6534d8878d711c6d6e4";
            $postData = array(
                'mobileNumbers' => $data['phone'],
                'smsContent' => "you are registered on posforyou.",
                'senderId' => "DEMOOS",
                'routeId' => 1,
                'smsContentType' => "english"
            );
            $data_json = json_encode($postData);

            // init the resource
            $ch = curl_init();

            curl_setopt_array($ch, array(
                CURLOPT_URL => $url,
                CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json)),
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => $data_json,
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0
            ));

            //get response
            $output = curl_exec($ch);

            //Print error if any
            if (curl_errno($ch)) {
                echo 'error:' . curl_error($ch);
            }
            curl_close($ch);

            $this->_redirect('demoreq/seller/login');
        } catch (Mage_Core_Exception $e) {
            $session->setData('sellerdata', $data);
            $message = $e->getMessage();
            Mage::getSingleton('core/session')->addError($message);
            $this->_redirect('demoreq/seller/create');
        }
        return;
    }
    }

Best Answer

You can add these (meta_title,meta_keyword,meta_description) fields in your module table.

Then add this code in your module form of adminhtml

$fieldset->addField("meta_title", "text", array(
        "label" => Mage::helper("demoreq")->__("Meta Title"),
        "name" => "meta_title",
        'required' => 'required',
));
$fieldset->addField("meta_keyword", "textarea", array(
        "label" => Mage::helper("demoreq")->__("Meta Keyword"),
        "name" => "meta_keyword",
        'required' => 'required',
));
$fieldset->addField("meta_description", "textarea", array(
        "label" => Mage::helper("demoreq")->__("Meta Description"),
        "name" => "meta_description",
        'required' => 'required',
));

[EDIT] If you want set these vale on front-end then you can set it via your frontend controller.For this add this code.

$this->loadLayout();
/* get you title, description, and key here 
*
*/
$this->getLayout()->getBlock('head')->setTitle($title);
$this->getLayout()->getBlock('head')->setDescription($description);
$this->getLayout()->getBlock('head')->setKeywords($keyword);
$this->renderLayout();

And clear your magento cache storage.

Related Topic