3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Controller \Adminhtml \Product \Initialization ;
7
8
8
9
use Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory as CustomOptionFactory ;
9
10
use Magento \Catalog \Api \Data \ProductLinkInterfaceFactory as ProductLinkFactory ;
11
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
10
12
use Magento \Catalog \Api \ProductRepositoryInterface \Proxy as ProductRepository ;
13
+ use Magento \Catalog \Controller \Adminhtml \Product \Initialization \Helper \AttributeDefaultValueFilter ;
11
14
use Magento \Catalog \Model \Product ;
12
15
use Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks ;
13
16
use Magento \Catalog \Model \Product \Link \Resolver as LinkResolver ;
17
+ use Magento \Catalog \Model \Product \LinkTypeProvider ;
14
18
use Magento \Framework \App \ObjectManager ;
15
19
use Magento \Catalog \Controller \Adminhtml \Product \Initialization \Helper \AttributeFilter ;
16
20
@@ -81,7 +85,7 @@ class Helper
81
85
private $ dateTimeFilter ;
82
86
83
87
/**
84
- * @var \Magento\Catalog\Model\Product\ LinkTypeProvider
88
+ * @var LinkTypeProvider
85
89
*/
86
90
private $ linkTypeProvider ;
87
91
@@ -99,10 +103,10 @@ class Helper
99
103
* @param ProductLinks $productLinks
100
104
* @param \Magento\Backend\Helper\Js $jsHelper
101
105
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
102
- * @param \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory |null $customOptionFactory
103
- * @param \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory |null $productLinkFactory
104
- * @param \Magento\Catalog\Api\ ProductRepositoryInterface|null $productRepository
105
- * @param \Magento\Catalog\Model\Product\ LinkTypeProvider|null $linkTypeProvider
106
+ * @param CustomOptionFactory |null $customOptionFactory
107
+ * @param ProductLinkFactory |null $productLinkFactory
108
+ * @param ProductRepositoryInterface|null $productRepository
109
+ * @param LinkTypeProvider|null $linkTypeProvider
106
110
* @param AttributeFilter|null $attributeFilter
107
111
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
108
112
*/
@@ -113,10 +117,10 @@ public function __construct(
113
117
\Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks $ productLinks ,
114
118
\Magento \Backend \Helper \Js $ jsHelper ,
115
119
\Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter ,
116
- \ Magento \ Catalog \ Api \ Data \ ProductCustomOptionInterfaceFactory $ customOptionFactory = null ,
117
- \ Magento \ Catalog \ Api \ Data \ ProductLinkInterfaceFactory $ productLinkFactory = null ,
118
- \ Magento \ Catalog \ Api \ ProductRepositoryInterface $ productRepository = null ,
119
- \ Magento \ Catalog \ Model \ Product \ LinkTypeProvider $ linkTypeProvider = null ,
120
+ CustomOptionFactory $ customOptionFactory = null ,
121
+ ProductLinkFactory $ productLinkFactory = null ,
122
+ ProductRepositoryInterface $ productRepository = null ,
123
+ LinkTypeProvider $ linkTypeProvider = null ,
120
124
AttributeFilter $ attributeFilter = null
121
125
) {
122
126
$ this ->request = $ request ;
@@ -125,16 +129,13 @@ public function __construct(
125
129
$ this ->productLinks = $ productLinks ;
126
130
$ this ->jsHelper = $ jsHelper ;
127
131
$ this ->dateFilter = $ dateFilter ;
128
- $ this ->customOptionFactory = $ customOptionFactory ?: \Magento \Framework \App \ObjectManager::getInstance ()
129
- ->get (\Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory::class);
130
- $ this ->productLinkFactory = $ productLinkFactory ?: \Magento \Framework \App \ObjectManager::getInstance ()
131
- ->get (\Magento \Catalog \Api \Data \ProductLinkInterfaceFactory::class);
132
- $ this ->productRepository = $ productRepository ?: \Magento \Framework \App \ObjectManager::getInstance ()
133
- ->get (\Magento \Catalog \Api \ProductRepositoryInterface::class);
134
- $ this ->linkTypeProvider = $ linkTypeProvider ?: \Magento \Framework \App \ObjectManager::getInstance ()
135
- ->get (\Magento \Catalog \Model \Product \LinkTypeProvider::class);
136
- $ this ->attributeFilter = $ attributeFilter ?: \Magento \Framework \App \ObjectManager::getInstance ()
137
- ->get (AttributeFilter::class);
132
+
133
+ $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
134
+ $ this ->customOptionFactory = $ customOptionFactory ?: $ objectManager ->get (CustomOptionFactory::class);
135
+ $ this ->productLinkFactory = $ productLinkFactory ?: $ objectManager ->get (ProductLinkFactory::class);
136
+ $ this ->productRepository = $ productRepository ?: $ objectManager ->get (ProductRepositoryInterface::class);
137
+ $ this ->linkTypeProvider = $ linkTypeProvider ?: $ objectManager ->get (LinkTypeProvider::class);
138
+ $ this ->attributeFilter = $ attributeFilter ?: $ objectManager ->get (AttributeFilter::class);
138
139
}
139
140
140
141
/**
@@ -150,8 +151,7 @@ public function __construct(
150
151
*/
151
152
public function initializeFromData (\Magento \Catalog \Model \Product $ product , array $ productData )
152
153
{
153
- unset($ productData ['custom_attributes ' ]);
154
- unset($ productData ['extension_attributes ' ]);
154
+ unset($ productData ['custom_attributes ' ], $ productData ['extension_attributes ' ]);
155
155
156
156
if ($ productData ) {
157
157
$ stockData = isset ($ productData ['stock_data ' ]) ? $ productData ['stock_data ' ] : [];
@@ -199,28 +199,13 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
199
199
$ productData ['tier_price ' ] = isset ($ productData ['tier_price ' ]) ? $ productData ['tier_price ' ] : [];
200
200
201
201
$ useDefaults = (array )$ this ->request ->getPost ('use_default ' , []);
202
-
203
202
$ productData = $ this ->attributeFilter ->prepareProductAttributes ($ product , $ productData , $ useDefaults );
204
-
205
203
$ product ->addData ($ productData );
206
204
207
205
if ($ wasLockedMedia ) {
208
206
$ product ->lockAttribute ('media ' );
209
207
}
210
208
211
- /**
212
- * Check "Use Default Value" checkboxes values
213
- */
214
- foreach ($ useDefaults as $ attributeCode => $ useDefaultState ) {
215
- if ($ useDefaultState ) {
216
- $ product ->setData ($ attributeCode , null );
217
- // UI component sends value even if field is disabled, so 'Use Config Settings' must be reset to false
218
- if ($ product ->hasData ('use_config_ ' . $ attributeCode )) {
219
- $ product ->setData ('use_config_ ' . $ attributeCode , false );
220
- }
221
- }
222
- }
223
-
224
209
$ product = $ this ->setProductLinks ($ product );
225
210
$ product = $ this ->fillProductOptions ($ product , $ productOptions );
226
211
0 commit comments