Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
url_rewrites.php
Go to the documentation of this file.
1 <?php
9 $category->isObjectNew(true);
10 $category->setId(3)
11  ->setName('Category 1')
12  ->setParentId(2)
13  ->setPath('1/2/3')
14  ->setLevel(2)
15  ->setAvailableSortBy('name')
16  ->setDefaultSortBy('name')
17  ->setIsActive(true)
18  ->setPosition(1)
19  ->save();
20 
21 $urlKeys = ['url-key', 'url-key-1', 'url-key-2', 'url-key-5', 'url-key-1000', 'url-key-999', 'url-key-asdf'];
22 
23 foreach ($urlKeys as $i => $urlKey) {
24  $id = $i + 1;
26  \Magento\Catalog\Model\Product::class
27  );
28  $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
29  ->setStoreId(1)
30  ->setAttributeSetId(4)
31  ->setWebsiteIds([1])
32  ->setName('Simple Product ' . $id)
33  ->setSku('simple-' . $id)
34  ->setPrice(10)
35  ->setCategoryIds([3])
36  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
37  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
38  ->setUrlKey($urlKey)->setUrlPath($urlKey)
39  ->save();
40 }
$category
Definition: url_rewrites.php:8
$id
Definition: fieldset.phtml:14
$urlKeys
$product
$i
Definition: gallery.phtml:31