Ejemplo n.º 1
0
 /**
  * Authenticate Action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $this->_eventManager->dispatch('mperf_authenticate');
     $resultRedirect = $this->resultRedirectFactory->create();
     /* Get my own infos */
     $result = $this->_restHelper->get('me');
     if ($result['info']['http_code'] < 200 || $result['info']['http_code'] > 299) {
         return $this->redirectToError($resultRedirect, 'API ' . __('Call') . ' : \'GET\' ' . __('on') . ' \'/me\' ' . __('failed. Please check your XKey'));
     }
     $result = $result['result'];
     /* Get more infos about me */
     $contactResult = $this->_restHelper->get('contacts/' . $result['id']);
     if ($contactResult['info']['http_code'] < 200 || $contactResult['info']['http_code'] > 299) {
         return $this->redirectToError($resultRedirect, 'API ' . __('Call') . ' : \'GET\' ' . __('on') . ' \'/contacts/' . $result['id'] . '\' ' . __('failed. Please check your XKey'));
     }
     $contactResult = $contactResult['result'];
     $this->saveContactInfos($result, $contactResult);
     /* Final step: Redirect to param page */
     if ($this->_config->isReady()) {
         $this->messageManager->addSuccess(__('You succesfully linked your XKey to Magento2'));
         /* Since we just auth, we now need to generate the mailperformance pre-stored bindings */
         return $this->_redirect('*/Check/Reload', ['path' => $this->getRequest()->getParam('path')]);
     }
     return $this->redirectToError($resultRedirect, __('Unknown error, please try again later'));
 }
 public function execute($observer)
 {
     $data = $observer->getData();
     $orderId = $data['order_ids'][0];
     // FLO
     $dataJson = $this->_quote->getDataFromSqlToFields($orderId);
     $endUrl = 'targets?unicity=';
     foreach ($dataJson as $key => $value) {
         $result = $this->_quote->getSqlLine('mailperf_fields', 'id', $key);
         if ($result[0]['isUnicity'] == 1) {
             $endUrl .= $value;
         }
     }
     /* Check if target exists */
     $getResponseApi = $this->_restHelper->get($endUrl);
     /* perform a POST or PUT action depending on the previous result */
     if ($getResponseApi['info']['http_code'] == 200) {
         $endUrl = 'targets/' . $getResponseApi['result']['id'];
         $getResponseApi = $this->_restHelper->put($endUrl, $dataJson);
     } else {
         if ($getResponseApi['info']['http_code'] == 404) {
             $endUrl = 'targets/';
             $getResponseApi = $this->_restHelper->post($endUrl, $dataJson);
         } else {
             /* An error message should be there, the API call failed. */
         }
     }
     $idSegement = $this->cfg->getConfig('checkoutSuccess/segment', 'none');
     if ($idSegement != 'none') {
         $endUrl = 'targets/' . $getResponseApi['result']['id'] . '/segments/' . $idSegement;
         $getResponseApi = $this->_restHelper->post($endUrl, NULL);
     }
 }
 /**
  * @param  EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $data = $observer->getData();
     $orderId = $data['order_ids'][0];
     $orderData = $this->_quote->getOrderData($orderId);
     /* Now, lets update/create a target */
     $getResponseApi = $this->_restHelper->put('targets', $orderData);
     if (!isset($getResponseApi['result']['id'])) {
         /* Target creation/update failed */
         return 0;
     }
     $idSegement = $this->cfg->getConfig('checkoutSuccess/segment', 'none');
     if ($idSegement != 'none') {
         $endUrl = 'targets/' . $getResponseApi['result']['id'] . '/segments/' . $idSegement;
         $getResponseApi = $this->_restHelper->post($endUrl, null);
     }
 }
Ejemplo n.º 4
0
 /**
  * @return bool
  */
 public function populateFields()
 {
     $this->_getResource()->createTableFields();
     $this->_getResource()->flushFields();
     /* Make REST request */
     $result = $this->_rest->get('fields/');
     /* Check if everything went fine or lock down the module*/
     if ($result['info']['http_code'] < 200 || $result['info']['http_code'] > 299) {
         $this->cfg->saveConfig('linkstate', 'unvalid');
         return false;
     }
     /* Populate DB */
     $tab = $result['result'];
     foreach ($tab as $elem) {
         $this->saveFields(['id' => $elem['id'], 'name' => $elem['name'], 'isUnicity' => $elem['isUnicity'], 'type' => $elem['type']]);
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * @return bool
  */
 public function populateSegments()
 {
     $this->_getResource()->createTableSegments();
     $this->_getResource()->flushSegments();
     /* Make REST request */
     $result = $this->_rest->get('segments/');
     /* Check if everything went fine or lock down the module*/
     if ($result['info']['http_code'] < 200 || $result['info']['http_code'] > 299) {
         $this->cfg->saveConfig('linkstate', 'unvalid');
         return false;
     }
     /* Populate DB */
     $tab = $result['result'];
     foreach ($tab as $elem) {
         if ($elem['type'] == 'static') {
             $this->saveSegments($elem['id'], $elem['name']);
         }
     }
     return true;
 }