File tree Expand file tree Collapse file tree 2 files changed +18
-18
lines changed
app/code/Magento/Bundle/Model Expand file tree Collapse file tree 2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -201,10 +201,10 @@ public function save(
201
201
202
202
/** @var \Magento\Bundle\Model\Option $existingOption */
203
203
$ existingOption = $ optionCollection ->getFirstItem ();
204
- if (!$ optionId ) {
205
- $ option ->setOptionId (null );
206
- }
207
204
if (!$ optionId || $ existingOption ->getParentId () != $ parentId ) {
205
+ //If option ID is empty or existing option's parent ID is different
206
+ //we'd need a new ID for the option.
207
+ $ option ->setOptionId (null );
208
208
$ option ->setDefaultTitle ($ option ->getTitle ());
209
209
if (is_array ($ option ->getProductLinks ())) {
210
210
$ linksToAdd = $ option ->getProductLinks ();
Original file line number Diff line number Diff line change @@ -65,22 +65,22 @@ public function execute($entity, $arguments = [])
65
65
}
66
66
67
67
if (!$ entity ->getCopyFromView ()) {
68
- $ updatedOptions = [];
69
68
$ oldOptions = $ this ->optionRepository ->getList ($ entity ->getSku ());
70
-
71
- $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
72
-
73
- $ productId = $ entity ->getData ($ metadata ->getLinkField ());
74
-
75
- foreach ($ options as $ option ) {
76
- $ updatedOptions [$ option ->getOptionId ()][$ productId ] = (bool )$ option ->getOptionId ();
77
- }
78
-
79
- foreach ($ oldOptions as $ option ) {
80
- if (!isset ($ updatedOptions [$ option ->getOptionId ()][$ productId ])) {
81
- $ option ->setParentId ($ productId );
82
- $ this ->removeOptionLinks ($ entity ->getSku (), $ option );
83
- $ this ->optionRepository ->delete ($ option );
69
+ if ($ oldOptions ) {
70
+ $ remainingOptions = [];
71
+ $ metadata
72
+ = $ this ->metadataPool ->getMetadata (ProductInterface::class);
73
+ $ productId = $ entity ->getData ($ metadata ->getLinkField ());
74
+
75
+ foreach ($ options as $ option ) {
76
+ $ remainingOptions [] = $ option ->getOptionId ();
77
+ }
78
+ foreach ($ oldOptions as $ option ) {
79
+ if (!in_array ($ option ->getOptionId (), $ remainingOptions )) {
80
+ $ option ->setParentId ($ productId );
81
+ $ this ->removeOptionLinks ($ entity ->getSku (), $ option );
82
+ $ this ->optionRepository ->delete ($ option );
83
+ }
84
84
}
85
85
}
86
86
}
You can’t perform that action at this time.
0 commit comments