/** * @covers \Magento\Store\Model\App\Emulation::startEnvironmentEmulation * @covers \Magento\Store\Model\App\Emulation::stopEnvironmentEmulation */ public function testEnvironmentEmulation() { $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Store\\Model\\App\\Emulation'); \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE); $design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface'); $this->_model->startEnvironmentEmulation(1); $this->_model->stopEnvironmentEmulation(); $this->assertEquals(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, $design->getArea()); }
public function testStop() { // Test data $initArea = 'initial area'; $initTheme = 'initial design theme'; $initLocale = 'initial locale code'; $initialStore = 1; $initTranslateInline = false; $this->inlineTranslationMock->expects($this->once())->method('isEnabled')->willReturn($initTranslateInline); $this->viewDesignMock->expects($this->once())->method('getArea')->willReturn($initArea); $this->viewDesignMock->expects($this->once())->method('getDesignTheme')->willReturn($initTheme); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn($initLocale); $this->model->storeCurrentEnvironmentInfo(); // Expectations $this->inlineTranslationMock->expects($this->once())->method('resume')->with($initTranslateInline); $this->viewDesignMock->expects($this->once())->method('setDesignTheme')->with($initTheme, $initArea); $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with($initialStore); $this->localeResolverMock->expects($this->once())->method('setLocale')->with($initLocale); $this->translateMock->expects($this->once())->method('setLocale')->with($initLocale); $this->translateMock->expects($this->once())->method('loadData')->with($initArea); // Test $this->model->stopEnvironmentEmulation(); }
/** * Send customer email * * @return bool * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function send() { if ($this->_website === null || $this->_customer === null) { return false; } if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) { return false; } if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) { return false; } if ($this->_customer->getStoreId() > 0) { $store = $this->_storeManager->getStore($this->_customer->getStoreId()); } else { $store = $this->_website->getDefaultStore(); } $storeId = $store->getId(); if ($this->_type == 'price' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) { return false; } elseif ($this->_type == 'stock' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) { return false; } if ($this->_type != 'price' && $this->_type != 'stock') { return false; } $this->_appEmulation->startEnvironmentEmulation($storeId); if ($this->_type == 'price') { $this->_getPriceBlock()->setStore($store)->reset(); foreach ($this->_priceProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getPriceBlock()->addProduct($product); } $block = $this->_getPriceBlock(); $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); } else { $this->_getStockBlock()->setStore($store)->reset(); foreach ($this->_stockProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getStockBlock()->addProduct($product); } $block = $this->_getStockBlock(); $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); } $alertGrid = $this->_appState->emulateAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND, [$block, 'toHtml']); $this->_appEmulation->stopEnvironmentEmulation(); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars(['customerName' => $this->_customerHelper->getCustomerName($this->_customer), 'alertGrid' => $alertGrid])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->_customer->getEmail(), $this->_customerHelper->getCustomerName($this->_customer))->getTransport(); $transport->sendMessage(); return true; }
/** * Render payment information block * * @param InfoInterface $info * @param int $storeId * @return string * @throws \Exception */ public function getInfoBlockHtml(InfoInterface $info, $storeId) { $this->_appEmulation->startEnvironmentEmulation($storeId); try { // Retrieve specified view block from appropriate design package (depends on emulated store) $paymentBlock = $this->getInfoBlock($info); $paymentBlock->setArea(\Magento\Framework\App\Area::AREA_FRONTEND)->setIsSecureMode(true); $paymentBlock->getMethod()->setStore($storeId); $paymentBlockHtml = $paymentBlock->toHtml(); } catch (\Exception $exception) { $this->_appEmulation->stopEnvironmentEmulation(); throw $exception; } $this->_appEmulation->stopEnvironmentEmulation(); return $paymentBlockHtml; }
/** * Revert design settings to previous * * @return $this */ protected function cancelDesignConfig() { $this->appEmulation->stopEnvironmentEmulation(); $this->hasDesignBeenApplied = false; return $this; }
/** * Revert design settings to previous * * @return $this */ protected function _cancelDesignConfig() { $this->_appEmulation->stopEnvironmentEmulation(); return $this; }