/** * Load design * * @return void */ public function load() { $area = $this->_areaList->getArea($this->appState->getAreaCode()); $area->load(\Magento\Framework\App\Area::PART_DESIGN); $area->load(\Magento\Framework\App\Area::PART_TRANSLATE); $area->detectDesign($this->_request); }
/** * @param array $buildSubject * @return mixed */ public function build(array $buildSubject) { /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $payment = $paymentDataObject->getPayment(); $order = $paymentDataObject->getOrder(); $storeId = $order->getStoreId(); $request = []; if ($this->adyenHelper->getAdyenCcConfigDataFlag('cse_enabled', $storeId)) { $request['additionalData']['card.encrypted.json'] = $payment->getAdditionalInformation("encrypted_data"); } else { $requestCreditCardDetails = ["expiryMonth" => $payment->getCcExpMonth(), "expiryYear" => $payment->getCcExpYear(), "holderName" => $payment->getCcOwner(), "number" => $payment->getCcNumber(), "cvc" => $payment->getCcCid()]; $cardDetails['card'] = $requestCreditCardDetails; $request = array_merge($request, $cardDetails); } /** * if MOTO for backend is enabled use MOTO as shopper interaction type */ $enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId); if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE && $enableMoto) { $request['shopperInteraction'] = "Moto"; } // if installments is set add it into the request if ($payment->getAdditionalInformation('number_of_installments') && $payment->getAdditionalInformation('number_of_installments') > 0) { $request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments'); } return $request; }
/** * @expectedException \Exception * @expectedExceptionMessage Some error */ public function testEmulateAreaCodeException() { $areaCode = 'original code'; $emulatedCode = 'emulated code'; $this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode); $this->model->setAreaCode($areaCode); $this->model->emulateAreaCode($emulatedCode, [$this, 'emulateAreaCodeCallbackException']); $this->assertEquals($this->model->getAreaCode(), $areaCode); }
/** * @param AbstractAction $subject * @param RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(AbstractAction $subject, RequestInterface $request) { if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost() && $this->notificationStorage->isExists(NotificationStorage::UPDATE_CUSTOMER_SESSION, $this->session->getCustomerId())) { $customer = $this->customerRepository->getById($this->session->getCustomerId()); $this->session->setCustomerData($customer); $this->session->setCustomerGroupId($customer->getGroupId()); $this->session->regenerateId(); $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId()); } }
/** * @return bool */ public function isFrontendArea() { try { if ($this->state->getAreaCode() == Area::AREA_ADMINHTML) { return false; } } catch (LocalizedException $e) { /* Area is not initialized. Do nothing. */ return true; } return true; }
/** * Get translation data * * @param string $themePath * @return string[] * @throws \Exception * @throws \Magento\Framework\Exception */ public function getData($themePath) { $dictionary = []; $files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath); foreach ($files as $filePath) { $content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0])); foreach ($this->getPhrases($content) as $phrase) { $translatedPhrase = (string) __($phrase); if ($phrase != $translatedPhrase) { $dictionary[$phrase] = $translatedPhrase; } } } return $dictionary; }
/** * Parse and save edited translation * * @param array $translateParams * @return array */ public function processAjaxPost(array $translateParams) { if (!$this->_translateInline->isAllowed()) { return ['inline' => 'not allowed']; } $this->_appCache->invalidate(\Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER); $this->_validateTranslationParams($translateParams); $this->_filterTranslationParams($translateParams, ['custom']); /** @var $validStoreId int */ $validStoreId = $this->_storeManager->getStore()->getId(); /** @var $resource \Magento\Translation\Model\ResourceModel\StringUtils */ $resource = $this->_resourceFactory->create(); foreach ($translateParams as $param) { if ($this->_appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $storeId = 0; } else { if (empty($param['perstore'])) { $resource->deleteTranslate($param['original'], null, false); $storeId = 0; } else { $storeId = $validStoreId; } } $resource->saveTranslate($param['original'], $param['custom'], null, $storeId); } return $this->getCacheManger()->updateAndGetTranslations(); }
/** * Handle REST request * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { $this->checkPermissions(); $route = $this->getCurrentRoute(); if ($route->isSecure() && !$this->_request->isSecure()) { throw new \Magento\Webapi\Exception(__('Operation allowed only in HTTPS')); } /** @var array $inputData */ $inputData = $this->_request->getRequestData(); $serviceMethodName = $route->getServiceMethod(); $serviceClassName = $route->getServiceClass(); $inputData = $this->overrideParams($inputData, $route->getParameters()); $inputParams = $this->_serializer->getInputData($serviceClassName, $serviceMethodName, $inputData); $service = $this->_objectManager->get($serviceClassName); /** @var \Magento\Framework\Service\Data\AbstractExtensibleObject $outputData */ $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); $outputData = $this->dataObjectConverter->processServiceOutput($outputData); if ($this->_request->getParam(PartialResponseProcessor::FILTER_PARAMETER) && is_array($outputData)) { $outputData = $this->partialResponseProcessor->filter($outputData); } $this->_response->prepareResponse($outputData); } catch (\Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_response->setException($maskedException); } return $this->_response; }
public function getAdyenOneclickPaymentMethods() { $billingAgreements = []; if ($this->_customerSession->isLoggedIn()) { $customerId = $this->_customerSession->getCustomerId(); // is admin? if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { //retrieve storeId from quote $store = $this->_session->getQuote()->getStore(); } else { $store = $this->_storeManager->getStore(); } $baCollection = $this->_billingAgreementCollectionFactory->create(); $baCollection->addFieldToFilter('customer_id', $customerId); $baCollection->addFieldToFilter('store_id', $store->getId()); $baCollection->addFieldToFilter('method_code', 'adyen_oneclick'); $baCollection->addActiveFilter(); $recurringPaymentType = $this->_getRecurringContractType(); foreach ($baCollection as $billingAgreement) { $agreementData = $billingAgreement->getAgreementData(); // check if AgreementLabel is set and if contract has an recurringType if ($billingAgreement->getAgreementLabel()) { $data = ['reference_id' => $billingAgreement->getReferenceId(), 'agreement_label' => $billingAgreement->getAgreementLabel(), 'agreement_data' => $agreementData]; $billingAgreements[] = $data; } } } return $billingAgreements; }
/** * Retrieve package area * * @return string */ public function getArea() { // In order to support environment emulation of area, if area is set, return it if ($this->_area && !$this->_appState->isAreaCodeEmulated()) { return $this->_area; } return $this->_appState->getAreaCode(); }
/** * Retrieve instance of a theme currently used in an area * * @return \Magento\Framework\View\Design\ThemeInterface */ public function get() { $area = $this->appState->getAreaCode(); if ($this->design->getDesignTheme()->getArea() == $area || $this->design->getArea() == $area) { return $this->design->getDesignTheme(); } /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */ $themeCollection = $this->themeFactory->create(); $themeIdentifier = $this->design->getConfigurationDesignTheme($area); if (is_numeric($themeIdentifier)) { $result = $themeCollection->getItemById($themeIdentifier); } else { $themeFullPath = $area . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . $themeIdentifier; $result = $themeCollection->getThemeByFullPath($themeFullPath); } return $result; }
/** * @param InputInterface $input * @param OutputInterface $output * @return null|int */ protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; try { $area = $this->appState->getAreaCode(); if ($area != Area::AREA_ADMINHTML) { $this->appState->setAreaCode(Area::AREA_ADMINHTML); } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->appState->setAreaCode(Area::AREA_ADMINHTML); } $area = $this->appState->getAreaCode(); $configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface'); $this->objectManager->configure($configLoader->load($area)); $this->registry->register('isSecureArea', true); }
/** * Get translation data * * @param string $themePath * @return array * @throws \Exception * @throws \Magento\Framework\Exception\LocalizedException */ public function getData($themePath) { $areaCode = $this->appState->getAreaCode(); $files = array_merge($this->filesUtility->getJsFiles('base', $themePath), $this->filesUtility->getJsFiles($areaCode, $themePath), $this->filesUtility->getStaticHtmlFiles('base', $themePath), $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath)); $dictionary = []; foreach ($files as $filePath) { /** @var \Magento\Framework\Filesystem\File\Read $read */ $read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE); $content = $read->readAll(); foreach ($this->getPhrases($content) as $phrase) { $translatedPhrase = $this->translate->render([$phrase], []); if ($phrase != $translatedPhrase) { $dictionary[$phrase] = $translatedPhrase; } } } return $dictionary; }
/** * For admin use RECURRING contract for front-end get it from configuration * * @return mixed|string * @throws \Magento\Framework\Exception\LocalizedException */ public function getRecurringPaymentType() { // For admin always use Recurring if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { return \Adyen\Payment\Model\RecurringType::RECURRING; } else { return $this->adyenHelper->getAdyenOneclickConfigData('recurring_payment_type'); } }
/** * Set store_id value to quote item * * @param Item $item * @return void */ protected function setItemStoreId(Item $item) { if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $storeId = $this->storeManager->getStore($this->storeManager->getStore()->getId())->getId(); $item->setStoreId($storeId); } else { $item->setStoreId($this->storeManager->getStore()->getId()); } }
/** * @param array $buildSubject * @return array */ public function build(array $buildSubject) { $result = []; /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $payment = $paymentDataObject->getPayment(); // Needs to change when oneclick,cc using facade impl. $paymentMethodCode = $payment->getMethodInstance()->getCode(); $storeId = null; if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $storeId = $payment->getOrder()->getStoreId(); } $recurringType = $this->adyenHelper->getAdyenAbstractConfigData('recurring_type', $storeId); // set the recurring type $recurringContractType = null; if ($recurringType) { if ($paymentMethodCode == \Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider::CODE) { /* * For ONECLICK look at the recurringPaymentType that the merchant * has selected in Adyen ONECLICK settings */ if ($payment->getAdditionalInformation('customer_interaction')) { $recurringContractType = \Adyen\Payment\Model\RecurringType::ONECLICK; } else { $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING; } } else { if ($paymentMethodCode == \Adyen\Payment\Model\Ui\AdyenCcConfigProvider::CODE) { if ($payment->getAdditionalInformation("store_cc") == "" && ($recurringType == "ONECLICK,RECURRING" || $recurringType == "RECURRING")) { $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING; } elseif ($payment->getAdditionalInformation("store_cc") == "1") { $recurringContractType = $recurringType; } } else { $recurringContractType = $recurringType; } } } if ($recurringContractType) { $recurring = ['contract' => $recurringContractType]; $result['recurring'] = $recurring; } return $result; }
/** * Retrieve has verification configuration * * @return bool */ public function hasVerification() { // if backend order and moto payments is turned on don't show cvc if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $this->getCheckoutSession(); $store = $this->_checkoutSession->getQuote()->getStore(); $enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $store->getId()); if ($enableMoto) { return false; } } return true; }
/** * Initialize menu object * * @return void */ protected function _initMenu() { if (!$this->_menu) { $this->_menu = $this->_menuFactory->create(); $cache = $this->_configCacheType->load(self::CACHE_MENU_OBJECT); if ($cache) { $this->_menu->unserialize($cache); return; } $this->_director->direct($this->_configReader->read($this->_appState->getAreaCode()), $this->_menuBuilder, $this->_logger); $this->_menu = $this->_menuBuilder->getResult($this->_menu); $this->_configCacheType->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT); } }
public function getAdyenHppPaymentMethods() { $paymentMethods = null; // is admin? if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { //retrieve storeId from quote $store = $this->_session->getQuote()->getStore(); } else { $store = $this->_storeManager->getStore(); } // is adyen HPP enabled ? $hppActive = $this->methods['adyen_hpp']->isAvailable(); if ($hppActive) { $paymentMethods = $this->_addHppMethodsToConfig($store); } return $paymentMethods; }
/** * Initialize translation data * * @param string|null $area * @param bool $forceReload * @return $this */ public function loadData($area = null, $forceReload = false) { $this->setConfig(['area' => isset($area) ? $area : $this->_appState->getAreaCode()]); if (!$forceReload) { $this->_data = $this->_loadCache(); if ($this->_data !== false) { return $this; } } $this->_data = []; $this->_loadModuleTranslation(); $this->_loadThemeTranslation(); $this->_loadPackTranslation(); $this->_loadDbTranslation(); $this->_saveCache(); return $this; }
/** * Handle REST request * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if ($this->isSchemaRequest()) { $this->processSchemaRequest(); } else { $this->processApiRequest(); } } catch (\Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_response->setException($maskedException); } return $this->_response; }
/** * Dispatch SOAP request. * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if (!$this->_appState->isInstalled()) { throw new WebapiException(__('Magento is not yet installed')); } if ($this->_isWsdlRequest()) { $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_soapServer->generateUri()); $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST); $this->_setResponseBody($responseBody); } else { $this->_soapServer->handle(); } } catch (\Exception $e) { $this->_prepareErrorResponse($e); } return $this->_response; }
/** * Address after save event handler * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute(\Magento\Framework\Event\Observer $observer) { /** @var $customerAddress Address */ $customerAddress = $observer->getCustomerAddress(); $customer = $customerAddress->getCustomer(); if (!$this->_customerAddress->isVatValidationEnabled($customer->getStore()) || $this->_coreRegistry->registry(self::VIV_PROCESSED_FLAG) || !$this->_canProcessAddress($customerAddress)) { return; } try { $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, true); if ($customerAddress->getVatId() == '' || !$this->_customerVat->isCountryInEU($customerAddress->getCountry())) { $defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId(); if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) { $customer->setGroupId($defaultGroupId); $customer->save(); $this->customerSession->setCustomerGroupId($defaultGroupId); } } else { $result = $this->_customerVat->checkVatNumber($customerAddress->getCountryId(), $customerAddress->getVatId()); $newGroupId = $this->_customerVat->getCustomerGroupIdBasedOnVatNumber($customerAddress->getCountryId(), $result, $customer->getStore()); if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $newGroupId) { $customer->setGroupId($newGroupId); $customer->save(); $this->customerSession->setCustomerGroupId($newGroupId); } $customerAddress->setVatValidationResult($result); if ($this->appState->getAreaCode() == Area::AREA_FRONTEND) { if ($result->getIsValid()) { $this->addValidMessage($customerAddress, $result); } elseif ($result->getRequestSuccess()) { $this->addInvalidMessage($customerAddress); } else { $this->addErrorMessage($customerAddress); } } } } catch (\Exception $e) { $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, false, true); } }
/** * Configure session handler and start session * * @throws \Magento\Framework\Exception\SessionException * @return $this */ public function start() { if (!$this->isSessionExists()) { \Magento\Framework\Profiler::start('session_start'); try { $this->appState->getAreaCode(); } catch (\Magento\Framework\Exception\LocalizedException $e) { throw new \Magento\Framework\Exception\SessionException(new \Magento\Framework\Phrase('Area code not set: Area code must be set before starting a session.'), $e); } // Need to apply the config options so they can be ready by session_start $this->initIniOptions(); $this->registerSaveHandler(); // potential custom logic for session id (ex. switching between hosts) $this->setSessionId($this->sidResolver->getSid($this)); session_start(); $this->validator->validate($this); register_shutdown_function([$this, 'writeClose']); $this->_addHost(); \Magento\Framework\Profiler::stop('session_start'); } $this->storage->init(isset($_SESSION) ? $_SESSION : []); return $this; }
/** * Retrieve layout html directive * * @param string[] $construction * @return string */ public function layoutDirective($construction) { $this->_directiveParams = $this->_getParameters($construction[2]); if (!isset($this->_directiveParams['area'])) { $this->_directiveParams['area'] = 'frontend'; } if ($this->_directiveParams['area'] != $this->_appState->getAreaCode()) { return $this->_appState->emulateAreaCode($this->_directiveParams['area'], [$this, 'emulateAreaCallback']); } else { return $this->emulateAreaCallback(); } }
/** * Retrieve layout html directive * * @param string[] $construction * @return string */ public function layoutDirective($construction) { $this->_directiveParams = $this->getParameters($construction[2]); if (!isset($this->_directiveParams['area'])) { $this->_directiveParams['area'] = \Magento\Framework\App\Area::AREA_FRONTEND; } if ($this->_directiveParams['area'] != $this->_appState->getAreaCode()) { return $this->_appState->emulateAreaCode($this->_directiveParams['area'], [$this, 'emulateAreaCallback']); } else { return $this->emulateAreaCallback(); } }
/** * Retrieve package area * * @return string */ public function getArea() { return $this->_appState->getAreaCode(); }
/** * Get design area * * @return string */ public function getArea() { return $this->_getData('area') ? $this->_getData('area') : $this->_appState->getAreaCode(); }
/** * Retrieve renderer for area from config * * @param string $section * @param string $group * @param string $code * @return array */ public function getTotalsRenderer($section, $group, $code) { $path = implode('/', [$section, $group, $code, 'renderers', $this->_appState->getAreaCode()]); return $this->_dataContainer->get($path); }
/** * Return "disable checkout" error message based on the current area context * * @param $store * @return \Magento\Framework\Phrase * @throws \Magento\Framework\Exception\LocalizedException */ public function getErrorActionDisableCheckoutMessage($store) { if ($this->appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { return __($this->getErrorActionDisableCheckoutMessageBackend($store), $this->backendUrl->getUrl('admin/system_config/edit', ['section' => 'tax']), $this->backendUrl->getUrl('avatax/log')); } else { return __($this->getErrorActionDisableCheckoutMessageFrontend($store)); } }