/** * @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>'); } }
/** * {@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; }
/** * 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'); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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'); }
/** * 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); }
/** * 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'); }
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; } }
/** * {@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>'); }
/** * 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(); }
/** * 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'); } }
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; }
/** * 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); } }