Skip to content

Commit 70bfe84

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-741' into PR_19_May_2022_Odubovyk
2 parents 609e41e + 130beb0 commit 70bfe84

File tree

2 files changed

+84
-0
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Initialization

2 files changed

+84
-0
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ class Helper
121121
*/
122122
private $categoryLinkFactory;
123123

124+
/**
125+
* @var array
126+
*/
127+
private $productDataKeys = [
128+
'weight',
129+
'special_price',
130+
'cost',
131+
'country_of_manufacture',
132+
'description',
133+
'short_description',
134+
'meta_description',
135+
'meta_keyword',
136+
'meta_title',
137+
'page_layout',
138+
'custom_design',
139+
'gift_wrapping_price'
140+
];
141+
124142
/**
125143
* Constructor
126144
*
@@ -203,6 +221,12 @@ public function initializeFromData(Product $product, array $productData)
203221
$productData['product_has_weight'] = 0;
204222
}
205223

224+
foreach ($productData as $key => $value) {
225+
if (in_array($key, $this->productDataKeys) && $value === '') {
226+
$productData[$key] = null;
227+
}
228+
}
229+
206230
foreach (['category_ids', 'website_ids'] as $field) {
207231
if (!isset($productData[$field])) {
208232
$productData[$field] = [];
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+
namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test for Initialization Helper
16+
*/
17+
class HelperTest extends TestCase
18+
{
19+
/**
20+
* @var Helper
21+
*/
22+
private $helper;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->helper = Bootstrap::getObjectManager()->get(Helper::class);
30+
}
31+
32+
/**
33+
* Test that method resets product data
34+
*
35+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
36+
*/
37+
public function testInitializeFromData()
38+
{
39+
/** @var ProductRepositoryInterface $productRepository */
40+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
41+
$product = $productRepository->get('simple1');
42+
43+
$productData = [
44+
'weight' => null,
45+
'special_price' => null,
46+
'cost' => null,
47+
'description' => null,
48+
'short_description' => null,
49+
'meta_description' => null,
50+
'meta_keyword' => null,
51+
'meta_title' => null,
52+
];
53+
54+
$resultProduct = $this->helper->initializeFromData($product, $productData);
55+
56+
foreach (array_keys($productData) as $key) {
57+
$this->assertEquals(null, $resultProduct->getData($key));
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)