@@ -84,26 +84,6 @@ public function execute($entity, $arguments = [])
8484 return $ entity ;
8585 }
8686
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-
10787 /**
10888 * Save custom options
10989 *
@@ -115,10 +95,10 @@ private function isProductValid(ProductInterface $product): bool
11595 */
11696 private function processOptionsSaving (array $ options , bool $ hasChangedSku , ProductInterface $ product ): void
11797 {
118- $ isProductValid = $ this ->isProductValid ($ product );
98+ $ isProductHasRelations = $ this ->isProductHasRelations ($ product );
11999 /** @var ProductCustomOptionInterface $option */
120100 foreach ($ options as $ option ) {
121- if (!$ isProductValid && $ option ->getIsRequire ()) {
101+ if (!$ isProductHasRelations && $ option ->getIsRequire ()) {
122102 $ message = 'Required custom options cannot be added to a simple product '
123103 . ' that is a part of a composite product. ' ;
124104 throw new CouldNotSaveException (__ ($ message ));
@@ -130,4 +110,24 @@ private function processOptionsSaving(array $options, bool $hasChangedSku, Produ
130110 $ this ->optionRepository ->save ($ option );
131111 }
132112 }
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+ }
133133}
0 commit comments