예제 #1
0
 public function testProcessWithoutStoreCode()
 {
     $path = 'rest/V1/customerAccounts/createCustomer';
     $result = $this->pathProcessor->process($path);
     $this->assertEquals('/V1/customerAccounts/createCustomer', $result);
     $this->assertEquals('default', $this->storeManager->getStore()->getCode());
 }
예제 #2
0
 /**
  * Log out user and redirect him to new admin custom url
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function afterCustomUrlChanged()
 {
     if (is_null($this->_coreRegistry->registry('custom_admin_path_redirect'))) {
         return;
     }
     $this->_authSession->destroy();
     $route = $this->_backendData->getAreaFrontName();
     $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
     exit(0);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function postToConsumer($consumerId, $endpointUrl)
 {
     try {
         $consumer = $this->_consumerFactory->create()->load($consumerId);
         if (!$consumer->getId()) {
             throw new \Magento\Framework\Oauth\Exception(__('A consumer with ID %1 does not exist', $consumerId), OauthInterface::ERR_PARAMETER_REJECTED);
         }
         $consumerData = $consumer->getData();
         $verifier = $this->_tokenFactory->create()->createVerifierToken($consumerId);
         $storeBaseUrl = $this->_storeManager->getStore()->getBaseUrl();
         $this->_httpClient->setUri($endpointUrl);
         $this->_httpClient->setParameterPost(['oauth_consumer_key' => $consumerData['key'], 'oauth_consumer_secret' => $consumerData['secret'], 'store_base_url' => $storeBaseUrl, 'oauth_verifier' => $verifier->getVerifier()]);
         $maxredirects = $this->_dataHelper->getConsumerPostMaxRedirects();
         $timeout = $this->_dataHelper->getConsumerPostTimeout();
         $this->_httpClient->setConfig(['maxredirects' => $maxredirects, 'timeout' => $timeout]);
         $this->_httpClient->request(\Magento\Framework\HTTP\ZendClient::POST);
         return $verifier->getVerifier();
     } catch (\Magento\Framework\Model\Exception $exception) {
         throw $exception;
     } catch (\Magento\Framework\Oauth\Exception $exception) {
         throw $exception;
     } catch (\Exception $exception) {
         $this->_logger->critical($exception);
         throw new \Magento\Framework\Oauth\Exception('Unable to post data to consumer due to an unexpected error');
     }
 }
예제 #4
0
 /**
  * Get scope name and scopeId
  * @todo refactor to scope resolver
  * @return void
  */
 private function initScope()
 {
     if (is_null($this->getSection())) {
         $this->setSection('');
     }
     if (is_null($this->getWebsite())) {
         $this->setWebsite('');
     }
     if (is_null($this->getStore())) {
         $this->setStore('');
     }
     if ($this->getStore()) {
         $scope = 'stores';
         $store = $this->_storeManager->getStore($this->getStore());
         $scopeId = (int) $store->getId();
         $scopeCode = $store->getCode();
     } elseif ($this->getWebsite()) {
         $scope = 'websites';
         $website = $this->_storeManager->getWebsite($this->getWebsite());
         $scopeId = (int) $website->getId();
         $scopeCode = $website->getCode();
     } else {
         $scope = 'default';
         $scopeId = 0;
         $scopeCode = '';
     }
     $this->setScope($scope);
     $this->setScopeId($scopeId);
     $this->setScopeCode($scopeCode);
 }
예제 #5
0
 /**
  * Perform operations after collection load
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     $items = $this->getColumnValues('page_id');
     if (count($items)) {
         $connection = $this->getConnection();
         $select = $connection->select()->from(['cps' => $this->getTable('cms_page_store')])->where('cps.page_id IN (?)', $items);
         $result = $connection->fetchPairs($select);
         if ($result) {
             foreach ($this as $item) {
                 $pageId = $item->getData('page_id');
                 if (!isset($result[$pageId])) {
                     continue;
                 }
                 if ($result[$pageId] == 0) {
                     $stores = $this->_storeManager->getStores(false, true);
                     $storeId = current($stores)->getId();
                     $storeCode = key($stores);
                 } else {
                     $storeId = $result[$item->getData('page_id')];
                     $storeCode = $this->_storeManager->getStore($storeId)->getCode();
                 }
                 $item->setData('_first_store_id', $storeId);
                 $item->setData('store_code', $storeCode);
                 $item->setData('store_id', [$result[$pageId]]);
             }
         }
     }
     $this->_previewFlag = false;
     return parent::_afterLoad();
 }
예제 #6
0
 /**
  * Parse \Exception Response Body
  *
  * @param string $message \Exception message to parse
  * @param null|\Magento\Catalog\Model\Product $product
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function parseGdataExceptionMessage($message, $product = null)
 {
     $result = [];
     foreach (explode("\n", $message) as $row) {
         if (trim($row) == '') {
             continue;
         }
         if (strip_tags($row) == $row) {
             $row = preg_replace('/@ (.*)/', __('See \'\\1\''), $row);
             if (!is_null($product)) {
                 $row .= ' ' . __("for product '%1' (in '%2' store)", $product->getName(), $this->_storeManager->getStore($product->getStoreId())->getName());
             }
             $result[] = $row;
             continue;
         }
         // parse not well-formatted xml
         preg_match_all('/(reason|field|type)=\\"([^\\"]+)\\"/', $row, $matches);
         if (is_array($matches) && count($matches) == 3 && is_array($matches[1]) && count($matches[1]) > 0) {
             $c = count($matches[1]);
             for ($i = 0; $i < $c; $i++) {
                 if (isset($matches[2][$i])) {
                     $result[] = ucfirst($matches[1][$i]) . ': ' . $matches[2][$i];
                 }
             }
         }
     }
     return implode(". ", $result);
 }
예제 #7
0
 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Framework\Store\StoreManagerInterface $storeManager
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param array $data
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Store\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, array $data = [])
 {
     parent::__construct($context);
     $this->_scopeConfig = $scopeConfig;
     $this->_currentStore = isset($data['current_store']) ? $data['current_store'] : $storeManager->getStore();
     if (!$this->_currentStore instanceof \Magento\Store\Model\Store) {
         throw new \InvalidArgumentException('Required store object is invalid');
     }
     $this->_website = isset($data['website']) ? $data['website'] : $storeManager->getWebsite();
     if (!$this->_website instanceof \Magento\Store\Model\Website) {
         throw new \InvalidArgumentException('Required website object is invalid');
     }
 }
예제 #8
0
 /**
  * Add product to Google Content.
  *
  * @param int[] $productIds
  * @param int $storeId
  * @return $this
  * @throws \Exception|\Zend_Gdata_App_CaptchaRequiredException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function addProducts($productIds, $storeId)
 {
     $totalAdded = 0;
     $errors = [];
     if (is_array($productIds)) {
         foreach ($productIds as $productId) {
             if ($this->_flag && $this->_flag->isExpired()) {
                 break;
             }
             try {
                 $product = $this->productRepository->getById($productId, false, $storeId);
                 $item = $this->_itemFactory->create();
                 $item->insertItem($product)->save();
                 // The product was added successfully
                 $totalAdded++;
             } catch (\Magento\Framework\Exception\NoSuchEntityException $noEntityException) {
             } catch (\Zend_Gdata_App_CaptchaRequiredException $e) {
                 throw $e;
             } catch (\Zend_Gdata_App_Exception $e) {
                 $errors[] = $this->_gleShoppingData->parseGdataExceptionMessage($e->getMessage(), $product);
             } catch (\Zend_Db_Statement_Exception $e) {
                 $message = $e->getMessage();
                 if ($e->getCode() == self::ERROR_CODE_SQL_UNIQUE_INDEX) {
                     $message = __("The Google Content item for product '%1' (in '%2' store) already exists.", $product->getName(), $this->_storeManager->getStore($product->getStoreId())->getName());
                 }
                 $errors[] = $message;
             } catch (CoreException $e) {
                 $errors[] = __('The product "%1" cannot be added to Google Content. %2', $product->getName(), $e->getMessage());
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
                 $errors[] = __('The product "%1" hasn\'t been added to Google Content.', $product->getName());
             }
         }
         if (empty($productIds)) {
             return $this;
         }
     }
     if ($totalAdded > 0) {
         $this->_notifier->addNotice(__('Products were added to Google Shopping account.'), __('A total of %1 product(s) have been added to Google Content.', $totalAdded));
     }
     if (count($errors)) {
         $this->_notifier->addMajor(__('Errors happened while adding products to Google Shopping.'), $errors);
     }
     if ($this->_flag->isExpired()) {
         $this->_notifier->addMajor(__('Operation of adding products to Google Shopping expired.'), __('Some products may have not been added to Google Shopping bacause of expiration'));
     }
     return $this;
 }
예제 #9
0
 /**
  * Check whether System Base currency equals Google Content target currency or not
  *
  * @param int $storeId
  * @return boolean
  */
 public function isValidDefaultCurrencyCode($storeId = null)
 {
     return $this->_storeManager->getStore($storeId)->getDefaultCurrencyCode() == $this->getTargetCurrency($storeId);
 }
예제 #10
0
 /**
  * Retrieve homepage url
  *
  * @return string
  */
 public function getHomeUrl()
 {
     return $this->_storeManager->getStore()->getBaseUrl();
 }
예제 #11
0
 /**
  * Init merge model
  *
  * @param \Magento\Framework\View\DesignInterface $design
  * @param \Magento\Framework\Store\StoreManagerInterface $storeManager
  * @param \Magento\Framework\View\File\CollectorInterface $fileSource
  * @param \Magento\Framework\View\File\CollectorInterface $pageLayoutFileSource
  * @param \Magento\Core\Model\Resource\Layout\Update $resource
  * @param \Magento\Framework\App\State $appState
  * @param \Magento\Framework\Cache\FrontendInterface $cache
  * @param \Magento\Core\Model\Layout\Update\Validator $validator
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\View\Design\ThemeInterface $theme Non-injectable theme instance
  * @param string $cacheSuffix
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\View\DesignInterface $design, \Magento\Framework\Store\StoreManagerInterface $storeManager, \Magento\Framework\View\File\CollectorInterface $fileSource, \Magento\Framework\View\File\CollectorInterface $pageLayoutFileSource, \Magento\Core\Model\Resource\Layout\Update $resource, \Magento\Framework\App\State $appState, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Core\Model\Layout\Update\Validator $validator, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Design\ThemeInterface $theme = null, $cacheSuffix = '')
 {
     $this->_theme = $theme ?: $design->getDesignTheme();
     $this->_store = $storeManager->getStore();
     $this->_fileSource = $fileSource;
     $this->pageLayoutFileSource = $pageLayoutFileSource;
     $this->_resource = $resource;
     $this->_appState = $appState;
     $this->_cache = $cache;
     $this->_layoutValidator = $validator;
     $this->_logger = $logger;
     $this->filesystem = $filesystem;
     $this->cacheSuffix = $cacheSuffix;
 }
예제 #12
0
 /**
  * Custom setter for 'price' attribute
  *
  * @param Entry $entry
  * @param Product $product
  * @param mixed $value Fload price value
  * @param string $name Google Content attribute name
  * @return Entry
  */
 protected function _setAttributePrice($entry, $product, $value, $name = 'price')
 {
     $store = $this->_storeManager->getStore($product->getStoreId());
     $price = $this->priceCurrency->convert($value, $store);
     return $this->_setAttribute($entry, $name, self::ATTRIBUTE_TYPE_FLOAT, sprintf('%.2f', $this->priceCurrency->round($price)), $store->getDefaultCurrencyCode());
 }
예제 #13
0
 /**
  * Retrieve secure url for current request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return string
  */
 protected function _getCurrentSecureUrl($request)
 {
     $alias = $request->getAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS) || $request->getPathInfo();
     return $this->_storeManager->getStore()->getBaseUrl('link', true) . ltrim($alias, '/');
 }