6
6
namespace Magento \Catalog \Model \ResourceModel \Product ;
7
7
8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Store \Model \Store ;
9
10
10
11
/**
11
12
* Catalog product custom option resource model
@@ -106,7 +107,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
106
107
*/
107
108
108
109
if (in_array ($ object ->getType (), $ this ->getPriceTypes ())) {
109
- //save for store_id = 0
110
+ // save for store_id = 0
110
111
if (!$ object ->getData ('scope ' , 'price ' )) {
111
112
$ statement = $ connection ->select ()->from (
112
113
$ priceTable ,
@@ -116,11 +117,24 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
116
117
$ object ->getId ()
117
118
)->where (
118
119
'store_id = ? ' ,
119
- \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
120
+ Store::DEFAULT_STORE_ID
120
121
);
121
122
$ optionId = $ connection ->fetchOne ($ statement );
122
123
123
- if ($ optionId ) {
124
+ if (!$ optionId ) {
125
+ $ data = $ this ->_prepareDataForTable (
126
+ new \Magento \Framework \DataObject (
127
+ [
128
+ 'option_id ' => $ object ->getId (),
129
+ 'store_id ' => Store::DEFAULT_STORE_ID ,
130
+ 'price ' => $ object ->getPrice (),
131
+ 'price_type ' => $ object ->getPriceType (),
132
+ ]
133
+ ),
134
+ $ priceTable
135
+ );
136
+ $ connection ->insert ($ priceTable , $ data );
137
+ } elseif ((int )$ object ->getStoreId () === Store::DEFAULT_STORE_ID ) {
124
138
$ data = $ this ->_prepareDataForTable (
125
139
new \Magento \Framework \DataObject (
126
140
['price ' => $ object ->getPrice (), 'price_type ' => $ object ->getPriceType ()]
@@ -133,31 +147,18 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
133
147
$ data ,
134
148
[
135
149
'option_id = ? ' => $ object ->getId (),
136
- 'store_id = ? ' => \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
150
+ 'store_id = ? ' => Store::DEFAULT_STORE_ID
137
151
]
138
152
);
139
- } else {
140
- $ data = $ this ->_prepareDataForTable (
141
- new \Magento \Framework \DataObject (
142
- [
143
- 'option_id ' => $ object ->getId (),
144
- 'store_id ' => \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
145
- 'price ' => $ object ->getPrice (),
146
- 'price_type ' => $ object ->getPriceType (),
147
- ]
148
- ),
149
- $ priceTable
150
- );
151
- $ connection ->insert ($ priceTable , $ data );
152
153
}
153
154
}
154
155
155
156
$ scope = (int )$ this ->_config ->getValue (
156
- \ Magento \ Store \ Model \ Store::XML_PATH_PRICE_SCOPE ,
157
+ Store::XML_PATH_PRICE_SCOPE ,
157
158
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
158
159
);
159
160
160
- if ($ object ->getStoreId () != '0 ' && $ scope == \ Magento \ Store \ Model \ Store::PRICE_SCOPE_WEBSITE ) {
161
+ if ($ object ->getStoreId () != '0 ' && $ scope == Store::PRICE_SCOPE_WEBSITE ) {
161
162
$ baseCurrency = $ this ->_config ->getValue (
162
163
\Magento \Directory \Model \Currency::XML_PATH_CURRENCY_BASE ,
163
164
'default '
@@ -216,7 +217,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
216
217
}
217
218
}
218
219
}
219
- } elseif ($ scope == \ Magento \ Store \ Model \ Store::PRICE_SCOPE_WEBSITE && $ object ->getData ('scope ' , 'price ' )
220
+ } elseif ($ scope == Store::PRICE_SCOPE_WEBSITE && $ object ->getData ('scope ' , 'price ' )
220
221
) {
221
222
$ connection ->delete (
222
223
$ priceTable ,
@@ -239,20 +240,20 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
239
240
{
240
241
$ connection = $ this ->getConnection ();
241
242
$ titleTableName = $ this ->getTable ('catalog_product_option_title ' );
242
- foreach ([\ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID , $ object ->getStoreId ()] as $ storeId ) {
243
+ foreach ([Store::DEFAULT_STORE_ID , $ object ->getStoreId ()] as $ storeId ) {
243
244
$ existInCurrentStore = $ this ->getColFromOptionTable ($ titleTableName , (int )$ object ->getId (), (int )$ storeId );
244
- $ existInDefaultStore = (int )$ storeId == \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ?
245
+ $ existInDefaultStore = (int )$ storeId == Store::DEFAULT_STORE_ID ?
245
246
$ existInCurrentStore :
246
247
$ this ->getColFromOptionTable (
247
248
$ titleTableName ,
248
249
(int )$ object ->getId (),
249
- \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
250
+ Store::DEFAULT_STORE_ID
250
251
);
251
252
252
253
if ($ object ->getTitle ()) {
253
254
$ isDeleteStoreTitle = (bool )$ object ->getData ('is_delete_store_title ' );
254
255
if ($ existInCurrentStore ) {
255
- if ($ isDeleteStoreTitle && (int )$ storeId != \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ) {
256
+ if ($ isDeleteStoreTitle && (int )$ storeId != Store::DEFAULT_STORE_ID ) {
256
257
$ connection ->delete ($ titleTableName , ['option_title_id = ? ' => $ existInCurrentStore ]);
257
258
} elseif ($ object ->getStoreId () == $ storeId ) {
258
259
$ data = $ this ->_prepareDataForTable (
@@ -270,9 +271,9 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
270
271
}
271
272
} else {
272
273
// we should insert record into not default store only of if it does not exist in default store
273
- if (($ storeId == \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID && !$ existInDefaultStore ) ||
274
+ if (($ storeId == Store::DEFAULT_STORE_ID && !$ existInDefaultStore ) ||
274
275
(
275
- $ storeId != \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID &&
276
+ $ storeId != Store::DEFAULT_STORE_ID &&
276
277
!$ existInCurrentStore &&
277
278
!$ isDeleteStoreTitle
278
279
)
@@ -291,7 +292,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
291
292
}
292
293
}
293
294
} else {
294
- if ($ object ->getId () && $ object ->getStoreId () > \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
295
+ if ($ object ->getId () && $ object ->getStoreId () > Store::DEFAULT_STORE_ID
295
296
&& $ storeId
296
297
) {
297
298
$ connection ->delete (
@@ -470,7 +471,7 @@ public function getSearchableData($productId, $storeId)
470
471
'option_title_default.option_id=product_option.option_id ' ,
471
472
$ connection ->quoteInto (
472
473
'option_title_default.store_id = ? ' ,
473
- \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
474
+ Store::DEFAULT_STORE_ID
474
475
)
475
476
]
476
477
);
@@ -517,7 +518,7 @@ public function getSearchableData($productId, $storeId)
517
518
'option_title_default.option_type_id=option_type.option_type_id ' ,
518
519
$ connection ->quoteInto (
519
520
'option_title_default.store_id = ? ' ,
520
- \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
521
+ Store::DEFAULT_STORE_ID
521
522
)
522
523
]
523
524
);
0 commit comments