1

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;
    }
    }
0

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.

  • i tried this but after veiwing source code it does not showing those meta description, keywords which are in database – Neeya Jan 30 '17 at 8:29
  • where it's not showing ? – Arunendra Jan 30 '17 at 9:02
  • i have added seller when creating seller i have fill this textarea but when i view page source code it is not showing those values which i have filled from admin panel – Neeya Jan 30 '17 at 9:26
  • but in database it is showing – Neeya Jan 30 '17 at 9:26
  • Can you share any screen shot – Arunendra Jan 30 '17 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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