/** * @covers \Magento\Core\Model\App\Emulation::startEnvironmentEmulation * @covers \Magento\Core\Model\App\Emulation::stopEnvironmentEmulation */ public function testEnvironmentEmulation() { $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Core\\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'); $initialEnvInfo = $this->_model->startEnvironmentEmulation(1); $initialDesign = $initialEnvInfo->getInitialDesign(); $this->assertEquals(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, $initialDesign['area']); $this->assertEquals(\Magento\Framework\App\Area::AREA_FRONTEND, $design->getDesignTheme()->getData('area')); $this->_model->stopEnvironmentEmulation($initialEnvInfo); $this->assertEquals(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, $design->getArea()); }
/** * Revert design settings to previous * * @return $this */ protected function _cancelDesignConfig() { if (!empty($this->_initialEnvironmentInfo)) { $this->_appEmulation->stopEnvironmentEmulation($this->_initialEnvironmentInfo); $this->_initialEnvironmentInfo = null; } return $this; }
/** * Render payment information block * * @param Info $info * @param int $storeId * @return string * @throws \Exception */ public function getInfoBlockHtml(Info $info, $storeId) { $initialEnvironmentInfo = $this->_appEmulation->startEnvironmentEmulation($storeId); try { // Retrieve specified view block from appropriate design package (depends on emulated store) $paymentBlock = $info->getBlockMock() ?: $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($initialEnvironmentInfo); throw $exception; } $this->_appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); return $paymentBlockHtml; }
/** * Send customer email * * @return bool */ public function send() { if (is_null($this->_website) || is_null($this->_customer)) { 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; } $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; } $initialEnvironmentInfo = $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, array($block, 'toHtml')); $this->_appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('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; }