Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_simple_xss.php
Go to the documentation of this file.
1 <?php
9 
10 $objectManager->removeSharedInstance(\Magento\Catalog\Model\ProductRepository::class);
11 $objectManager->removeSharedInstance(\Magento\Catalog\Model\CategoryLinkRepository::class);
12 
14 $categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
15 
16 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
17 
18 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
19  ->setAttributeSetId(4)
20  ->setWebsiteIds([1])
21  ->setName('<script>alert("xss");</script>')
22  ->setSku('product-with-xss')
23  ->setPrice(10)
24  ->setDescription('Description with <b>html tag</b>')
25  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
26  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
27  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
28  ->save();
29 
30 $categoryLinkManagement->assignProductToCategories(
31  $product->getSku(),
32  [2]
33 );
$objectManager
$categoryLinkManagement