Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
integration
testsuite
Magento
Quote
Fixtures
simple_product.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
use
Magento\Catalog\Api\ProductRepositoryInterface
;
9
use
Magento\Catalog\Model\Product
;
10
use
Magento\Catalog\Model\Product\Attribute\Source\Status
;
11
use
Magento\Catalog\Model\Product\Visibility
;
12
use
Magento\CatalogInventory\Api\Data\StockItemInterface
;
13
use
Magento\TestFramework\Helper\Bootstrap
;
14
use
Magento\TestFramework\ObjectManager
;
15
17
$objectManager
= Bootstrap::getObjectManager();
18
20
$product
=
$objectManager
->create(Product::class);
21
$product
->setTypeId(
'simple'
)
22
->setAttributeSetId(4)
23
->setName(
'Simple Product'
)
24
->setSku(
'simple002'
)
25
->setPrice(10)
26
->setQty(100)
27
->setVisibility(Visibility::VISIBILITY_BOTH)
28
->setStatus(Status::STATUS_ENABLED);
29
31
$stockItem
=
$objectManager
->create(StockItemInterface::class);
32
$stockItem
->setQty(100)
33
->setIsInStock(
true
);
34
$extensionAttributes
=
$product
->getExtensionAttributes();
35
$extensionAttributes
->setStockItem(
$stockItem
);
36
38
$productRepository
=
$objectManager
->get(ProductRepositoryInterface::class);
39
$product
=
$productRepository
->save(
$product
);
Magento\CatalogInventory\Api\Data\StockItemInterface
Definition:
StockItemInterface.php:19
Magento\Catalog\Model\Product\Attribute\Source\Status
Definition:
Status.php:18
$stockItem
$stockItem
Definition:
simple_product.php:31
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
Magento\Catalog\Api\ProductRepositoryInterface
Definition:
ProductRepositoryInterface.php:14
$productRepository
$productRepository
Definition:
simple_product.php:38
Magento\Catalog\Model\Product
Definition:
ActionTest.php:6
$extensionAttributes
$extensionAttributes
Definition:
simple_product.php:34
Magento\Catalog\Model\Product\Visibility
Definition:
Visibility.php:17
$product
$product
Definition:
simple_product.php:8
$objectManager
$objectManager
Definition:
simple_product.php:17
Magento\TestFramework\ObjectManager
Definition:
Config.php:6