Skip to content

Commit f4ca6de

Browse files
committed
Merge branch 'MC-35421' into 2.4-develop-com-pr13
2 parents 794fd6d + bccbe2c commit f4ca6de

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Helper\DefaultCategory;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Catalog\Model\Product\Type;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Store\Api\WebsiteRepositoryInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
18+
$objectManager = Bootstrap::getObjectManager();
19+
/** @var WebsiteRepositoryInterface $websiteRepository */
20+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
21+
$defaultWebsiteId = $websiteRepository->get('base')->getId();
22+
/** @var DefaultCategory $defaultCategory */
23+
$defaultCategory = $objectManager->get(DefaultCategory::class);
24+
/** @var ProductRepositoryInterface $productRepository */
25+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
26+
/** @var ProductInterfaceFactory $productFactory */
27+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
28+
$product = $productFactory->create();
29+
$productData = [
30+
ProductInterface::TYPE_ID => Type::TYPE_SIMPLE,
31+
ProductInterface::ATTRIBUTE_SET_ID => $product->getDefaultAttributeSetId(),
32+
ProductInterface::SKU => 'product_disabled',
33+
ProductInterface::NAME => 'Product with category',
34+
ProductInterface::PRICE => 10,
35+
ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH,
36+
ProductInterface::STATUS => Status::STATUS_DISABLED,
37+
'website_ids' => [$defaultWebsiteId],
38+
'stock_data' => [
39+
'use_config_manage_stock' => 1,
40+
'qty' => 100,
41+
'is_qty_decimal' => 0,
42+
'is_in_stock' => 1,
43+
],
44+
'category_ids' => [$defaultCategory->getId()],
45+
];
46+
$product->setData($productData);
47+
48+
$productRepository->save($product);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var Registry $registry */
15+
$registry = $objectManager->get(Registry::class);
16+
/** @var ProductRepositoryInterface $productRepository */
17+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
18+
$registry->unregister('isSecureArea');
19+
$registry->register('isSecureArea', true);
20+
21+
try {
22+
$productRepository->deleteById('product_disabled');
23+
} catch (NoSuchEntityException $e) {
24+
// product already deleted
25+
}
26+
27+
$registry->unregister('isSecureArea');
28+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)