示例#1
1
文件: Store.php 项目: aiesh/magento2
 /**
  * Read configuration by code
  *
  * @param string $code
  * @return array
  */
 public function read($code = null)
 {
     if ($this->_appState->isInstalled()) {
         if (empty($code)) {
             $store = $this->_storeManager->getStore();
         } elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) {
             $store = $this->_storeManager->getDefaultStoreView();
         } else {
             $store = $this->_storeFactory->create();
             $store->load($code);
         }
         if (!$store->getCode()) {
             throw NoSuchEntityException::singleField('storeCode', $code);
         }
         $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource();
         $config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
         $collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId()));
         $dbStoreConfig = array();
         foreach ($collection as $item) {
             $dbStoreConfig[$item->getPath()] = $item->getValue();
         }
         $config = $this->_converter->convert($dbStoreConfig, $config);
     } else {
         $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource();
         $config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
     }
     return $config;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->setDecorated(true);
     $this->appState->setAreaCode('catalog');
     $connection = $this->attributeResource->getConnection();
     $attributeTables = $this->getAttributeTables();
     $progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables));
     $progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%');
     $this->attributeResource->beginTransaction();
     try {
         // Find and remove unused attributes
         foreach ($attributeTables as $attributeTable) {
             $progress->setMessage($attributeTable . ' ');
             $affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable);
             if (count($affectedIds) > 0) {
                 $connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]);
             }
             $progress->advance();
         }
         $this->attributeResource->commit();
         $output->writeln("");
         $output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
         $output->writeln("<comment>  " . implode("\n  ", $attributeTables) . "</comment>");
     } catch (\Exception $exception) {
         $this->attributeResource->rollBack();
         $output->writeln("");
         $output->writeln("<error>{$exception->getMessage()}</error>");
     }
 }
 /**
  * @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;
 }
示例#4
0
 /**
  * Get config value by key
  *
  * @param null|string $path
  * @param null|mixed $default
  * @return null|mixed
  */
 public function get($path = null, $default = null)
 {
     if (!$this->_appState->isInstalled() && !in_array($this->_configScope->getCurrentScope(), array('global', 'install'))) {
         return $default;
     }
     return parent::get($path, $default);
 }
示例#5
0
 public function testProcess()
 {
     $sourceFilePath = realpath(__DIR__ . '/_files/oyejorge.less');
     $expectedCss = $this->state->getMode() === State::MODE_DEVELOPER ? file_get_contents(__DIR__ . '/_files/oyejorge_dev.css') : file_get_contents(__DIR__ . '/_files/oyejorge.css');
     $actualCss = $this->model->process($sourceFilePath);
     $this->assertEquals($this->cutCopyrights($expectedCss), $actualCss);
 }
示例#6
0
 /**
  * Check whether asset minification is on for specified content type
  *
  * @param string $contentType
  * @return bool
  */
 public function isEnabled($contentType)
 {
     if (!isset($this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType])) {
         $this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType] = $this->appState->getMode() != State::MODE_DEVELOPER && (bool) $this->scopeConfig->isSetFlag(sprintf(self::XML_PATH_MINIFICATION_ENABLED, $contentType), $this->scope);
     }
     return $this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType];
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         return;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         return;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
 public function testNotUnlockProcessInProductionMode()
 {
     $this->stateMock->expects(self::exactly(2))->method('getMode')->willReturn(State::MODE_PRODUCTION);
     $this->filesystemMock->expects(self::never())->method('getDirectoryWrite');
     $this->lockerProcess->lockProcess(self::LOCK_NAME);
     $this->lockerProcess->unlockProcess();
 }
示例#9
0
 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     $parser = new \Less_Parser($options);
     $parser->parseFile($sourceFilePath, '');
     return $parser->getCss();
 }
示例#10
0
 /**
  * Retrieve deployment version of static files
  *
  * @return string
  */
 public function getValue()
 {
     if (!$this->cachedValue) {
         $this->cachedValue = $this->readValue($this->appState->getMode());
     }
     return $this->cachedValue;
 }
示例#11
0
 /**
  * Perform required checks before cron run
  *
  * @param \Magento\Framework\App\Cron $subject
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @throws \Magento\Framework\Exception
  */
 public function beforeLaunch(\Magento\Framework\App\Cron $subject)
 {
     $this->_sidResolver->setUseSessionInUrl(false);
     if (false == $this->_appState->isInstalled()) {
         throw new \Magento\Framework\Exception('Application is not installed yet, please complete the installation first.');
     }
 }
 /**
  * @return void
  */
 public function testWidgetDirective()
 {
     $result = 'some text';
     $construction = ['{{widget type="Widget\\Link" anchor_text="Test" template="block.phtml" id_path="p/1"}}', 'widget', ' type="" anchor_text="Test" template="block.phtml" id_path="p/1"'];
     $this->appStateMock->expects($this->once())->method('emulateAreaCode')->with('frontend', [$this->filterEmulate, 'generateWidget'], [$construction])->willReturn($result);
     $this->assertSame($result, $this->filterEmulate->widgetDirective($construction));
 }
示例#13
0
 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
示例#14
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $this->_state->setAreaCode('crontab');
     $this->_eventManager->dispatch('default');
     $this->_response->setCode(0);
     return $this->_response;
 }
示例#15
0
 /**
  * Make sure the aggregated configuration is materialized
  *
  * By default write the file if it doesn't exist, but in developer mode always do it.
  *
  * @param string $relPath
  * @return void
  */
 private function ensureSourceFile($relPath)
 {
     $dir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER || !$dir->isExist($relPath)) {
         $dir->writeFile($relPath, $this->config->getConfig());
     }
 }
示例#16
0
 /**
  * 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);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
 /**
  * @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;
 }
 protected function configureAdminArea()
 {
     $config = ['test config'];
     $this->configLoaderMock->expects($this->once())->method('load')->with(FrontNameResolver::AREA_CODE)->will($this->returnValue($config));
     $this->objectManager->expects($this->once())->method('configure')->with($config);
     $this->stateMock->expects($this->once())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
 }
 /**
  * @dataProvider dataProvider
  */
 public function testAroundDispatchDisabled($state)
 {
     $this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null));
     $this->versionMock->expects($this->never())->method('process');
     $this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state));
     $this->responseMock->expects($this->never())->method('setHeader');
     $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock);
 }
示例#21
0
 protected function setUp()
 {
     $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getBasePath', 'isSecure', 'getHttpHost'], [], '', false, false);
     $this->requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/'));
     $this->requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host'));
     $this->appState = $this->getMock('\\Magento\\Framework\\App\\State', ['isInstalled'], [], '', false, false);
     $this->appState->expects($this->atLeastOnce())->method('isInstalled')->will($this->returnValue(true));
 }
示例#22
0
 public function testBeforeExecuteWithProductionMode()
 {
     $this->appState->expects($this->once())->method('getMode')->willReturn('production');
     $this->themeRegistration->expects($this->never())->method('register');
     $this->logger->expects($this->never())->method('critical');
     $object = new Registration($this->themeRegistration, $this->logger, $this->appState);
     $object->beforeExecute($this->abstractAction, $this->request);
 }
示例#23
0
 /**
  * @param State\OptionsInterface $options
  * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
  * @param \Magento\Framework\App\State $appState
  * @param bool $banAll Whether all cache types are forced to be disabled
  */
 public function __construct(State\OptionsInterface $options, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, \Magento\Framework\App\State $appState, $banAll = false)
 {
     $this->_options = $options;
     $this->_cacheFrontend = $cacheFrontendPool->get(\Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID);
     if ($appState->isInstalled()) {
         $this->_loadTypeStatuses($banAll);
     }
 }
示例#24
0
 /**
  * Perform url rewites
  *
  * @param \Magento\Framework\App\FrontController $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_state->isInstalled()) {
         return $proceed($request);
     }
     $this->_rewriteService->applyRewrites($request);
     return $proceed($request);
 }
示例#25
0
 public function testPublish()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
     $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
     $this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
     $this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true));
     $this->assertTrue($this->object->publish($this->getAsset()));
 }
示例#26
0
 public function testCreateRequireJsAssetDevMode()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     $this->dir->expects($this->never())->method('isExist');
     $data = 'requirejs config data';
     $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
     $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
     $this->assertSame($this->asset, $this->object->createRequireJsAsset());
 }
 /**
  * @param \Magento\Framework\Event\ObserverInterface $object
  * @param Observer $observer
  * @return $this
  * @throws \LogicException
  */
 protected function _callObserverMethod($object, $observer)
 {
     if ($object instanceof \Magento\Framework\Event\ObserverInterface) {
         $object->execute($observer);
     } elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
         throw new \LogicException(sprintf('Observer "%s" must implement interface "%s"', get_class($object), 'Magento\\Framework\\Event\\ObserverInterface'));
     }
     return $this;
 }
 /**
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $loggerExpects
  * @param string $stateMode
  * @return void
  * @dataProvider reorderChildElementLogDataProvider
  */
 public function testReorderChildElementLog($loggerExpects, $stateMode)
 {
     $parentName = 'parent';
     $childName = 'child';
     $offsetOrSibling = '-';
     $this->stateMock->expects($this->once())->method('getMode')->willReturn($stateMode);
     $this->loggerMock->expects($loggerExpects)->method('critical')->with("Broken reference: the '{$childName}' tries to reorder itself towards '', but " . "their parents are different: '{$parentName}' and '' respectively.");
     $this->dataStructure->reorderChildElement($parentName, $childName, $offsetOrSibling);
 }
 public function testLoad()
 {
     $area = $this->getMock('Magento\\Framework\\App\\Area', [], [], '', false);
     $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('area'));
     $this->_areaListMock->expects($this->once())->method('getArea')->with('area')->will($this->returnValue($area));
     $area->expects($this->at(0))->method('load')->with(\Magento\Framework\App\Area::PART_DESIGN)->will($this->returnValue($area));
     $area->expects($this->at(1))->method('load')->with(\Magento\Framework\App\Area::PART_TRANSLATE)->will($this->returnValue($area));
     $this->_model->load($this->_requestMock);
 }
示例#30
0
 /**
  * Performs non-existent observer method calls protection
  *
  * @param object $object
  * @param string $method
  * @param Observer $observer
  * @return $this
  * @throws \LogicException
  */
 protected function _callObserverMethod($object, $method, $observer)
 {
     if (method_exists($object, $method) && is_callable([$object, $method])) {
         $object->{$method}($observer);
     } elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
         throw new \LogicException('Method "' . $method . '" is not defined in "' . get_class($object) . '"');
     }
     return $this;
 }