Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_with_unique_input_attribute.php
Go to the documentation of this file.
1 <?php
6 require __DIR__ . '/unique_input_attribute.php';
7 
9 
11 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
12 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
13  ->setAttributeSetId(4)
14  ->setName('Simple Product with unique input attribute')
15  ->setSku('simple product with unique input attribute')
16  ->setPrice(10)
17  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
18  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
19  ->setWebsiteIds([1])
20  ->setStockData(['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1])
21  ->setData($attribute->getAttributeCode(), 'unique value')
22  ->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60