@@ -81,28 +81,21 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
8181 {
8282 parent ::_afterSave ($ object );
8383
84- $ condition = [
84+ $ conditions = [
8585 'option_id = ? ' => $ object ->getId (),
8686 'store_id = ? OR store_id = 0 ' => $ object ->getStoreId (),
8787 'parent_product_id = ? ' => $ object ->getParentId ()
8888 ];
8989
9090 $ connection = $ this ->getConnection ();
9191
92- $ select = $ connection ->select ()->from ($ this ->getTable ('catalog_product_bundle_option_value ' ));
93- foreach ($ condition as $ k => $ v ) {
94- $ select ->where ($ k , $ v );
95- }
96- $ select ->limit (1 );
97-
98- $ rowSelect = $ connection ->fetchRow ($ select );
99- if (is_array ($ rowSelect )) {
92+ if ($ this ->isOptionPresent ($ conditions )) {
10093 $ connection ->update (
10194 $ this ->getTable ('catalog_product_bundle_option_value ' ),
10295 [
10396 'title ' => $ object ->getTitle ()
10497 ],
105- $ condition
98+ $ conditions
10699 );
107100 } else {
108101 $ data = new \Magento \Framework \DataObject ();
@@ -225,4 +218,26 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
225218
226219 return $ this ;
227220 }
221+
222+ /**
223+ * Is Bundle option present in the database
224+ *
225+ * @param array $conditions
226+ *
227+ * @return bool
228+ */
229+ private function isOptionPresent ($ conditions )
230+ {
231+ $ connection = $ this ->getConnection ();
232+
233+ $ select = $ connection ->select ()->from ($ this ->getTable ('catalog_product_bundle_option_value ' ));
234+ foreach ($ conditions as $ condition => $ conditionValue ) {
235+ $ select ->where ($ condition , $ conditionValue );
236+ }
237+ $ select ->limit (1 );
238+
239+ $ rowSelect = $ connection ->fetchRow ($ select );
240+
241+ return is_array ($ rowSelect );
242+ }
228243}
0 commit comments