示例#1
0
 /**
  * @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());
 }
示例#2
0
 public function testStartDefaults()
 {
     // Test data
     $inlineTranslate = false;
     $initArea = 'initial area';
     $initTheme = 'initial design theme';
     $initStore = 1;
     $initLocale = 'initial locale code';
     $newInlineTranslate = false;
     $newLocale = 'new locale code';
     $newArea = \Magento\Framework\App\Area::AREA_FRONTEND;
     // Stubs
     $this->inlineTranslationMock->expects($this->any())->method('isEnabled')->willReturn($inlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('getArea')->willReturn($initArea);
     $this->viewDesignMock->expects($this->any())->method('getDesignTheme')->willReturn($initTheme);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getStoreId')->willReturn($initStore);
     $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($initLocale);
     $this->inlineConfigMock->expects($this->any())->method('isActive')->willReturn($newInlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('getConfigurationDesignTheme')->willReturn($initTheme);
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($newLocale);
     // Expectations
     $this->storeMock->expects($this->any())->method('getStoreId')->willReturn($initStore);
     $this->inlineTranslationMock->expects($this->any())->method('suspend')->with($newInlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('setDesignTheme')->with($initTheme);
     $this->localeResolverMock->expects($this->any())->method('setLocale')->with($newLocale);
     $this->translateMock->expects($this->any())->method('setLocale')->with($newLocale);
     $this->translateMock->expects($this->any())->method('loadData')->with($newArea);
     $this->storeManagerMock->expects($this->any())->method('setCurrentStore')->with(self::NEW_STORE_ID);
     // Test
     $this->model->startEnvironmentEmulation(self::NEW_STORE_ID, \Magento\Framework\App\Area::AREA_FRONTEND);
 }
 /**
  * Applying of design config
  *
  * @return $this
  */
 protected function _applyDesignConfig()
 {
     $designConfig = $this->getDesignConfig();
     $store = $designConfig->getStore();
     $storeId = is_object($store) ? $store->getId() : $store;
     $area = $designConfig->getArea();
     if ($storeId !== null) {
         $this->_appEmulation->startEnvironmentEmulation($storeId, $area);
     }
     return $this;
 }
示例#4
0
文件: Email.php 项目: nja78/magento2
 /**
  * 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;
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 /**
  * Apply design config so that emails are processed within the context of the appropriate area/store/theme.
  * Can be called multiple times without issue.
  *
  * @return bool
  */
 protected function applyDesignConfig()
 {
     // Only run app emulation if this is the parent template and emulation isn't already running.
     // Otherwise child will run inside parent emulation.
     if ($this->isChildTemplate() || $this->hasDesignBeenApplied) {
         return false;
     }
     $this->hasDesignBeenApplied = true;
     $designConfig = $this->getDesignConfig();
     $storeId = $designConfig->getStore();
     $area = $designConfig->getArea();
     if ($storeId !== null) {
         // Force emulation in case email is being sent from same store so that theme will be loaded. Helpful
         // for situations where emails may be sent from bootstrap files that load frontend store, but not theme
         $this->appEmulation->startEnvironmentEmulation($storeId, $area, true);
     }
     return true;
 }