/** * @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(); }
/** * Creates operation * * @param string $operationAlias * @param mixed $arguments * @return OperationInterface * @throws OperationException */ public function create($operationAlias, $arguments = null) { if (!array_key_exists($operationAlias, $this->operationsDefinitions)) { throw new OperationException(sprintf('Unrecognized operation "%s"', $operationAlias), OperationException::UNAVAILABLE_OPERATION); } return $this->objectManager->create($this->operationsDefinitions[$operationAlias], ['data' => $arguments]); }
/** * Get proxied instance * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = true === $this->_isShared ? $this->_objectManager->get($this->_instanceName) : $this->_objectManager->create($this->_instanceName); } return $this->_subject; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { try { /** @var \Magento\Deploy\Model\Mode $modeController */ $modeController = $this->objectManager->create('Magento\\Deploy\\Model\\Mode', ['input' => $input, 'output' => $output]); $toMode = $input->getArgument(self::MODE_ARGUMENT); $skipCompilation = $input->getOption(self::SKIP_COMPILATION_OPTION); switch ($toMode) { case State::MODE_DEVELOPER: $modeController->enableDeveloperMode(); break; case State::MODE_PRODUCTION: if ($skipCompilation) { $modeController->enableProductionModeMinimal(); } else { $modeController->enableProductionMode(); } break; default: throw new LocalizedException(__('Cannot switch into given mode "%1"', $toMode)); } $output->writeln('Enabled ' . $toMode . ' mode.'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } return; } }
/** * Set up */ public function setUp() { $this->objectManager = Bootstrap::getObjectManager(); $this->accountManagement = $this->objectManager->create('Magento\\Customer\\Api\\AccountManagementInterface'); $this->securityManager = $this->objectManager->create('Magento\\Security\\Model\\SecurityManager'); $this->passwordResetRequestEvent = $this->objectManager->get('Magento\\Security\\Model\\PasswordResetRequestEvent'); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->groupRepository = $this->objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface'); $this->groupFactory = $this->objectManager->create('Magento\\Customer\\Api\\Data\\GroupInterfaceFactory'); $this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder'); }
public function testInitForm() { $this->setupExistingCustomerData(); $block = $this->_objectManager->create('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Addresses'); /** @var Addresses $block */ $block = $block->initForm(); /** @var \Magento\Framework\Data\Form $form */ $form = $block->getForm(); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Fieldset', $form->getElement('address_fieldset')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('prefix')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('firstname')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('middlename')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('lastname')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('suffix')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('company')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Multiline', $form->getElement('street')); $this->assertEquals(2, $form->getElement('street')->getLineCount()); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('city')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Select', $form->getElement('country_id')); $this->assertEquals('US', $form->getElement('country_id')->getValue()); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('region')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Hidden', $form->getElement('region_id')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('postcode')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('telephone')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('fax')); $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('vat_id')); }
/** * Get current Catalog Layer * * @return \Magento\Catalog\Model\Layer */ public function get() { if (!isset($this->layer)) { $this->layer = $this->objectManager->create($this->layersPool[self::CATALOG_LAYER_CATEGORY]); } return $this->layer; }
/** * Create new calculator * * @param string $type Type of calculator * @param int $storeId * @param CustomerAddress $billingAddress * @param CustomerAddress $shippingAddress * @param null|int $customerTaxClassId * @param null|int $customerId * @return \Magento\Tax\Model\Calculation\AbstractCalculator * @throws \InvalidArgumentException */ public function create($type, $storeId, CustomerAddress $billingAddress = null, CustomerAddress $shippingAddress = null, $customerTaxClassId = null, $customerId = null) { switch ($type) { case self::CALC_UNIT_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\UnitBaseCalculator'; break; case self::CALC_ROW_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\RowBaseCalculator'; break; case self::CALC_TOTAL_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\TotalBaseCalculator'; break; default: throw new \InvalidArgumentException('Unknown calculation type: ' . $type); } /** @var \Magento\Tax\Model\Calculation\AbstractCalculator $calculator */ $calculator = $this->objectManager->create($className, ['storeId' => $storeId]); if (null != $shippingAddress) { $calculator->setShippingAddress($shippingAddress); } if (null != $billingAddress) { $calculator->setBillingAddress($billingAddress); } if (null != $customerTaxClassId) { $calculator->setCustomerTaxClassId($customerTaxClassId); } if (null != $customerId) { $calculator->setCustomerId($customerId); } return $calculator; }
/** * Create action * * @param string $actionName * @return ActionInterface * @throws \InvalidArgumentException */ public function create($actionName) { if (!is_subclass_of($actionName, '\\Magento\\Framework\\App\\ActionInterface')) { throw new \InvalidArgumentException('Invalid action name provided'); } return $this->_objectManager->create($actionName); }
/** * @magentoApiDataFixture Magento/Sales/_files/order.php */ public function testOrderGet() { $expectedOrderData = ['base_subtotal' => '100.0000', 'subtotal' => '100.0000', 'customer_is_guest' => '1', 'increment_id' => self::ORDER_INCREMENT_ID]; $expectedPayments = ['method' => 'checkmo']; $expectedBillingAddressNotEmpty = ['city', 'postcode', 'lastname', 'street', 'region', 'telephone', 'country_id', 'firstname']; /** @var \Magento\Sales\Model\Order $order */ $order = $this->objectManager->create('Magento\\Sales\\Model\\Order'); $order->loadByIncrementId(self::ORDER_INCREMENT_ID); $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $order->getId(), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_READ_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_READ_NAME . 'get']]; $result = $this->_webApiCall($serviceInfo, ['id' => $order->getId()]); foreach ($expectedOrderData as $field => $value) { $this->assertArrayHasKey($field, $result); $this->assertEquals($value, $result[$field]); } $this->assertArrayHasKey('payments', $result); foreach ($expectedPayments as $field => $value) { $paymentsKey = key($result['payments']); $this->assertArrayHasKey($field, $result['payments'][$paymentsKey]); $this->assertEquals($value, $result['payments'][$paymentsKey][$field]); } $this->assertArrayHasKey('billing_address', $result); $this->assertArrayHasKey('shipping_address', $result); foreach ($expectedBillingAddressNotEmpty as $field) { $this->assertArrayHasKey($field, $result['billing_address']); $this->assertArrayHasKey($field, $result['shipping_address']); } }
/** * @magentoDataFixture Magento/Catalog/_files/product_simple.php * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ public function testUpdateWebsites() { /** @var \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository */ $websiteRepository = $this->objectManager->create(\Magento\Store\Api\WebsiteRepositoryInterface::class); /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); /** @var \Magento\Framework\App\CacheInterface $cacheManager */ $pageCache = $this->objectManager->create(\Magento\PageCache\Model\Cache\Type::class); /** @var \Magento\Catalog\Model\Product $product */ $product = $productRepository->get('simple'); foreach ($product->getCategoryIds() as $categoryId) { $pageCache->save('test_data', 'test_data_category_id_' . $categoryId, [\Magento\Catalog\Model\Category::CACHE_TAG . '_' . $categoryId]); $this->assertEquals('test_data', $pageCache->load('test_data_category_id_' . $categoryId)); } $websites = $websiteRepository->getList(); $websiteIds = []; foreach ($websites as $websiteCode => $website) { if (in_array($websiteCode, ['secondwebsite', 'thirdwebsite'])) { $websiteIds[] = $website->getId(); } } $this->action->updateWebsites([$product->getId()], $websiteIds, 'add'); foreach ($product->getCategoryIds() as $categoryId) { $this->assertEmpty($pageCache->load('test_data_category_id_' . $categoryId)); } }
/** * Create simple product. * * @param string $sku * @param string $name * @param bool $isActive * @param double $priceWholesale * @param double $weight * @return int */ public function create($sku, $name, $isActive, $priceWholesale, $weight) { $this->_logger->debug("Create new product (sku: {$sku}; name: {$name}; active: {$isActive}; price: {$priceWholesale}; weight: {$weight}.)"); /** * Retrieve attribute set ID. */ /** @var \Magento\Framework\Api\SearchCriteriaInterface $crit */ $crit = $this->_manObj->create(\Magento\Framework\Api\SearchCriteriaInterface::class); /** @var \Magento\Eav\Model\Entity\Attribute\Set $attrSet */ $list = $this->_mageRepoAttrSet->getList($crit); $items = $list->getItems(); $attrSet = reset($items); $attrSetId = $attrSet->getId(); /** * Create simple product. */ /** @var $product ProductInterface */ $product = $this->_manObj->create(ProductInterface::class); $product->setSku(trim($sku)); $product->setName(trim($name)); $status = $this->_getStatus($isActive); $product->setStatus($status); $product->setPrice($priceWholesale); $product->setWeight($weight); $product->setAttributeSetId($attrSetId); $product->setTypeId(Type::TYPE_SIMPLE); $product->setUrlKey($sku); // MOBI-331 : use SKU as URL Key instead of Product Name $saved = $this->_mageRepoProd->save($product); /* return product ID */ $result = $saved->getId(); return $result; }
/** * @param string $type * @return \Magento\SalesRule\Model\Rule\Action\Discount\DiscountInterface * @throws \InvalidArgumentException */ public function create($type) { if (!isset($this->classByType[$type])) { throw new \InvalidArgumentException($type . ' is unknown type'); } return $this->_objectManager->create($this->classByType[$type]); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { /* parse arguments */ $argIds = $input->getArgument(static::ARG_IDS); if (is_null($argIds)) { $ids = null; $output->writeln('<info>List of all products will be pulled from Odoo.<info>'); } else { $ids = explode(',', $argIds); $output->writeln("<info>Products with Odoo IDs ({$argIds}) will be pulled from Odoo.<info>"); } /* setup session */ $this->_setAreaCode(); /* call service operation */ /** @var ProductsFromOdooRequest $req */ $req = $this->_manObj->create(ProductsFromOdooRequest::class); $req->setOdooIds($ids); /** @var ProductsFromOdooResponse $resp */ $resp = $this->_callReplicate->productsFromOdoo($req); if ($resp->isSucceed()) { $output->writeln('<info>Replication is done.<info>'); } else { $output->writeln('<info>Replication is failed.<info>'); } }
/** @inheritdoc */ public function getItemsByOrderId($orderId) { $result = []; /* aliases and tables */ $asOrder = 'sale'; $asPvItem = 'pv'; $tblOrder = [$asOrder => $this->_resource->getTableName(Cfg::ENTITY_MAGE_SALES_ORDER_ITEM)]; $tblPvItem = [$asPvItem => $this->_resource->getTableName(Entity::ENTITY_NAME)]; /* SELECT FROM sales_order_item */ $query = $this->_conn->select(); $cols = []; $query->from($tblOrder, $cols); /* LEFT JOIN prxgt_pv_sale_item pwq */ $on = $asPvItem . '.' . Entity::ATTR_SALE_ITEM_ID . '=' . $asOrder . '.' . Cfg::E_SALE_ORDER_ITEM_A_ITEM_ID; $cols = '*'; // get all columns $query->joinLeft($tblPvItem, $on, $cols); /* WHERE */ $where = $asOrder . '.' . Cfg::E_SALE_ORDER_ITEM_A_ORDER_ID . '=' . (int) $orderId; $query->where($where); /* fetch data */ $rows = $this->_conn->fetchAll($query); foreach ($rows as $row) { /** @var Entity $item */ $item = $this->_manObj->create(Entity::class, $row); $result[$item->getSaleItemId()] = $item; } return $result; }
/** * @param string $requestName * @return AbstractCollection * @throws \Exception */ public function getReport($requestName) { if (!isset($this->collections[$requestName])) { throw new \Exception(sprintf('Not registered handle %s', $requestName)); } return $this->objectManager->create($this->collections[$requestName]); }
/** * Retrieve router instance by id * * @param string $routerId * @return RouterInterface */ protected function getRouterInstance($routerId) { if (!isset($this->routerList[$routerId]['object'])) { $this->routerList[$routerId]['object'] = $this->objectManager->create($this->routerList[$routerId]['class']); } return $this->routerList[$routerId]['object']; }
/** * Tests list of order transactions * @dataProvider filtersDataProvider */ public function testTransactionList($filters) { /** @var Order $order */ $order = $this->objectManager->create('Magento\\Sales\\Model\\Order'); /** * @var $transactionRepository \Magento\Sales\Model\Order\Payment\Transaction\Repository */ $transactionRepository = 'Magento\\Sales\\Model\\Order\\Payment\\Transaction\\Repository'; $transactionRepository = $this->objectManager->create($transactionRepository); $order->loadByIncrementId('100000006'); /** @var Payment $payment */ $payment = $order->getPayment(); /** @var Transaction $transaction */ $transaction = $transactionRepository->getByTransactionId('trx_auth', $payment->getId(), $order->getId()); $childTransactions = $transaction->getChildTransactions(); $childTransaction = reset($childTransactions); /** @var $searchCriteriaBuilder \Magento\Framework\Api\SearchCriteriaBuilder */ $searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder'); $searchCriteriaBuilder->addFilters($filters); $searchData = $searchCriteriaBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchData]; $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_READ_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_READ_NAME . 'getList']]; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertArrayHasKey('items', $result); $transactionData = $this->getPreparedTransactionData($transaction); $childTransactionData = $this->getPreparedTransactionData($childTransaction); $transactionData['child_transactions'][] = $childTransactionData; $expectedData = [$transactionData, $childTransactionData]; $this->assertEquals($expectedData, $result['items']); }
/** * Main Retry Method to start retry cycle */ public function retry() { $this->_logger->request("Main retry method called"); // Getting all the cases that were not submitted to Signifyd $waitingCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::WAITING_SUBMISSION_STATUS); foreach ($waitingCases as $case) { $this->_logger->request("Signifyd: preparing for send case no: {$case['order_increment']}"); $order = $this->_objectManager->get('Magento\\Sales\\Model\\Order')->loadByIncrementId($case['order_increment']); $caseData = $this->_helper->processOrderData($order); $result = $this->_helper->postCaseToSignifyd($caseData, $order); if ($result) { $caseObj = $this->_objectManager->create('Signifyd\\Connect\\Model\\Casedata')->load($case->getOrderIncrement())->setCode($result)->setMagentoStatus(CaseRetry::IN_REVIEW_STATUS)->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); $caseObj->save(); } } // Getting all the cases that are awaiting review from Signifyd $inReviewCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::IN_REVIEW_STATUS); foreach ($inReviewCases as $case) { $this->_logger->request("Signifyd: preparing for review case no: {$case['order_increment']}"); $order = $this->_objectManager->get('Magento\\Sales\\Model\\Order')->loadByIncrementId($case['order_increment']); $result = $this->caseRetryObj->processInReviewCase($case, $order); if ($result) { } } // Getting all the cases that need processing after the response was received $inProcessingCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::PROCESSING_RESPONSE_STATUS); foreach ($inProcessingCases as $case) { $this->_logger->request("Signifyd: preparing for review case no: {$case['order_increment']}"); $order = $this->_objectManager->get('Magento\\Sales\\Model\\Order')->loadByIncrementId($case['order_increment']); $this->caseRetryObj->processResponseStatus($case, $order); } $this->_logger->request("Main retry method ended"); return; }
public function setUp() { $directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', ['root' => DirectoryList::ROOT]); $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem', ['directoryList' => $directoryList]); $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_model = $this->_objectManager->create('Magento\\Persistent\\Model\\Persistent\\Config', ['filesystem' => $filesystem]); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $layout \Magento\Framework\View\Layout */ $layout = $this->objectManager->create('Magento\\Framework\\View\\LayoutInterface'); $this->block = $layout->createBlock('Magento\\Integration\\Block\\Adminhtml\\Integration\\Edit\\Form'); }
protected function getConfigurableAttributeOptions() { /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection */ $optionCollection = $this->objectManager->create('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option\\Collection'); $options = $optionCollection->setAttributeFilter($this->configurableAttribute->getId())->getData(); return $options; }
/** * Get applied to layer filter items * * @return Item[] */ public function getFilters() { try { if ($this->bxHelperData->isFilterLayoutEnabled($this->_layer)) { $category = $this->_categoryViewBlock->getCurrentCategory(); if ($category != null && $category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) { return parent::getFilters(); } $filters = array(); $facets = $this->p13nHelper->getFacets(); if ($facets) { foreach ($this->bxHelperData->getAllFacetFieldNames() as $fieldName) { if ($facets->isSelected($fieldName)) { $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\LayerFilterItem"); $filter->setFacets($facets); $filter->setFieldName($fieldName); $filters[] = $filter; } } } return $filters; } return parent::getFilters(); } catch (\Exception $e) { $this->bxHelperData->setFallback(true); $this->_logger->critical($e); return parent::getFilters(); } }
/** * Create link builder instance * * @param string $instance * @param array $arguments * @return CopyConstructorInterface * @throws \InvalidArgumentException */ public function create($instance, array $arguments = []) { if (!is_subclass_of($instance, '\\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface')) { throw new \InvalidArgumentException($instance . ' does not implement \\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface'); } return $this->objectManager->create($instance, $arguments); }
/** * Retrieve indexer instance by id * * @param string $indexerId * @return IndexerInterface */ public function get($indexerId) { if (!isset($this->indexers[$indexerId])) { $this->indexers[$indexerId] = $this->objectManager->create('Magento\\Indexer\\Model\\IndexerInterface')->load($indexerId); } return $this->indexers[$indexerId]; }
/** * @param string $className * @return \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter * @throws \InvalidArgumentException */ public function create($className) { if (!$className) { throw new \InvalidArgumentException('Incorrect class name'); } return $this->_objectManager->create($className); }
/** * @return \Magento\Framework\View\Result\Layout */ public function create() { /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->objectManager->create($this->instanceName); $resultLayout->addDefaultHandle(); return $resultLayout; }
/** * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ public function testBundleImport() { // import data from CSV file $pathToFile = __DIR__ . '/../../_files/import_bundle.csv'; $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]); $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData(); $this->assertTrue($errors->getErrorsCount() == 0); $this->model->importData(); $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class); $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME); $this->assertTrue(is_numeric($productId)); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class); $product->load($productId); $this->assertFalse($product->isObjectNew()); $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName()); $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId()); $this->assertEquals(1, $product->getShipmentType()); $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList); $bundleOptionCollection = $product->getExtensionAttributes()->getBundleProductOptions(); $this->assertEquals(2, count($bundleOptionCollection)); foreach ($bundleOptionCollection as $optionKey => $option) { $this->assertEquals('checkbox', $option->getData('type')); $this->assertEquals('Option ' . ($optionKey + 1), $option->getData('title')); $this->assertEquals(self::TEST_PRODUCT_NAME, $option->getData('sku')); $this->assertEquals($optionKey + 1, count($option->getData('product_links'))); foreach ($option->getData('product_links') as $linkKey => $productLink) { $optionSku = 'Simple ' . ($optionKey + 1 + $linkKey); $this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id')); $this->assertEquals($optionSku, $productLink->getData('sku')); } } }
/** * Prolong session * * @return string */ public function prolongAction() { try { if ($this->objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { /** @var \Magento\Framework\App\State $adminAppState */ $adminAppState = $this->objectManager->get('Magento\Framework\App\State'); $adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN); /* @var \Magento\Backend\Model\Auth\Session $session */ $sessionConfig = $this->objectManager->get('Magento\Backend\Model\Session\AdminConfig'); $sessionConfig->setCookiePath('/setup'); $session = $this->objectManager->create( 'Magento\Backend\Model\Auth\Session', [ 'sessionConfig' => $sessionConfig, 'appState' => $adminAppState ] ); $session->prolong(); return \Zend_Json::encode(['success' => true]); } } catch (\Exception $e) { } return \Zend_Json::encode(['success' => false]); }