/**
  * @param  string $feature
  * @return string
  */
 public function isFeatureEnabled($feature)
 {
     if ($this->_config->getStoreConfig('cfg/' . $feature) == 0) {
         return __('Disabled');
     }
     return __('Enabled');
 }
 /**
  * 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'));
 }
 /**
  * @param  mixed
  * @param  string
  * @param  string
  * @param  bool
  * @return void
  */
 protected function addField($fieldset, $name, $label, $isField = true)
 {
     if ($isField) {
         $options = $this->list->getFields($this->_config->getConfig(self::NAME . '/' . $name, 'none'));
     } else {
         $options = $this->list->getSegments($this->_config->getConfig(self::NAME . '/' . $name, 'none'));
     }
     $fieldset->addField($name, 'select', ['label' => __($label), 'required' => false, 'name' => $name, 'options' => $options, 'disabled' => false]);
 }
 /**
  * If plugin is locked, will return this page
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $this->_eventManager->dispatch('mperf_request', ['from' => 'Check']);
     if ($this->_config->isReady()) {
         $resultRedirect = $this->resultRedirectFactory->create();
         return $this->_redirect('*/' . $this->getRequest()->getParam('path'));
     } else {
         $this->messageManager->addWarning(__('Your MailPerformance XKey hasn\'t been validated yet or is not valid anymore'));
         $resultPageFactory = $this->_objectManager->create('Magento\\Framework\\View\\Result\\PageFactory');
         $resultPage = $resultPageFactory->create();
         return $resultPage;
     }
 }
 /**
  * @param  string
  * @return array
  */
 public function getDataFromSqlToFields($valuePrimaryKey)
 {
     $tabFromSql = $this->getSqlLine('sales_order', 'entity_id', $valuePrimaryKey);
     $nameTab = array('coupon_code', 'store_id', 'total_due', 'is_virtual', 'total_qty_ordered', 'customer_is_guest', 'coupon_rule_name', 'created_at', 'updated_at', 'order_currency_code', 'shipping_method', 'customer_firstname', 'customer_lastname', 'customer_email', 'weight', 'shipping_address_id', 'customer_group_id');
     $tabToFields = array();
     if ($tabFromSql[0]['customer_is_guest'] == 1) {
         $guestInfos = $this->getGuestName($tabFromSql[0]['billing_address_id']);
         $tabFromSql[0]['customer_firstname'] = $guestInfos['firstname'];
         $tabFromSql[0]['customer_lastname'] = $guestInfos['lastname'];
     }
     /* Retrieve chosen fields IDs */
     foreach ($nameTab as $key) {
         $fieldId = $this->cfg->getConfig('checkoutSuccess/' . $key, 'none');
         if ($fieldId != 'none') {
             $tabToFields[$fieldId] = $tabFromSql[0][$key];
         }
     }
     /* Put fields in right formart */
     $fieldTab = $this->fields->getAllFields();
     foreach ($fieldTab as $field) {
         foreach ($tabToFields as $key => &$value) {
             $this->reformat($field, $key, $value);
         }
     }
     return $tabToFields;
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * @return bool
  */
 private function checkAndSave()
 {
     $toSave = $this->getRequest()->getPostValue();
     /* Check if settings are valid for API calls, returning an error if anything goes wrong*/
     $integrity = $this->checkIntegrity($toSave);
     /* Check if there is an error and then return it */
     if ($integrity['haveError']) {
         $this->messageManager->addError($integrity['message']);
         return false;
     }
     /* Since we're fine, let's save. */
     $event = $this->getRequest()->getParam('form') . '/';
     foreach ($toSave as $key => $result) {
         if ($key != 'form_key') {
             $this->_config->saveConfig($event . $key, $result);
         }
     }
     $this->messageManager->addSuccess(__('Saved !'));
     return true;
 }