Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_with_fpt.php
Go to the documentation of this file.
1 <?php
9 
11 $installer = Bootstrap::getObjectManager()->create(
12  \Magento\Catalog\Setup\CategorySetup::class
13 );
14 $attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default');
15 $entityModel = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity::class);
16 $entityTypeId = $entityModel->setType(Product::ENTITY)->getTypeId();
17 $groupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
18 
19 $attribute = Bootstrap::getObjectManager()->create(
20  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
21 );
22 $attribute->setAttributeCode(
23  'fpt_for_all'
24 )->setEntityTypeId(
26 )->setAttributeGroupId(
27  $groupId
28 )->setAttributeSetId(
30 )->setFrontendInput(
31  'weee'
32 )->setIsUserDefined(
33  1
34 )->save();
35 
36 $product = Bootstrap::getObjectManager()->create(Product::class);
37 $product->setTypeId(
38  'simple'
39 )->setAttributeSetId(
41 )->setStoreId(
42  1
43 )->setWebsiteIds(
44  [1]
45 )->setVisibility(
46  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
47 )->setStatus(
48  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
49 )->setStockData(
50  ['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
51 )->setName(
52  'Simple Product FPT'
53 )->setSku(
54  'simple-with-ftp'
55 )->setPrice(
56  100
57 )->setFptForAll(
58  [['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 12.70, 'delete' => '']]
59 )->save();
$attribute
$entityTypeId
$installer
$attributeSetId
$entityModel