4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- // @codingStandardsIgnoreFile
8
7
9
8
namespace Magento \Catalog \Model \Product ;
10
9
10
+ use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
11
11
use Magento \Catalog \Api \Data \ProductCustomOptionValuesInterface ;
12
12
use Magento \Catalog \Model \Product ;
13
13
use Magento \Catalog \Model \ResourceModel \Product \Option \Value \Collection ;
14
14
use Magento \Catalog \Pricing \Price \BasePrice ;
15
15
use Magento \Framework \Exception \LocalizedException ;
16
+ use Magento \Framework \Model \AbstractExtensibleModel ;
16
17
17
18
/**
18
19
* Catalog product option model
25
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
27
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
27
28
*/
28
- class Option extends \Magento \Framework \Model \AbstractExtensibleModel
29
- implements \Magento \Catalog \Api \Data \ProductCustomOptionInterface
29
+ class Option extends AbstractExtensibleModel implements ProductCustomOptionInterface
30
30
{
31
31
const OPTION_GROUP_TEXT = 'text ' ;
32
32
@@ -77,31 +77,31 @@ class Option extends \Magento\Framework\Model\AbstractExtensibleModel
77
77
/**
78
78
* @var Product
79
79
*/
80
- protected $ _product ;
80
+ protected $ product ;
81
81
82
82
/**
83
83
* @var array
84
84
*/
85
- protected $ _options = [];
85
+ protected $ options = [];
86
86
87
87
/**
88
88
* @var array
89
89
*/
90
- protected $ _values = null ;
90
+ protected $ values = null ;
91
91
92
92
/**
93
93
* Catalog product option value
94
94
*
95
95
* @var Option\Value
96
96
*/
97
- protected $ _productOptionValue ;
97
+ protected $ productOptionValue ;
98
98
99
99
/**
100
100
* Product option factory
101
101
*
102
102
* @var \Magento\Catalog\Model\Product\Option\Type\Factory
103
103
*/
104
- protected $ _optionFactory ;
104
+ protected $ optionTypeFactory ;
105
105
106
106
/**
107
107
* @var \Magento\Framework\Stdlib\StringUtils
@@ -140,8 +140,8 @@ public function __construct(
140
140
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
141
141
array $ data = []
142
142
) {
143
- $ this ->_productOptionValue = $ productOptionValue ;
144
- $ this ->_optionFactory = $ optionFactory ;
143
+ $ this ->productOptionValue = $ productOptionValue ;
144
+ $ this ->optionTypeFactory = $ optionFactory ;
145
145
$ this ->validatorPool = $ validatorPool ;
146
146
$ this ->string = $ string ;
147
147
parent ::__construct (
@@ -182,7 +182,7 @@ protected function _construct()
182
182
*/
183
183
public function addValue (Option \Value $ value )
184
184
{
185
- $ this ->_values [$ value ->getId ()] = $ value ;
185
+ $ this ->values [$ value ->getId ()] = $ value ;
186
186
return $ this ;
187
187
}
188
188
@@ -194,8 +194,8 @@ public function addValue(Option\Value $value)
194
194
*/
195
195
public function getValueById ($ valueId )
196
196
{
197
- if (isset ($ this ->_values [$ valueId ])) {
198
- return $ this ->_values [$ valueId ];
197
+ if (isset ($ this ->values [$ valueId ])) {
198
+ return $ this ->values [$ valueId ];
199
199
}
200
200
201
201
return null ;
@@ -206,7 +206,7 @@ public function getValueById($valueId)
206
206
*/
207
207
public function getValues ()
208
208
{
209
- return $ this ->_values ;
209
+ return $ this ->values ;
210
210
}
211
211
212
212
/**
@@ -216,7 +216,7 @@ public function getValues()
216
216
*/
217
217
public function getValueInstance ()
218
218
{
219
- return $ this ->_productOptionValue ;
219
+ return $ this ->productOptionValue ;
220
220
}
221
221
222
222
/**
@@ -227,7 +227,7 @@ public function getValueInstance()
227
227
*/
228
228
public function addOption ($ option )
229
229
{
230
- $ this ->_options [] = $ option ;
230
+ $ this ->options [] = $ option ;
231
231
return $ this ;
232
232
}
233
233
@@ -238,7 +238,7 @@ public function addOption($option)
238
238
*/
239
239
public function getOptions ()
240
240
{
241
- return $ this ->_options ;
241
+ return $ this ->options ;
242
242
}
243
243
244
244
/**
@@ -249,7 +249,7 @@ public function getOptions()
249
249
*/
250
250
public function setOptions ($ options )
251
251
{
252
- $ this ->_options = $ options ;
252
+ $ this ->options = $ options ;
253
253
return $ this ;
254
254
}
255
255
@@ -260,7 +260,7 @@ public function setOptions($options)
260
260
*/
261
261
public function unsetOptions ()
262
262
{
263
- $ this ->_options = [];
263
+ $ this ->options = [];
264
264
return $ this ;
265
265
}
266
266
@@ -271,7 +271,7 @@ public function unsetOptions()
271
271
*/
272
272
public function getProduct ()
273
273
{
274
- return $ this ->_product ;
274
+ return $ this ->product ;
275
275
}
276
276
277
277
/**
@@ -282,7 +282,7 @@ public function getProduct()
282
282
*/
283
283
public function setProduct (Product $ product = null )
284
284
{
285
- $ this ->_product = $ product ;
285
+ $ this ->product = $ product ;
286
286
return $ this ;
287
287
}
288
288
@@ -294,7 +294,7 @@ public function setProduct(Product $product = null)
294
294
*/
295
295
public function getGroupByType ($ type = null )
296
296
{
297
- if (is_null ( $ type) ) {
297
+ if ($ type === null ) {
298
298
$ type = $ this ->getType ();
299
299
}
300
300
$ optionGroupsToTypes = [
@@ -324,7 +324,7 @@ public function groupFactory($type)
324
324
{
325
325
$ group = $ this ->getGroupByType ($ type );
326
326
if (!empty ($ group )) {
327
- return $ this ->_optionFactory ->create (
327
+ return $ this ->optionTypeFactory ->create (
328
328
'Magento\Catalog\Model\Product\Option\Type \\' . $ this ->string ->upperCaseWords ($ group )
329
329
);
330
330
}
@@ -451,24 +451,24 @@ public function getPrice($flag = false)
451
451
/**
452
452
* Delete prices of option
453
453
*
454
- * @param int $option_id
454
+ * @param int $optionId
455
455
* @return $this
456
456
*/
457
- public function deletePrices ($ option_id )
457
+ public function deletePrices ($ optionId )
458
458
{
459
- $ this ->getResource ()->deletePrices ($ option_id );
459
+ $ this ->getResource ()->deletePrices ($ optionId );
460
460
return $ this ;
461
461
}
462
462
463
463
/**
464
464
* Delete titles of option
465
465
*
466
- * @param int $option_id
466
+ * @param int $optionId
467
467
* @return $this
468
468
*/
469
- public function deleteTitles ($ option_id )
469
+ public function deleteTitles ($ optionId )
470
470
{
471
- $ this ->getResource ()->deleteTitles ($ option_id );
471
+ $ this ->getResource ()->deleteTitles ($ optionId );
472
472
return $ this ;
473
473
}
474
474
@@ -480,7 +480,8 @@ public function deleteTitles($option_id)
480
480
*/
481
481
public function getProductOptionCollection (Product $ product )
482
482
{
483
- $ collection = $ this ->getCollection ()->addFieldToFilter (
483
+ $ collection = clone $ this ->getCollection ();
484
+ $ collection ->addFieldToFilter (
484
485
'product_id ' ,
485
486
$ product ->getId ()
486
487
)->addTitleToResult (
@@ -519,12 +520,12 @@ public function getValuesCollection()
519
520
* Get collection of values by given option ids
520
521
*
521
522
* @param array $optionIds
522
- * @param int $store_id
523
+ * @param int $storeId
523
524
* @return Collection
524
525
*/
525
- public function getOptionValuesByOptionId ($ optionIds , $ store_id )
526
+ public function getOptionValuesByOptionId ($ optionIds , $ storeId )
526
527
{
527
- $ collection = $ this ->_productOptionValue ->getValuesByOption ($ optionIds , $ this ->getId (), $ store_id );
528
+ $ collection = $ this ->productOptionValue ->getValuesByOption ($ optionIds , $ this ->getId (), $ storeId );
528
529
529
530
return $ collection ;
530
531
}
@@ -563,7 +564,7 @@ public function getSearchableData($productId, $storeId)
563
564
protected function _clearData ()
564
565
{
565
566
$ this ->_data = [];
566
- $ this ->_values = null ;
567
+ $ this ->values = null ;
567
568
return $ this ;
568
569
}
569
570
@@ -574,8 +575,8 @@ protected function _clearData()
574
575
*/
575
576
protected function _clearReferences ()
576
577
{
577
- if (!empty ($ this ->_values )) {
578
- foreach ($ this ->_values as $ value ) {
578
+ if (!empty ($ this ->values )) {
579
+ foreach ($ this ->values as $ value ) {
579
580
$ value ->unsetOption ();
580
581
}
581
582
}
@@ -848,7 +849,7 @@ public function setImageSizeY($imageSizeY)
848
849
*/
849
850
public function setValues (array $ values = null )
850
851
{
851
- $ this ->_values = $ values ;
852
+ $ this ->values = $ values ;
852
853
return $ this ;
853
854
}
854
855
0 commit comments