本文整理汇总了PHP中Magento\Framework\ObjectManagerInterface::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManagerInterface::create方法的具体用法?PHP ObjectManagerInterface::create怎么用?PHP ObjectManagerInterface::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\ObjectManagerInterface
的用法示例。
在下文中一共展示了ObjectManagerInterface::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @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();
}
示例2: create
/**
* 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]);
}
示例3: _getSubject
/**
* 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;
}
示例4: execute
/**
* {@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;
}
}
示例5: setUp
/**
* 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');
}
示例6: setUp
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');
}
示例7: testInitForm
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'));
}
示例8: get
/**
* 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;
}
示例9: create
/**
* 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;
}
示例10: create
/**
* 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);
}
示例11: testOrderGet
/**
* @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']);
}
}
示例12: testUpdateWebsites
/**
* @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));
}
}
示例13: create
/**
* 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;
}
示例14: create
/**
* @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]);
}
示例15: execute
/**
* {@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>');
}
}