/**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return null|int null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $omParams = $_SERVER;
     $omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
     $omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
     $this->objectManager = $this->objectManagerFactory->create($omParams);
     $area = FrontNameResolver::AREA_CODE;
     /** @var \Magento\Framework\App\State $appState */
     $appState = $this->objectManager->get('Magento\\Framework\\App\\State');
     $appState->setAreaCode($area);
     $configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
     $this->objectManager->configure($configLoader->load($area));
     $output->writeln('Import started');
     $time = microtime(true);
     /** @var \FireGento\FastSimpleImport\Model\Importer $importerModel */
     $importerModel = $this->objectManager->create('FireGento\\FastSimpleImport\\Model\\Importer');
     $productsArray = $this->getEntities();
     $importerModel->setBehavior($this->getBehavior());
     $importerModel->setEntityCode($this->getEntityCode());
     $adapterFactory = $this->objectManager->create('FireGento\\FastSimpleImport\\Model\\Adapters\\NestedArrayAdapterFactory');
     $importerModel->setImportAdapterFactory($adapterFactory);
     try {
         $importerModel->processImport($productsArray);
     } catch (\Exception $e) {
         $output->writeln($e->getMessage());
     }
     $output->write($importerModel->getLogTrace());
     $output->write($importerModel->getErrorMessages());
     $output->writeln('Import finished. Elapsed time: ' . round(microtime(true) - $time, 2) . 's' . "\n");
     $this->afterFinishImport();
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ordersCount = $input->getOption(self::INPUT_KEY_COUNT);
     $removeGeneratedItems = $input->getOption(self::INPUT_KEY_REMOVE);
     $messages = $this->validate($ordersCount, $removeGeneratedItems);
     if (!empty($messages)) {
         $output->writeln(implode(PHP_EOL, $messages));
         return;
     }
     $omParams = $_SERVER;
     $omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
     $omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
     $objectManager = $this->objectManagerFactory->create($omParams);
     $params[self::INPUT_KEY_COUNT] = $ordersCount;
     $params[self::INPUT_KEY_REMOVE] = $removeGeneratedItems;
     $adminAppState = $objectManager->get('Magento\\Framework\\App\\State');
     $adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN);
     $this->context->setParameters($params);
     $this->context->setObjectManager($objectManager);
     $productsCreator = $objectManager->create('Atwix\\Samplegen\\Helper\\OrdersCreator', ['context' => $this->context]);
     try {
         $productsCreator->launch();
         $output->writeln('<info>' . 'All operations completed successfully' . '</info>');
     } catch (\Exception $e) {
         $output->writeln('<error>' . "{$e->getMessage()}" . '</error>');
     }
 }
Example #3
0
 /**
  * Constructor
  *
  * @param ObjectManagerFactory $objectManagerFactory
  */
 public function __construct(ObjectManagerFactory $objectManagerFactory)
 {
     $params = $_SERVER;
     $params[StoreManager::PARAM_RUN_CODE] = 'admin';
     $params[StoreManager::PARAM_RUN_TYPE] = 'store';
     $this->objectManager = $objectManagerFactory->create($params);
     parent::__construct();
 }
 /**
  * Constructor
  *
  * @param ObjectManagerFactory $objectManagerFactory
  * @param SampleData $sampleData
  */
 public function __construct(ObjectManagerFactory $objectManagerFactory, SampleData $sampleData)
 {
     $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
     $params[State::PARAM_MODE] = State::MODE_DEVELOPER;
     $this->objectManager = $objectManagerFactory->create($params);
     $this->sampleData = $sampleData;
     parent::__construct();
 }
Example #5
0
 /**
  * Constructor
  *
  * @param ObjectManagerFactory $objectManagerFactory
  */
 public function __construct(ObjectManagerFactory $objectManagerFactory)
 {
     $params = $_SERVER;
     $params[StoreManager::PARAM_RUN_CODE] = 'admin';
     $params[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
     $this->objectManager = $objectManagerFactory->create($params);
     parent::__construct();
 }
 private function getConfigResource(ObjectManagerFactory $objectManagerFactory)
 {
     try {
         $params = $_SERVER;
         $params[StoreManager::PARAM_RUN_CODE] = 'admin';
         $params[StoreManager::PARAM_RUN_TYPE] = 'store';
         $objectManager = $objectManagerFactory->create($params);
         return $objectManager->get('Shockwavemk\\Staging\\Console\\Model\\Resource\\Config');
     } catch (\Exception $e) {
         return null;
     }
 }
 protected function setUp()
 {
     $this->objectManagerFactory = $this->getMock('Magento\\Framework\\App\\ObjectManagerFactory', [], [], '', false);
     $this->objectManager = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface');
     $this->objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager);
     $this->stateMock = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false);
     $this->configLoaderMock = $this->getMock('Magento\\Framework\\App\\ObjectManager\\ConfigLoader', [], [], '', false);
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap($this->getObjectManagerReturnValueMap()));
     $this->collectionFactory = $this->getMockBuilder('Magento\\Indexer\\Model\\Indexer\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->indexerFactory = $this->getMockBuilder('Magento\\Indexer\\Model\\IndexerFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->objectManager->expects($this->any())->method('create')->will($this->returnValueMap([['Magento\\Indexer\\Model\\Indexer\\CollectionFactory', [], $this->collectionFactory], ['Magento\\Indexer\\Model\\IndexerFactory', [], $this->indexerFactory]]));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>' . 'Started.' . '</info>');
     $omParams = $_SERVER;
     $omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
     $omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
     $objectManager = $this->objectManagerFactory->create($omParams);
     /** @var \JZahedieh\FileConfigurator\Loader\YamlLoader $yamlLoader */
     $yamlLoader = $objectManager->create('JZahedieh\\FileConfigurator\\Loader\\YamlLoader');
     $yamlLoader->process();
     $output->writeln('<info>' . 'Finished.' . '</info>');
 }
 /**
  * Gets initialized object manager
  *
  * @return ObjectManagerInterface
  */
 protected function getObjectManager()
 {
     if (null == $this->objectManager) {
         $area = FrontNameResolver::AREA_CODE;
         $this->objectManager = $this->objectManagerFactory->create($_SERVER);
         /** @var \Magento\Framework\App\State $appState */
         $appState = $this->objectManager->get('Magento\\Framework\\App\\State');
         $appState->setAreaCode($area);
         $configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
         $this->objectManager->configure($configLoader->load($area));
     }
     return $this->objectManager;
 }
 protected function setUp()
 {
     $this->objectManagerFactory = $this->getMock('Magento\\Framework\\App\\ObjectManagerFactory', [], [], '', false);
     $this->objectManager = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface');
     //TODO: temporary fix unit
     $stateMock = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false);
     $stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml')->willReturnSelf();
     $this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\App\\State')->willReturn($stateMock);
     $this->objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager);
     $this->collectionFactory = $this->getMockBuilder('Magento\\Indexer\\Model\\Indexer\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->indexerFactory = $this->getMockBuilder('Magento\\Indexer\\Model\\IndexerFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->objectManager->expects($this->exactly(2))->method('create')->will($this->returnValueMap([['Magento\\Indexer\\Model\\Indexer\\CollectionFactory', [], $this->collectionFactory], ['Magento\\Indexer\\Model\\IndexerFactory', [], $this->indexerFactory]]));
     $this->objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager);
 }
Example #11
0
 /**
  * Constructor
  * @param ObjectManagerFactory $objectManagerFactory
  */
 public function __construct(ObjectManagerFactory $objectManagerFactory)
 {
     $params = $_SERVER;
     $params[StoreManager::PARAM_RUN_CODE] = 'admin';
     $params[StoreManager::PARAM_RUN_TYPE] = 'store';
     $objectManager = $objectManagerFactory->create($params);
     /** @var \Magento\Framework\App\State $appState */
     $appState = $objectManager->get('Magento\\Framework\\App\\State');
     $appState->setAreaCode('adminmhtml');
     //TODO: temporary fix.
     $this->collectionFactory = $objectManager->create('Magento\\Indexer\\Model\\Indexer\\CollectionFactory');
     $this->indexerFactory = $objectManager->create('Magento\\Indexer\\Model\\IndexerFactory');
     parent::__construct();
 }
 /**
  * Retrieve checkout session
  *
  * @return \Magento\Checkout\Model\Session
  */
 public function getCheckoutSession()
 {
     /* $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
     		return $objectManager->get('Magento\Checkout\Model\Session'); */
     $objectManager = $this->_objectManagerFactory->create([]);
     return $objectManager->get('Magento\\Checkout\\Model\\Session');
 }
Example #13
0
 /**
  * Load primary config
  *
  * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
  * @param DriverPool $driverPool
  * @param mixed $argumentMapper
  * @param string $appMode
  * @return array
  */
 protected function _loadPrimaryConfig(DirectoryList $directoryList, $driverPool, $argumentMapper, $appMode)
 {
     if (null === $this->_primaryConfigData) {
         $this->_primaryConfigData = array_replace(parent::_loadPrimaryConfig($directoryList, $driverPool, $argumentMapper, $appMode), ['default_setup' => ['type' => 'Magento\\TestFramework\\Db\\ConnectionAdapter']]);
         $this->_primaryConfigData['preferences'] = array_replace($this->_primaryConfigData['preferences'], ['Magento\\Framework\\Stdlib\\CookieManagerInterface' => 'Magento\\TestFramework\\CookieManager', 'Magento\\Framework\\ObjectManager\\DynamicConfigInterface' => '\\Magento\\TestFramework\\ObjectManager\\Configurator', 'Magento\\Framework\\App\\RequestInterface' => 'Magento\\TestFramework\\Request', 'Magento\\Framework\\App\\Request\\Http' => 'Magento\\TestFramework\\Request', 'Magento\\Framework\\App\\ResponseInterface' => 'Magento\\TestFramework\\Response', 'Magento\\Framework\\App\\Response\\Http' => 'Magento\\TestFramework\\Response', 'Magento\\Framework\\Interception\\PluginListInterface' => 'Magento\\TestFramework\\Interception\\PluginList', 'Magento\\Framework\\Interception\\ObjectManager\\Config' => 'Magento\\TestFramework\\ObjectManager\\Config', 'Magento\\Framework\\View\\LayoutInterface' => 'Magento\\TestFramework\\View\\Layout', 'Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface' => 'Magento\\TestFramework\\Db\\ConnectionAdapter']);
     }
     return $this->_primaryConfigData;
 }
Example #14
0
 /**
  * Emulate application area and various services that are necessary for populating files
  *
  * @param string $areaCode
  * @return void
  */
 private function emulateApplicationArea($areaCode)
 {
     $this->objectManager = $this->omFactory->create([\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_DEFAULT]);
     /** @var \Magento\Framework\App\State $appState */
     $appState = $this->objectManager->get('Magento\\Framework\\App\\State');
     $appState->setAreaCode($areaCode);
     $this->assetRepo = $this->objectManager->get('Magento\\Framework\\View\\Asset\\Repository');
     $this->assetPublisher = $this->objectManager->create('Magento\\Framework\\App\\View\\Asset\\Publisher');
     $this->htmlMinifier = $this->objectManager->get('Magento\\Framework\\View\\Template\\Html\\MinifierInterface');
     $this->bundleManager = $this->objectManager->get('Magento\\Framework\\View\\Asset\\Bundle\\Manager');
 }
Example #15
0
 /**
  * Emulate application area and various services that are necessary for populating files
  *
  * @param string $areaCode
  * @return void
  */
 private function emulateApplicationArea($areaCode)
 {
     $this->objectManager = $this->omFactory->create([\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_PRODUCTION]);
     /** @var \Magento\Framework\App\State $appState */
     $appState = $this->objectManager->get(\Magento\Framework\App\State::class);
     $appState->setAreaCode($areaCode);
     $this->assetRepo = $this->objectManager->get(\Magento\Framework\View\Asset\Repository::class);
     $this->assetPublisher = $this->objectManager->create(\Magento\Framework\App\View\Asset\Publisher::class);
     $this->htmlMinifier = $this->objectManager->get(\Magento\Framework\View\Template\Html\MinifierInterface::class);
     $this->bundleManager = $this->objectManager->get(\Magento\Framework\View\Asset\Bundle\Manager::class);
 }
Example #16
0
 /**
  * Emulate application area and various services that are necessary for populating files
  *
  * @param string $areaCode
  * @return void
  */
 private function emulateApplicationArea($areaCode)
 {
     $objectManager = $this->omFactory->create([\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_DEFAULT]);
     /** @var \Magento\Framework\App\State $appState */
     $appState = $objectManager->get('Magento\\Framework\\App\\State');
     $appState->setAreaCode($areaCode);
     /** @var \Magento\Framework\App\ObjectManager\ConfigLoader $configLoader */
     $configLoader = $objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigLoader');
     $objectManager->configure($configLoader->load($areaCode));
     $this->assetRepo = $objectManager->get('Magento\\Framework\\View\\Asset\\Repository');
     $this->assetPublisher = $objectManager->get('Magento\\Framework\\App\\View\\Asset\\Publisher');
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $omParams = $_SERVER;
     $omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
     $omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
     $objectManager = $this->objectManagerFactory->create($omParams);
     $params[self::INPUT_KEY_GROUP] = $input->getOption(self::INPUT_KEY_GROUP);
     $params[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED] = '0';
     $bootstrap = $input->getOption(Cli::INPUT_KEY_BOOTSTRAP);
     if ($bootstrap) {
         $bootstrapProcessor = new ComplexParameter(Cli::INPUT_KEY_BOOTSTRAP);
         $bootstrapOptionValues = $bootstrapProcessor->getFromString('--' . Cli::INPUT_KEY_BOOTSTRAP . '=' . $bootstrap);
         $bootstrapOptionValue = $bootstrapOptionValues[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED];
         if ($bootstrapOptionValue) {
             $params[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED] = $bootstrapOptionValue;
         }
     }
     /** @var \Magento\Framework\App\Cron $cronObserver */
     $cronObserver = $objectManager->create('Magento\\Framework\\App\\Cron', ['parameters' => $params]);
     $cronObserver->launch();
     $output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
 }
 /**
  * Load primary config
  *
  * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
  * @param DriverPool $driverPool
  * @param mixed $argumentMapper
  * @param string $appMode
  * @return array
  */
 protected function _loadPrimaryConfig(DirectoryList $directoryList, $driverPool, $argumentMapper, $appMode)
 {
     if (null === $this->_primaryConfigData) {
         $this->_primaryConfigData = array_replace(parent::_loadPrimaryConfig($directoryList, $driverPool, $argumentMapper, $appMode), ['default_setup' => ['type' => 'Magento\\TestFramework\\Db\\ConnectionAdapter']]);
         $diPreferences = [];
         $diPreferencesPath = __DIR__ . '/../../../etc/di/preferences/';
         $preferenceFiles = glob($diPreferencesPath . '*.php');
         foreach ($preferenceFiles as $file) {
             if (!is_readable($file)) {
                 throw new LocalizedException(__("'%1' is not readable file.", $file));
             }
             $diPreferences = array_replace($diPreferences, include $file);
         }
         $this->_primaryConfigData['preferences'] = array_replace($this->_primaryConfigData['preferences'], $diPreferences);
     }
     return $this->_primaryConfigData;
 }
Example #19
0
 /**
  * Initializes object manager
  *
  * @return void
  */
 private function initObjectManager()
 {
     if (!$this->objectManager) {
         $this->objectManager = $this->factory->create($this->server);
         $this->maintenance = $this->objectManager->get('Magento\\Framework\\App\\MaintenanceMode');
     }
 }
Example #20
0
 protected function constructObjectManager()
 {
     global $autoloader;
     $magentoAutoloader = new Autoload\ClassLoaderWrapper($autoloader);
     Autoload\AutoloaderRegistry::registerAutoloader($magentoAutoloader);
     /* Overwrite all directories that are used by our module. A correct
        config path is required for a working object manager. */
     $dirList = new DirectoryList($this->useRoot ? BP : $this->getVfs(), [DirectoryList::CONFIG => ["path" => BP . "/app/etc"], DirectoryList::MEDIA => ["path" => $this->getVfs() . "/media"], DirectoryList::VAR_DIR => ["path" => $this->getVfs() . "/var"], DirectoryList::CACHE => ["path" => BP . "/cache"]]);
     Autoload\Populator::populateMappings($magentoAutoloader, $dirList, new ComponentRegistrar());
     $factory = new ObjectManagerFactory($dirList, new DriverPool(), new ConfigFilePool());
     $config = [State::PARAM_MODE => State::MODE_DEVELOPER, "MAGE_CONFIG" => ["db" => ["connection" => ["default" => ["host" => "127.0.0.1", "dbname" => "magento2_test", "username" => "root", "password" => ""]]], "resource" => ["default_setup" => ["connection" => "default"]], "modules" => ["Magento_Authorization" => 1, "Magento_Backend" => 1, "Magento_Config" => 1, "Magento_Developer" => 1, "Magento_Email" => 1, "Magento_MediaStorage" => 1, "Magento_Store" => 1, "Magento_Theme" => 1, "Magento_Translation" => 1, "Magento_Ui" => 1, "Tinify_CompressImages" => 1]]];
     $objectManager = $factory->create($config);
     return $objectManager;
 }
Example #21
0
 /**
  * Initializes the essential objects
  *
  * @return void
  */
 private function init()
 {
     if (!$this->objectManager) {
         $this->objectManager = $this->factory->create($this->rootDir, $this->server);
         $this->dirList = $this->objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList');
         $this->maintenance = $this->objectManager->get('Magento\\Framework\\App\\MaintenanceMode');
         /** @var $fileSystem \Magento\Framework\App\Filesystem */
         $fileSystem = $this->objectManager->get('Magento\\Framework\\App\\Filesystem');
         $this->configDir = $fileSystem->getDirectoryRead(Filesystem::CONFIG_DIR);
     }
 }
 /**
  * Load primary config
  *
  * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
  * @param mixed $argumentMapper
  * @param string $appMode
  * @return array
  */
 protected function _loadPrimaryConfig(\Magento\Framework\App\Filesystem\DirectoryList $directoryList, $argumentMapper, $appMode)
 {
     if (null === $this->_primaryConfigData) {
         $this->_primaryConfigData = array_replace(parent::_loadPrimaryConfig($directoryList, $argumentMapper, $appMode), array('default_setup' => array('type' => 'Magento\\TestFramework\\Db\\ConnectionAdapter')));
         $this->_primaryConfigData['preferences'] = array_replace($this->_primaryConfigData['preferences'], ['Magento\\Framework\\Stdlib\\Cookie' => 'Magento\\TestFramework\\Cookie', 'Magento\\Framework\\App\\RequestInterface' => 'Magento\\TestFramework\\Request', 'Magento\\Framework\\App\\Request\\Http' => 'Magento\\TestFramework\\Request', 'Magento\\Framework\\App\\ResponseInterface' => 'Magento\\TestFramework\\Response', 'Magento\\Framework\\App\\Response\\Http' => 'Magento\\TestFramework\\Response', 'Magento\\Framework\\Interception\\PluginList' => 'Magento\\TestFramework\\Interception\\PluginList', 'Magento\\Framework\\Interception\\ObjectManager\\Config' => 'Magento\\TestFramework\\ObjectManager\\Config', 'Magento\\Framework\\View\\LayoutInterface' => 'Magento\\TestFramework\\View\\Layout']);
     }
     return $this->_primaryConfigData;
 }