protected function getAccSettingsSectionHtml()
    {
        $url = $this->getUrl('adminhtml/adminform/settings');
        $formKey = Mage::getSingleton('core/session')->getFormKey();
        $email = $this->config->getEmail();
        $password = $this->config->getPassword();
        $apiKey = $this->config->getApiKey();
        $shopId = $this->config->getShopId();
        $html = <<<HTML
                <form id="edit_form" name="edit_form" method="post" action="{$url}">
                    <input name="form_key" type="hidden" value="{$formKey}" />
                    <input name="store" type="hidden" value="{$this->storeCode}" />
                    <h4 class="icon-head head-edit-form fieldset-legend">{$this->__('Account Settings')}</h4>
                    <fieldset id="my-fieldset">
                        <table cellspacing="0" class="form-list">
                            <tr>
                                <td class="label">{$this->__('Email Address')} </td>
                                <td class="input-ele">
                                    <input class="input-text" name="config[login]" size="40" maxlength="32" value="{$email}"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">{$this->__('Password')}</td>
                                <td class="input-ele">
                                    <input type="password" class="input-text" name="config[password]" size="40" maxlength="128" value="{$password}"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">{$this->__('API Key')} </td>
                                <td class="input-ele">
                                    <input class="input-text" name="config[api_key]" size="40" maxlength="32" value="{$apiKey}"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">{$this->__('Shop ID')} </td>
                                <td class="input-ele">
                                    <input class="input-text" name="config[shop_id]" size="40" maxlength="32" value="{$shopId}"/>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><button>Save</button></td>
                            </tr>    
                        </table>
                    </fieldset>
                </form>
HTML;
        return $html;
    }
 public function loginAction()
 {
     $this->shopUrl = urlencode(Mage::app()->getStore()->getBaseUrl());
     $this->shopName = urlencode(Mage::app()->getStore()->getName());
     $params = $this->getRequest()->getParams();
     $config = new Clearcode_Addshoppers_Helper_Config($params['store']);
     if ($config->getActive() != 1) {
         $config->setSocialEnabled(1);
         $params['configuration']['social'] = 1;
         $config->setOpenGraphEnabled(1);
         $params['configuration']['opengraph'] = 1;
         $config->setSchemaEnabled(1);
         $params['configuration']['use_schema'] = 1;
     }
     $data = "login="******"&password="******"&url=" . $this->shopUrl . "&category=Other" . "&phone=" . urlencode($config->getPhone()) . "&platform=" . $this->platform . "&site_name=" . $this->shopName;
     $return = $this->sendRequestWithBasicAuth($this->api_url . '/login', $data);
     if ($return['result'] == 17) {
         $message = Clearcode_Addshoppers_Block_Adminform::DOMAIN_BANNED;
     } elseif ($return['result'] == 11) {
         $message = Clearcode_Addshoppers_Block_Adminform::WRONG_CREDENTIAL;
     } elseif ($return['result'] == 1 || $return['result'] == 15 || $return['result'] == 10) {
         if ($return['result'] == 10) {
             if (isset($params['login']['login']) && isset($params['login']['password'])) {
                 $message = "LOGIN_MISSING_PARAMETER";
                 $data = "login="******"&password="******"&url=" . $this->shopUrl . "&category=" . urlencode($config->getCategory()) . "&phone=" . urlencode($config->getPhone()) . "&platform=" . $this->platform . "&site_name=" . $this->shopName;
                 $return = $this->sendRequestWithBasicAuth($this->api_url . '/login', $data);
                 // $this->getResponse()->setBody(var_dump($return));
                 if (!isset($return['shopid'])) {
                     $return['shopid'] = $config->getShopId();
                 }
                 if (!isset($return['api_key'])) {
                     $return['api_key'] = $config->getApiKey();
                 }
                 $buttons_codes = $this->getButtonsCode($return['shopid'], $return['api_key']);
                 $buttons_code_html = '';
                 if ($params['configuration']['social']) {
                     $buttons_code_html = '<div style="float:right;">' . $buttons_codes['buttons']['button2'] . '</div>';
                 }
                 if ($params['configuration']['opengraph']) {
                     $buttons_code_html = $buttons_code_html . $buttons_codes['buttons']['open-graph'];
                 }
                 if ($buttons_code_html == '') {
                     $buttons_code_html = $buttons_codes['buttons']['button1'];
                 }
                 if (!isset($buttons_codes['buttons']['button2'])) {
                     $config->setApiKey('9NF-HtmcFlwYOCOCpRJRwv6smHChiubg');
                     $buttons_code_html = '<div class="share-buttons share-buttons-panel" data-style="medium" data-counter="true" data-oauth="true" data-hover="true" data-buttons="twitter,facebook,pinterest"></div><div style="float:right;"><div class="share-buttons-multi"><div class="share-buttons share-buttons-fb-like" data-style="standard"></div><div class="share-buttons share-buttons-og" data-action="want" data-counter="false"></div><div class="share-buttons share-buttons-og" data-action="own" data-counter="false"></div></div></div>';
                 }
                 $config->setButtonsCode($buttons_code_html);
                 $config->setActive(1);
                 $config->setSocialEnabled($params['configuration']['social']);
                 $config->setOpenGraphEnabled($params['configuration']['opengraph']);
                 $config->setEmail($params['login']['login']);
                 $config->setPassword($params['login']['password']);
                 $config->setCategory($params['login']['category']);
                 $config->setShopId($return['shopid']);
                 $config->setApiKey($return['api_key']);
                 $config->setUrl($this->shopUrl);
                 $this->redirectBack($params['store']);
             }
         }
         if (isset($params['configuration']['use_schema'])) {
             $params['configuration']['use_schema'] = 1;
         }
         if (isset($params['configuration']['social'])) {
             $params['configuration']['social'] = 1;
         }
         if (isset($params['configuration']['opengraph'])) {
             $params['configuration']['opengraph'] = 1;
         }
         $config->setEnabled(1);
         $config->setSchemaEnabled($params['configuration']['use_schema']);
         $config->setApiKey($return['api_key']);
         $buttons_codes = $this->getButtonsCode($return['shopid'], $return['api_key']);
         $buttons_code_html = '';
         if ($params['configuration']['social']) {
             $buttons_code_html = '<div style="float:right;">' . $buttons_codes['buttons']['button2'] . '</div>';
         }
         if ($params['configuration']['opengraph']) {
             $buttons_code_html .= $buttons_codes['buttons']['open-graph'];
         }
         if ($buttons_code_html == '') {
             $buttons_code_html = $buttons_codes['buttons']['button1'];
         }
         $config->setButtonsCode($buttons_code_html);
         $config->setActive(1);
         $config->setSocialEnabled($params['configuration']['social']);
         $config->setOpenGraphEnabled($params['configuration']['opengraph']);
         $config->setEmail($params['login']['login']);
         $config->setPassword($params['login']['password']);
         $config->setCategory('Other');
         $config->setShopId($return['shopid']);
         $config->setApiKey($return['api_key']);
         $config->setUrl($this->shopUrl);
         $message = 'AUTHENTICATED';
     } else {
         $message = 'Unknown exception.';
     }
     Mage::getSingleton('core/session')->setData('message', array('value' => $message));
     Mage::app()->getCache()->clean();
     $this->redirectBack($params['store']);
 }
Exemple #3
0
 /**
  * Returns shop ID
  * 
  * @return string AddShoppers Shop ID
  */
 public function getShopId()
 {
     return $this->config->getShopId();
 }