/** * ItemFactory constructor. * * @param ObjectManagerInterface $objectManager The Object Manager * @param UrlInterface $urlBuilder The Url Builder * @param ScopeConfigInterface $scopeConfig The Scope Config * @param CategoryResource $categoryResource Category Resource Model */ public function __construct(ObjectManagerInterface $objectManager, UrlInterface $urlBuilder, ScopeConfigInterface $scopeConfig, CategoryResource $categoryResource) { parent::__construct($objectManager); $this->urlBuilder = $urlBuilder; $this->categoryUrlSuffix = $scopeConfig->getValue(self::XML_PATH_CATEGORY_URL_SUFFIX); $this->categoryResource = $categoryResource; }
/** * @param mixed $schedule * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function scheduledUpdateCurrencyRates($schedule) { $importWarnings = []; if (!$this->_scopeConfig->getValue(self::IMPORT_ENABLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::CRON_STRING_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return; } $errors = []; $rates = []; $service = $this->_scopeConfig->getValue(self::IMPORT_SERVICE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($service) { try { $importModel = $this->_importFactory->create($service); $rates = $importModel->fetchRates(); $errors = $importModel->getMessages(); } catch (\Exception $e) { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('We can\'t initialize the import model.'); } } else { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('Please specify the correct Import Service.'); } if (sizeof($errors) > 0) { foreach ($errors as $error) { $importWarnings[] = __('WARNING:') . ' ' . $error; } } if (sizeof($importWarnings) == 0) { $this->_currencyFactory->create()->saveRates($rates); } else { $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $importWarnings)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); } }
/** * Return whether the host from request is the backend host * @return bool */ public function isHostBackend() { $backendUrl = $this->configInterface->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE); $backendHost = parse_url(trim($backendUrl), PHP_URL_HOST); $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; return (strcasecmp($backendHost, $host) === 0); }
/** * Generate sitemaps * * @return void * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function scheduledGenerateSitemaps() { $errors = []; // check if scheduled generation enabled if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_GENERATION_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return; } $collection = $this->_collectionFactory->create(); /* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */ foreach ($collection as $sitemap) { /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ try { $sitemap->generateXml(); } catch (\Exception $e) { $errors[] = $e->getMessage(); } } if ($errors && $this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { $translate = $this->_translateModel->getTranslateInline(); $this->_translateModel->setTranslateInline(false); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); } }
/** * Create Backup * * @return $this */ public function execute() { if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) { return $this; } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(true); } $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE); $this->_errors = []; try { $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir()); $this->_coreRegistry->register('backup_manager', $backupManager); if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) { $backupManager->setRootDir($this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($this->_backupData->getBackupIgnorePaths()); } $backupManager->create(); $message = $this->_backupData->getCreateSuccessMessageByType($type); $this->_logger->info($message); } catch (\Exception $e) { $this->_errors[] = $e->getMessage(); $this->_errors[] = $e->getTrace(); $this->_logger->info($e->getMessage()); $this->_logger->critical($e); } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(false); } return $this; }
public function sendNotification($data) { if (!$data) { return false; } $this->inlineTranslation->suspend(); try { $postObject = new \Magento\Framework\DataObject(); $postObject->setData($data); $error = false; $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; /* $from = [ 'name' => '', 'email' => '' ];*/ $email_template = $this->scopeConfig->getValue('cadou/email/template'); if (empty($email_template)) { $email_template = (string) 'cadou_email_template'; // this code we have mentioned in the email_templates.xml } $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); /*$this->messageManager->addSuccess( __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.') );*/ return TRUE; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())); return FALSE; } }
/** * @dataProvider afterGetStateActiveDataProvider */ public function testAfterGetStateActive($scopeConfigMockReturnValue, $result, $assertResult) { /** @var \Magento\Checkout\Block\Cart\Shipping $subjectMock */ $subjectMock = $this->getMockBuilder('Magento\\Checkout\\Block\\Cart\\Shipping')->disableOriginalConstructor()->getMock(); $this->scopeConfigMock->expects($result ? $this->never() : $this->once())->method('getValue')->willReturn($scopeConfigMockReturnValue); $this->assertEquals($assertResult, $this->model->afterGetStateActive($subjectMock, $result)); }
/** * @param $unsecureBaseUrl * @param $useSecureInAdmin * @param $secureBaseUrl * @param $expected * @dataProvider shouldBeSecureDataProvider */ public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected) { $coreConfigValueMap = [[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl], [\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl]]; $this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap)); $this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin); $this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure('')); }
/** * @covers \Magento\Shipping\Model\Shipping\LabelGenerator * @param array $info * @dataProvider labelInfoDataProvider */ public function testAddTrackingNumbersToShipment(array $info) { $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order->expects(static::once())->method('getShippingMethod')->with(true)->willReturn($this->getShippingMethodMock()); /** * @var $shipmentMock \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject */ $shipmentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment')->disableOriginalConstructor()->getMock(); $shipmentMock->expects(static::once())->method('getOrder')->willReturn($order); $this->carrierFactory->expects(static::once())->method('create')->with(self::CARRIER_CODE)->willReturn($this->getCarrierMock()); $labelsMock = $this->getMockBuilder('\\Magento\\Shipping\\Model\\Shipping\\Labels')->disableOriginalConstructor()->getMock(); $labelsMock->expects(static::once())->method('requestToShipment')->with($shipmentMock)->willReturn($this->getResponseMock($info)); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $this->filesystem->expects(static::once())->method('getDirectoryWrite')->willReturn($this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')); $this->scopeConfig->expects(static::once())->method('getValue')->with('carriers/' . self::CARRIER_CODE . '/title', ScopeInterface::SCOPE_STORE, null)->willReturn(self::CARRIER_TITLE); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $trackMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->setMethods(['setNumber', 'setCarrierCode', 'setTitle'])->disableOriginalConstructor()->getMock(); $i = 0; $trackingNumbers = is_array($info['tracking_number']) ? $info['tracking_number'] : [$info['tracking_number']]; foreach ($trackingNumbers as $trackingNumber) { $trackMock->expects(static::at($i++))->method('setNumber')->with($trackingNumber)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setCarrierCode')->with(self::CARRIER_CODE)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setTitle')->with(self::CARRIER_TITLE)->willReturnSelf(); } $this->trackFactory->expects(static::any())->method('create')->willReturn($trackMock); /** * @var $requestMock \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ $requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->labelGenerator->create($shipmentMock, $requestMock); }
/** * Validate data * * @return bool * @throws Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _validate() { $sessionData = $_SESSION[self::VALIDATOR_KEY]; $validatorData = $this->_getSessionEnvironment(); if ($this->_scopeConfig->getValue(self::XML_PATH_USE_REMOTE_ADDR, $this->_scopeType) && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY]) { throw new Exception('Invalid session ' . self::VALIDATOR_REMOTE_ADDR_KEY . ' value.'); } if ($this->_scopeConfig->getValue(self::XML_PATH_USE_HTTP_VIA, $this->_scopeType) && $sessionData[self::VALIDATOR_HTTP_VIA_KEY] != $validatorData[self::VALIDATOR_HTTP_VIA_KEY]) { throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_VIA_KEY . ' value.'); } $httpXForwardedKey = $sessionData[self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY]; $validatorXForwarded = $validatorData[self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY]; if ($this->_scopeConfig->getValue(self::XML_PATH_USE_X_FORWARDED, $this->_scopeType) && $httpXForwardedKey != $validatorXForwarded) { throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY . ' value.'); } if ($this->_scopeConfig->getValue(self::XML_PATH_USE_USER_AGENT, $this->_scopeType) && $sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] != $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY]) { foreach ($this->_skippedAgentList as $agent) { if (preg_match('/' . $agent . '/iu', $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY])) { return true; } } throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_USER_AGENT_KEY . ' value.'); } return true; }
public function testGetLinksTitleWithoutTitle() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getLinksTitle'])->getMock(); $product->expects($this->once())->method('getLinksTitle')->willReturn(null); $this->scopeConfig->expects($this->once())->method('getValue')->with(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn('scope_config_value'); $this->assertEquals('scope_config_value', $this->helper->getLinksTitle($product)); }
public function testAfterDelete() { $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'old_value']]); $this->cacheTypeListMock->expects($this->exactly(2))->method('invalidate'); $this->model->setValue('some_value'); $this->assertSame($this->model, $this->model->afterDelete()); }
/** * Validate process * * @param \Magento\Framework\DataObject $object * @return bool * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function validate($object) { $attributeCode = $this->getAttribute()->getName(); $postDataConfig = $object->getData('use_post_data_config') ?: []; $isUseConfig = in_array($attributeCode, $postDataConfig); if ($this->getAttribute()->getIsRequired()) { $attributeValue = $object->getData($attributeCode); if ($this->getAttribute()->isValueEmpty($attributeValue) && !$isUseConfig) { return false; } } if ($this->getAttribute()->getIsUnique()) { if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { $label = $this->getAttribute()->getFrontend()->getLabel(); throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be unique.', $label)); } } if ($attributeCode == 'default_sort_by') { $available = $object->getData('available_sort_by') ?: []; $available = is_array($available) ? $available : explode(',', $available); $data = !in_array('default_sort_by', $postDataConfig) ? $object->getData($attributeCode) : $this->_scopeConfig->getValue("catalog/frontend/default_sort_by", \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if (!in_array($data, $available) && !in_array('available_sort_by', $postDataConfig)) { throw new \Magento\Framework\Exception\LocalizedException(__('Default Product Listing Sort by does not exist in Available Product Listing Sort By.')); } } return true; }
/** * @param \Magento\Framework\Controller\ResultInterface $subject * @param callable $proceed * @param ResponseHttp $response * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response) { $result = $proceed($response); $usePlugin = $this->registry->registry('use_page_cache_plugin'); if (!$usePlugin || !$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) { return $result; } if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { $cacheControlHeader = $response->getHeader('Cache-Control'); if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) { $response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue()); } $response->setHeader('X-Magento-Cache-Debug', 'MISS', true); } $tagsHeader = $response->getHeader('X-Magento-Tags'); $tags = []; if ($tagsHeader) { $tags = explode(',', $tagsHeader->getFieldValue()); $response->clearHeader('X-Magento-Tags'); } $tags = array_unique(array_merge($tags, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG])); $response->setHeader('X-Magento-Tags', implode(',', $tags)); $this->kernel->process($response); return $result; }
/** * Retrieve information from payment configuration * * @param string $field * @param int|null $storeId * * @return mixed */ public function getValue($field, $storeId = null) { if ($this->methodCode === null || $this->pathPattern === null) { return null; } return $this->scopeConfig->getValue(sprintf($this->pathPattern, $this->methodCode, $field), ScopeInterface::SCOPE_STORE, $storeId); }
/** * Get url for config settings where base url option can be changed * * @return string */ protected function _getConfigUrl() { $output = ''; $defaultUnsecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default'); $defaultSecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default'); if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER || $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER) { $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web')); } else { /** @var $dataCollection \Magento\Core\Model\Resource\Config\Data\Collection */ $dataCollection = $this->_configValueFactory->create()->getCollection(); $dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER); /** @var $data \Magento\Framework\App\Config\ValueInterface */ foreach ($dataCollection as $data) { if ($data->getScope() == 'stores') { $code = $this->_storeManager->getStore($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'store' => $code)); break; } elseif ($data->getScope() == 'websites') { $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'website' => $code)); break; } } } return $output; }
/** * @return void */ public function testExecute() { $customerId = 7; $captchaValue = 'some-value'; $email = '*****@*****.**'; $redirectUrl = 'http://magento.com/customer/account/edit/'; $captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false); $captcha->expects($this->once())->method('isRequired')->willReturn(true); $captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false); $this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha); $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]); $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false); $controller->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $controller->expects($this->any())->method('getResponse')->will($this->returnValue($response)); $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue); $customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false); $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock); $this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId); $this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true); $this->customerSessionMock->expects($this->once())->method('logout'); $this->customerSessionMock->expects($this->once())->method('start'); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email); $message = __('The account is locked. Please wait and try again or contact %1.', $email); $this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]); $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl); $this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller])); }
/** * @param array $queryParams * @return string */ public function getUrl(array $queryParams = []) { if (!$this->config->getValue('rss/config/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return ''; } return $this->urlBuilder->getUrl('rss/feed/index', $queryParams); }
/** * @return true * @throws Exception */ public function setConfig() { $posId = $this->scopeConfig->getValue(Payupl::XML_PATH_POS_ID, 'store'); if ($posId) { $this->posId = $posId; } else { throw new Exception('POS ID is empty.'); } $keyMd5 = $this->scopeConfig->getValue(Payupl::XML_PATH_KEY_MD5, 'store'); if ($keyMd5) { $this->keyMd5 = $keyMd5; } else { throw new Exception('Key MD5 is empty.'); } $secondKeyMd5 = $this->scopeConfig->getValue(Payupl::XML_PATH_SECOND_KEY_MD5, 'store'); if ($secondKeyMd5) { $this->secondKeyMd5 = $secondKeyMd5; } else { throw new Exception('Second key MD5 is empty.'); } $posAuthKey = $this->scopeConfig->getValue(Payupl::XML_PATH_POS_AUTH_KEY, 'store'); if ($posAuthKey) { $this->posAuthKey = $posAuthKey; } else { throw new Exception('POS auth key is empty.'); } return true; }
/** * @param $url * @param $host * @dataProvider hostsDataProvider */ public function testIsHostBackend($url, $host, $expectedValue) { $backendUrl = $url; $_SERVER['HTTP_HOST'] = $host; $this->scopeConfigMock->expects($this->once())->method('getValue')->with(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE)->willReturn($backendUrl); $this->assertEquals($this->model->isHostBackend(), $expectedValue); }
/** * Return Links Section Title for order item * * @return string */ public function getLinksTitle() { if ($this->_purchasedLinks->getLinkSectionTitle()) { return $this->_purchasedLinks->getLinkSectionTitle(); } return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); }
/** * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page */ public function execute() { $articleId = (int) $this->getRequest()->getParam('id'); $article = $this->articleFactory->create(); $article->load($articleId); if (!$article->isActive()) { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } $this->coreRegistry->register('current_article', $article); $resultPage = $this->resultPageFactory->create(); $title = $article->getMetaTitle() ?: $article->getName(); $resultPage->getConfig()->getTitle()->set($title); $resultPage->getConfig()->setDescription($article->getMetaDescription()); $resultPage->getConfig()->setKeywords($article->getMetaKeywords()); if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) { /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */ $breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs'); if ($breadcrumbsBlock) { $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'link' => $this->_url->getUrl('')]); $breadcrumbsBlock->addCrumb('articles', ['label' => __('Articles'), 'link' => $this->urlModel->getListUrl()]); $breadcrumbsBlock->addCrumb('article-' . $article->getId(), ['label' => $article->getName()]); } } return $resultPage; }
/** * Dispatch request * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface * @throws \Magento\Framework\Exception\NotFoundException */ public function dispatch(RequestInterface $request) { if (!$this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)) { throw new NotFoundException(__('Page not found.')); } return parent::dispatch($request); }
/** * @param int $callNumber * @param string $oldValue * @dataProvider afterSaveDataProvider */ public function testAfterSave($callNumber, $oldValue) { $this->cacheTypeListMock->expects($this->exactly($callNumber))->method('invalidate'); $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, $oldValue]]); $this->model->setValue('some_value'); $this->assertInstanceOf(get_class($this->model), $this->model->afterSave()); }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $url = $product->getProductUrl(false); if ($url) { $isStoreInUrl = $this->_scopeConfig->isSetFlag(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if (!$isStoreInUrl) { $urlInfo = parse_url($url); $store = $product->getStore()->getCode(); if (isset($urlInfo['query']) && $urlInfo['query'] != '') { $url .= '&___store=' . $store; } else { $url .= '?___store=' . $store; } } $links = $entry->getLink(); if (!is_array($links)) { $links = []; } $link = $entry->getService()->newLink(); $link->setHref($url); $link->setRel('alternate'); $link->setType('text/html'); if ($product->getName()) { $link->setTitle($product->getName()); } $links[0] = $link; $entry->setLink($links); } return $entry; }
/** * @param string $currencyFrom * @param string $currencyTo * @param int $retry * @return float|null */ protected function _convert($currencyFrom, $currencyTo, $retry = 0) { $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL); $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url); try { sleep($this->_scopeConfig->getValue('currency/google/delay', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $response = $this->_httpClient->setUri($url)->setConfig(['timeout' => $this->_scopeConfig->getValue('currency/google/timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)])->request('GET')->getBody(); $data = explode('bld>', $response); if (empty($data[1])) { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); return null; } $data = explode($currencyTo, $data[1]); $rate = null; if (empty($data[0])) { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); return null; } else { $rate = $data[0]; } return (double) $rate; } catch (\Exception $e) { if ($retry == 0) { $this->_convert($currencyFrom, $currencyTo, 1); } else { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); } } }
/** * Check if RSS feed allowed * * @return bool */ public function isAllowed() { if ($this->config->getValue('rss/order/status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return true; } return false; }
/** * @dataProvider filterProvider */ public function testAddInStockFilterToCollection($configMock) { $collectionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Link\\Product\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->any())->method('joinField'); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($configMock); $this->assertNull($this->stock->addInStockFilterToCollection($collectionMock)); }
/** * @param \Magento\Sales\Model\Order\Shipment $shipment * @param RequestInterface $request * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInterface $request) { $order = $shipment->getOrder(); $carrier = $this->carrierFactory->create($order->getShippingMethod(true)->getCarrierCode()); if (!$carrier->isShippingLabelsAvailable()) { throw new \Magento\Framework\Exception\LocalizedException(__('Shipping labels is not available.')); } $shipment->setPackages($request->getParam('packages')); $response = $this->labelFactory->create()->requestToShipment($shipment); if ($response->hasErrors()) { throw new \Magento\Framework\Exception\LocalizedException(__($response->getErrors())); } if (!$response->hasInfo()) { throw new \Magento\Framework\Exception\LocalizedException(__('Response info is not exist.')); } $labelsContent = []; $trackingNumbers = []; $info = $response->getInfo(); foreach ($info as $inf) { if (!empty($inf['tracking_number']) && !empty($inf['label_content'])) { $labelsContent[] = $inf['label_content']; $trackingNumbers[] = $inf['tracking_number']; } } $outputPdf = $this->combineLabelsPdf($labelsContent); $shipment->setShippingLabel($outputPdf->render()); $carrierCode = $carrier->getCarrierCode(); $carrierTitle = $this->scopeConfig->getValue('carriers/' . $carrierCode . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipment->getStoreId()); if (!empty($trackingNumbers)) { $this->addTrackingNumbersToShipment($shipment, $trackingNumbers, $carrierCode, $carrierTitle); } }
public function testAuthorize() { $paymentAction = 'some_action'; $this->scopeConfigMock->expects($this->any())->method('getValue')->with('payment/paymentmethod_directpost/payment_action', 'store', null)->willReturn($paymentAction); $this->paymentMock->expects($this->once())->method('setAdditionalInformation')->with('payment_type', $paymentAction); $this->directpost->authorize($this->paymentMock, 10); }