@@ -84,26 +84,6 @@ public function execute($entity, $arguments = [])
84
84
return $ entity ;
85
85
}
86
86
87
- /**
88
- * Check if product doesn't belong to composite product
89
- *
90
- * @param ProductInterface $product
91
- * @return bool
92
- */
93
- private function isProductValid (ProductInterface $ product ): bool
94
- {
95
- $ result = true ;
96
- if ($ product ->getTypeId () !== Type::TYPE_BUNDLE
97
- && $ product ->getTypeId () !== Configurable::TYPE_CODE
98
- && $ product ->getTypeId () !== Grouped::TYPE_CODE
99
- && $ this ->relation ->getRelationsByChildren ([$ product ->getId ()])
100
- ) {
101
- $ result = false ;
102
- }
103
-
104
- return $ result ;
105
- }
106
-
107
87
/**
108
88
* Save custom options
109
89
*
@@ -115,10 +95,10 @@ private function isProductValid(ProductInterface $product): bool
115
95
*/
116
96
private function processOptionsSaving (array $ options , bool $ hasChangedSku , ProductInterface $ product ): void
117
97
{
118
- $ isProductValid = $ this ->isProductValid ($ product );
98
+ $ isProductHasRelations = $ this ->isProductHasRelations ($ product );
119
99
/** @var ProductCustomOptionInterface $option */
120
100
foreach ($ options as $ option ) {
121
- if (!$ isProductValid && $ option ->getIsRequire ()) {
101
+ if (!$ isProductHasRelations && $ option ->getIsRequire ()) {
122
102
$ message = 'Required custom options cannot be added to a simple product '
123
103
. ' that is a part of a composite product. ' ;
124
104
throw new CouldNotSaveException (__ ($ message ));
@@ -130,4 +110,24 @@ private function processOptionsSaving(array $options, bool $hasChangedSku, Produ
130
110
$ this ->optionRepository ->save ($ option );
131
111
}
132
112
}
113
+
114
+ /**
115
+ * Check if product doesn't belong to composite product
116
+ *
117
+ * @param ProductInterface $product
118
+ * @return bool
119
+ */
120
+ private function isProductHasRelations (ProductInterface $ product ): bool
121
+ {
122
+ $ result = true ;
123
+ if ($ product ->getTypeId () !== Type::TYPE_BUNDLE
124
+ && $ product ->getTypeId () !== Configurable::TYPE_CODE
125
+ && $ product ->getTypeId () !== Grouped::TYPE_CODE
126
+ && $ this ->relation ->getRelationsByChildren ([$ product ->getId ()])
127
+ ) {
128
+ $ result = false ;
129
+ }
130
+
131
+ return $ result ;
132
+ }
133
133
}
0 commit comments