/** * @param string $entityType * @return Operation\ReadInterface * @throws \Exception */ public function getReadOperation($entityType) { if (!isset($this->operations[$entityType]['read'])) { return $this->objectManager->get($this->operations['default']['read']); } return $this->objectManager->get($this->operations[$entityType]['read']); }
public function testGetGridParentHtml() { $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Cart', '', []); $mockCollection = $this->getMockBuilder('\\Magento\\Framework\\Data\\Collection')->disableOriginalConstructor()->getMock(); $this->_block->setCollection($mockCollection); $this->assertContains("<div class=\"admin__data-grid-header admin__data-grid-toolbar\"", $this->_block->getGridParentHtml()); }
protected function setUp() { parent::setUp(); $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->fileSystem = $this->objectManager->get(\Magento\Framework\Filesystem::class); $this->productResource = $this->objectManager->create(\Magento\Catalog\Model\ResourceModel\Product::class); }
/** * Create cache model * * @return CacheInterface */ protected function _getCache() { if (null == $this->_cache) { $this->_cache = $this->_objectManager->get('Magento\\Framework\\App\\Cache'); } return $this->_cache; }
/** * Validate a composer.json under the given path * * @param string $path path to composer.json */ private function validateComposerJsonFile($path) { /** @var \Magento\Framework\Composer\MagentoComposerApplicationFactory $appFactory */ $appFactory = self::$objectManager->get('Magento\\Framework\\Composer\\MagentoComposerApplicationFactory'); $app = $appFactory->create(); $app->runComposerCommand(['command' => 'validate'], $path); }
/** * MOBI-504: don't retrieve session depended objects from Object Manager * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ private function _getTzDelta() { if (is_null($this->tzDelta)) { $this->tzDelta = $this->manObj->get(\Magento\Framework\Stdlib\DateTime\DateTime::class); } return $this->tzDelta; }
/** * Calculate the largest links block * * @param array $additionalRowsCount * @param int $productId * @return array|mixed */ public function getAdditionalRowsCount($additionalRowsCount, $productId) { foreach ($this->customizers as $className) { $additionalRowsCount = $this->objectManager->get($className)->getAdditionalRowsCount($additionalRowsCount, $productId); } return $additionalRowsCount; }
/** * @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(); }
/** * Create data helper * * @param string $area * @return \Magento\Authorizenet\Helper\Backend\Data|\Magento\Authorizenet\Helper\Data * @throws LocalizedException */ public function create($area) { if (!isset($this->helperMap[$area])) { throw new LocalizedException(__(sprintf('For this area <%s> no suitable helper', $area))); } return $this->objectManager->get($this->helperMap[$area]); }
/** * @param array $newData * @param array $expectedResult * @param array $fixtureData * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php * @dataProvider saveStockItemBySkuWithWrongInputDataProvider */ public function testStockItemPUTWithWrongInput($newData, $expectedResult, $fixtureData) { $stockItemOld = $this->getStockItemBySku($fixtureData); $productSku = 'simple1'; $itemId = $stockItemOld['item_id']; $resourcePath = str_replace([':productSku', ':itemId'], [$productSku, $itemId], self::RESOURCE_PUT_PATH); $serviceInfo = ['rest' => ['resourcePath' => $resourcePath, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT], 'soap' => ['service' => 'catalogInventoryStockRegistryV1', 'serviceVersion' => self::SERVICE_VERSION, 'operation' => 'catalogInventoryStockRegistryV1UpdateStockItemBySku']]; /** @var \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemDetailsDo */ $stockItemDetailsDo = $this->objectManager->get('Magento\\CatalogInventory\\Api\\Data\\StockItemInterfaceFactory')->create(); /** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */ $dataObjectHelper = $this->objectManager->get('Magento\\Framework\\Api\\DataObjectHelper'); $dataObjectHelper->populateWithArray($stockItemDetailsDo, $newData, '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface'); $data = $stockItemDetailsDo->getData(); $data['show_default_notification_message'] = false; $arguments = ['productSku' => $productSku, 'stockItem' => $data]; $this->assertEquals($stockItemOld['item_id'], $this->_webApiCall($serviceInfo, $arguments)); /** @var \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory */ $stockItemFactory = $this->objectManager->get('Magento\\CatalogInventory\\Api\\Data\\StockItemInterfaceFactory'); $stockItem = $stockItemFactory->create(); /** @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource */ $stockItemResource = $this->objectManager->get('Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item'); $stockItemResource->loadByProductId($stockItem, $stockItemOld['product_id'], $stockItemOld['stock_id']); $expectedResult['item_id'] = $stockItem->getItemId(); $this->assertEquals($expectedResult, array_intersect_key($stockItem->getData(), $expectedResult)); }
/** * 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]); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->helper = $this->objectManager->get('Magento\\Catalog\\Helper\\Data'); $this->taxRuleFixtureFactory = new TaxRuleFixtureFactory(); $this->scopeConfig = $this->objectManager->get('Magento\\Framework\\App\\MutableScopeConfig'); }
/** * Modify price * * @param mixed $price * @param Product $product * @return mixed */ public function modifyPrice($price, Product $product) { foreach ($this->modifiers as $modifierClass) { $price = $this->objectManager->get($modifierClass)->modifyPrice($price, $product); } return $price; }
/** * Returns operation by name by entity type * * @param string $entityType * @param string $operationName * @return object */ public function getOperation($entityType, $operationName) { if (!isset($this->operations[$entityType][$operationName])) { return $this->objectManager->get($this->operations['default'][$operationName]); } return $this->objectManager->get($this->operations[$entityType][$operationName]); }
/** * Retrieve subject * * @return \Magento\Config\Model\Config\Structure\SearchInterface */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->get('Magento\\Config\\Model\\Config\\Structure'); } return $this->_subject; }
/** * 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; }
/** * @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')); } } }
/** * 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; }
/** * @param Context $context Helper context. * @param ObjectManagerInterface $objectManager The object manager * @param AttributeFactory $attributeFactory Factory used to create attributes. * @param string $collectionFactory Factory class name to use for create attribute collections. */ public function __construct(Context $context, ObjectManagerInterface $objectManager, AttributeFactory $attributeFactory, $collectionFactory) { parent::__construct($context); $this->attributeFactory = $attributeFactory; $this->objectManager = $objectManager; $this->attributeCollectionFactory = $this->objectManager->get($collectionFactory); }
public function setUp() { $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_persistentSession = $this->_objectManager->get('Magento\\Persistent\\Helper\\Session'); $this->_customerSession = $this->_objectManager->get('Magento\\Customer\\Model\\Session'); $this->_model = $this->_objectManager->create('Magento\\Persistent\\Observer\\SynchronizePersistentOnLoginObserver', ['persistentSession' => $this->_persistentSession, 'customerSession' => $this->_customerSession]); }
/** * Get datetime * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ private function getDateTime() { if ($this->dateTime === null) { $this->dateTime = $this->objectManager->get('Magento\\Setup\\Model\\DateTime\\DateTimeProvider')->get(); } return $this->dateTime; }
/** * 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'); }
/** * Verify that an order placed with an existing customer can re-use the customer addresses. * * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php * @magentoAppIsolation enabled * @magentoDbIsolation enabled */ public function testPrepareCustomerQuote() { /** @var Quote $quote */ $quote = $this->_getFixtureQuote(); $quote->setCheckoutMethod(Onepage::METHOD_CUSTOMER); // to dive into _prepareCustomerQuote() on switch $quote->getShippingAddress()->setSameAsBilling(0); $quote->setReservedOrderId(null); $customer = $this->_objectManager->create('Magento\\Customer\\Model\\Customer')->load(1); $customer->setDefaultBilling(false)->setDefaultShipping(false)->save(); /** @var \Magento\Customer\Model\Session $customerSession */ $customerSession = $this->_objectManager->get('Magento\\Customer\\Model\\Session'); $customerSession->loginById(1); $checkout = $this->_getCheckout($quote); $checkout->place('token'); /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerService */ $customerService = $this->_objectManager->get('Magento\\Customer\\Api\\CustomerRepositoryInterface'); $customer = $customerService->getById($quote->getCustomerId()); $this->assertEquals(1, $quote->getCustomerId()); $this->assertEquals(2, count($customer->getAddresses())); $this->assertEquals(1, $quote->getBillingAddress()->getCustomerAddressId()); $this->assertEquals(2, $quote->getShippingAddress()->getCustomerAddressId()); $order = $checkout->getOrder(); $this->assertEquals(1, $order->getBillingAddress()->getCustomerAddressId()); $this->assertEquals(2, $order->getShippingAddress()->getCustomerAddressId()); }
/** * @magentoApiDataFixture Magento/Sales/_files/shipment.php */ public function testShipmentGet() { /** @var \Magento\Sales\Model\Order\Shipment $shipment */ $shipmentCollection = $this->objectManager->get('Magento\\Sales\\Model\\ResourceModel\\Order\\Shipment\\Collection'); $shipment = $shipmentCollection->getFirstItem(); $shipment->load($shipment->getId()); $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $shipment->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' => $shipment->getId()]); $data = $result; $this->assertArrayHasKey('items', $result); $this->assertArrayHasKey('tracks', $result); unset($data['items']); unset($data['packages']); unset($data['tracks']); foreach ($data as $key => $value) { if (!empty($value)) { $this->assertEquals($shipment->getData($key), $value, $key); } } $shipmentItem = $this->objectManager->get('Magento\\Sales\\Model\\Order\\Shipment\\Item'); foreach ($result['items'] as $item) { $shipmentItem->load($item['entity_id']); foreach ($item as $key => $value) { $this->assertEquals($shipmentItem->getData($key), $value, $key); } } $shipmentTrack = $this->objectManager->get('Magento\\Sales\\Model\\Order\\Shipment\\Track'); foreach ($result['tracks'] as $item) { $shipmentTrack->load($item['entity_id']); foreach ($item as $key => $value) { $this->assertEquals($shipmentTrack->getData($key), $value, $key); } } }
protected function setUp() { parent::setUp(); $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->fileSystem = $this->objectManager->get(\Magento\Framework\Filesystem::class); $this->model = $this->objectManager->create(\Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing::class); }
protected function setUp() { \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Multishipping\\Block\\Checkout\\Overview', 'checkout_overview', ['data' => ['renderer_template' => 'Magento_Multishipping::checkout/item/default.phtml', 'row_renderer_template' => 'Magento_Multishipping::checkout/overview/item.phtml']]); $this->_block->addChild('renderer.list', '\\Magento\\Framework\\View\\Element\\RendererList'); $this->_block->getChildBlock('renderer.list')->addChild('default', '\\Magento\\Checkout\\Block\\Cart\\Item\\Renderer', ['template' => 'cart/item/default.phtml']); }
/** * Create specification instance * * @param string $specificationClass * @return SpecificationInterface * @throws \InvalidArgumentException */ public function create($specificationClass) { $specification = $this->objectManager->get($specificationClass); if (!$specification instanceof SpecificationInterface) { throw new \InvalidArgumentException('Specification must implement SpecificationInterface'); } return $specification; }
/** * Get section source by name * * @param string $name * @return SectionSourceInterface * @throws LocalizedException */ protected function get($name) { $sectionSource = $this->objectManager->get($name); if (!$sectionSource instanceof SectionSourceInterface) { throw new LocalizedException(__('%1 doesn\'t extend \\Magento\\Customer\\CustomerData\\SectionSourceInterface', $name)); } return $sectionSource; }
public function setUp() { $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Persistent\Helper\Session $persistentSessionHelper */ $this->_persistentSessionHelper = $this->_objectManager->create('Magento\\Persistent\\Helper\\Session'); $this->_customerSession = $this->_objectManager->get('Magento\\Customer\\Model\\Session'); $this->_block = $this->_objectManager->create('Magento\\Persistent\\Block\\Header\\Additional'); }
/** * @param string $entityType * @return object * @throws NotFoundException */ public function create($entityType) { if (!isset($this->entities[$entityType])) { $message = sprintf('Repository for entity type %s is not declared', $entityType); throw new NotFoundException(new \Magento\Framework\Phrase($message)); } return $this->objectManager->get($this->entities[$entityType]); }