@@ -81,28 +81,21 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
81
81
{
82
82
parent ::_afterSave ($ object );
83
83
84
- $ condition = [
84
+ $ conditions = [
85
85
'option_id = ? ' => $ object ->getId (),
86
86
'store_id = ? OR store_id = 0 ' => $ object ->getStoreId (),
87
87
'parent_product_id = ? ' => $ object ->getParentId ()
88
88
];
89
89
90
90
$ connection = $ this ->getConnection ();
91
91
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 )) {
100
93
$ connection ->update (
101
94
$ this ->getTable ('catalog_product_bundle_option_value ' ),
102
95
[
103
96
'title ' => $ object ->getTitle ()
104
97
],
105
- $ condition
98
+ $ conditions
106
99
);
107
100
} else {
108
101
$ data = new \Magento \Framework \DataObject ();
@@ -225,4 +218,26 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
225
218
226
219
return $ this ;
227
220
}
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
+ }
228
243
}
0 commit comments