@@ -118,6 +118,9 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
118
118
$ attribute ->setAttributeId ($ existingModel ->getAttributeId ());
119
119
$ attribute ->setIsUserDefined ($ existingModel ->getIsUserDefined ());
120
120
$ attribute ->setFrontendInput ($ existingModel ->getFrontendInput ());
121
+ if ($ attribute ->getIsUserDefined ()) {
122
+ $ this ->processAttributeData ($ attribute );
123
+ }
121
124
122
125
if (is_array ($ attribute ->getFrontendLabels ())) {
123
126
$ defaultFrontendLabel = $ attribute ->getDefaultFrontendLabel ();
@@ -156,15 +159,7 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
156
159
$ this ->validateCode ($ attribute ->getAttributeCode ());
157
160
$ this ->validateFrontendInput ($ attribute ->getFrontendInput ());
158
161
159
- $ attribute ->setBackendType (
160
- $ attribute ->getBackendTypeByInput ($ attribute ->getFrontendInput ())
161
- );
162
- $ attribute ->setSourceModel (
163
- $ this ->productHelper ->getAttributeSourceModelByInputType ($ attribute ->getFrontendInput ())
164
- );
165
- $ attribute ->setBackendModel (
166
- $ this ->productHelper ->getAttributeBackendModelByInputType ($ attribute ->getFrontendInput ())
167
- );
162
+ $ this ->processAttributeData ($ attribute );
168
163
$ attribute ->setEntityTypeId (
169
164
$ this ->eavConfig
170
165
->getEntityType (\Magento \Catalog \Api \Data \ProductAttributeInterface::ENTITY_TYPE_CODE )
@@ -275,4 +270,23 @@ protected function validateFrontendInput($frontendInput)
275
270
throw InputException::invalidFieldValue ('frontend_input ' , $ frontendInput );
276
271
}
277
272
}
273
+
274
+ /**
275
+ * Process attribute data based on attribute frontend input type.
276
+ *
277
+ * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
278
+ * @return void
279
+ */
280
+ private function processAttributeData (\Magento \Catalog \Api \Data \ProductAttributeInterface $ attribute )
281
+ {
282
+ $ attribute ->setBackendType (
283
+ $ attribute ->getBackendTypeByInput ($ attribute ->getFrontendInput ())
284
+ );
285
+ $ attribute ->setSourceModel (
286
+ $ this ->productHelper ->getAttributeSourceModelByInputType ($ attribute ->getFrontendInput ())
287
+ );
288
+ $ attribute ->setBackendModel (
289
+ $ this ->productHelper ->getAttributeBackendModelByInputType ($ attribute ->getFrontendInput ())
290
+ );
291
+ }
278
292
}
0 commit comments