Skip to content

Commit ecb94d8

Browse files
committed
Merge remote-tracking branch 'origin/MC-15671' into 2.2-develop-pr95
2 parents b14a197 + da206d7 commit ecb94d8

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var $product \Magento\Catalog\Model\Product */
11+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
12+
13+
$product->setTypeId('simple')
14+
->setAttributeSetId($product->getDefaultAttributeSetId())
15+
->setWebsiteIds([1])
16+
->setName('Simple Product With File Custom Option')
17+
->setSku('simple-with-file-option')
18+
->setPrice(10)
19+
->setMetaTitle('meta title')
20+
->setMetaKeyword('meta keyword')
21+
->setMetaDescription('meta description')
22+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
23+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
24+
->setCanSaveCustomOptions(true)
25+
->setStockData(
26+
[
27+
'qty' => 100,
28+
'is_in_stock' => 1,
29+
]
30+
)
31+
->setHasOptions(true);
32+
33+
$option = [
34+
'title' => 'file option',
35+
'type' => 'file',
36+
'is_require' => true,
37+
'sort_order' => 3,
38+
'price' => 30.0,
39+
'price_type' => 'fixed',
40+
'sku' => 'file option sku',
41+
'file_extension' => 'jpg,png,gif',
42+
'image_size_x' => 2000,
43+
'image_size_y' => 2000,
44+
];
45+
46+
$customOptions = [];
47+
48+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */
49+
$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
50+
51+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $customOption */
52+
$customOption = $customOptionFactory->create(['data' => $option]);
53+
$customOption->setProductSku($product->getSku());
54+
$customOptions[] = $customOption;
55+
56+
$product->setOptions($customOptions);
57+
58+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */
59+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
60+
$productRepository->save($product);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var \Magento\Framework\Registry $registry */
9+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
10+
11+
$registry->unregister('isSecureArea');
12+
$registry->register('isSecureArea', true);
13+
14+
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
15+
\Magento\Catalog\Model\ProductRepository::class
16+
);
17+
try {
18+
$product = $repository->get('simple-with-file-option', false, null, true);
19+
$product->delete();
20+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
21+
//Entity already deleted
22+
}
23+
24+
$registry->unregister('isSecureArea');
25+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)