Skip to content

Commit 0279756

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-40789' into BugFestW4
2 parents 5693507 + 7225801 commit 0279756

File tree

10 files changed

+257
-58
lines changed

10 files changed

+257
-58
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public function getJsonConfig()
219219
/* @var $product \Magento\Catalog\Model\Product */
220220
$product = $this->getProduct();
221221

222-
$config = [];
223222
if (!$this->hasOptions()) {
224223
$config = [
225224
'productId' => $product->getId(),

app/code/Magento/Catalog/Block/Product/View/Options.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function _getPriceConfiguration($option)
162162
$data = [
163163
'prices' => [
164164
'oldPrice' => [
165-
'amount' => $this->pricingHelper->currency($option->getPrice(false), false, false),
165+
'amount' => $this->pricingHelper->currency($option->getRegularPrice(), false, false),
166166
'adjustments' => [],
167167
],
168168
'basePrice' => [
@@ -208,7 +208,6 @@ public function getJsonConfig()
208208
$config = [];
209209
foreach ($this->getOptions() as $option) {
210210
/* @var $option \Magento\Catalog\Model\Product\Option */
211-
$priceValue = 0;
212211
if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) {
213212
$tmpPriceValues = [];
214213
foreach ($option->getValues() as $value) {

app/code/Magento/Catalog/Model/Product.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,19 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
117117
*/
118118
protected $_errors = [];
119119

120+
/**
121+
* Product option factory
122+
*
123+
* @var Product\OptionFactory
124+
*/
125+
protected $optionFactory;
126+
120127
/**
121128
* Product option
122129
*
123130
* @var Product\Option
124131
*/
125-
protected $_optionInstance;
132+
protected $optionInstance;
126133

127134
/**
128135
* @var array
@@ -337,7 +344,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
337344
* @param Product\Link $productLink
338345
* @param Product\Configuration\Item\OptionFactory $itemOptionFactory
339346
* @param \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory
340-
* @param Product\Option $catalogProductOption
347+
* @param Product\OptionFactory $catalogProductOptionFactory
341348
* @param Product\Visibility $catalogProductVisibility
342349
* @param Product\Attribute\Source\Status $catalogProductStatus
343350
* @param Product\Media\Config $catalogProductMediaConfig
@@ -376,7 +383,7 @@ public function __construct(
376383
Product\Link $productLink,
377384
\Magento\Catalog\Model\Product\Configuration\Item\OptionFactory $itemOptionFactory,
378385
\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory,
379-
\Magento\Catalog\Model\Product\Option $catalogProductOption,
386+
\Magento\Catalog\Model\Product\OptionFactory $catalogProductOptionFactory,
380387
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
381388
\Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus,
382389
\Magento\Catalog\Model\Product\Media\Config $catalogProductMediaConfig,
@@ -405,7 +412,7 @@ public function __construct(
405412
$this->metadataService = $metadataService;
406413
$this->_itemOptionFactory = $itemOptionFactory;
407414
$this->_stockItemFactory = $stockItemFactory;
408-
$this->_optionInstance = $catalogProductOption;
415+
$this->optionFactory = $catalogProductOptionFactory;
409416
$this->_catalogProductVisibility = $catalogProductVisibility;
410417
$this->_catalogProductStatus = $catalogProductStatus;
411418
$this->_catalogProductMediaConfig = $catalogProductMediaConfig;
@@ -1889,7 +1896,11 @@ public function getWeight()
18891896
*/
18901897
public function getOptionInstance()
18911898
{
1892-
return $this->_optionInstance;
1899+
if (!isset($this->optionInstance)) {
1900+
$this->optionInstance = $this->optionFactory->create();
1901+
$this->optionInstance->setProduct($this);
1902+
}
1903+
return $this->optionInstance;
18931904
}
18941905

18951906
/**

app/code/Magento/Catalog/Model/Product/Option.php

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
87

98
namespace Magento\Catalog\Model\Product;
109

10+
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
1111
use Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface;
1212
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
1414
use Magento\Catalog\Pricing\Price\BasePrice;
1515
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Model\AbstractExtensibleModel;
1617

1718
/**
1819
* Catalog product option model
@@ -25,8 +26,7 @@
2526
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2627
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
2728
*/
28-
class Option extends \Magento\Framework\Model\AbstractExtensibleModel
29-
implements \Magento\Catalog\Api\Data\ProductCustomOptionInterface
29+
class Option extends AbstractExtensibleModel implements ProductCustomOptionInterface
3030
{
3131
const OPTION_GROUP_TEXT = 'text';
3232

@@ -77,31 +77,31 @@ class Option extends \Magento\Framework\Model\AbstractExtensibleModel
7777
/**
7878
* @var Product
7979
*/
80-
protected $_product;
80+
protected $product;
8181

8282
/**
8383
* @var array
8484
*/
85-
protected $_options = [];
85+
protected $options = [];
8686

8787
/**
8888
* @var array
8989
*/
90-
protected $_values = null;
90+
protected $values = null;
9191

9292
/**
9393
* Catalog product option value
9494
*
9595
* @var Option\Value
9696
*/
97-
protected $_productOptionValue;
97+
protected $productOptionValue;
9898

9999
/**
100100
* Product option factory
101101
*
102102
* @var \Magento\Catalog\Model\Product\Option\Type\Factory
103103
*/
104-
protected $_optionFactory;
104+
protected $optionTypeFactory;
105105

106106
/**
107107
* @var \Magento\Framework\Stdlib\StringUtils
@@ -140,8 +140,8 @@ public function __construct(
140140
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
141141
array $data = []
142142
) {
143-
$this->_productOptionValue = $productOptionValue;
144-
$this->_optionFactory = $optionFactory;
143+
$this->productOptionValue = $productOptionValue;
144+
$this->optionTypeFactory = $optionFactory;
145145
$this->validatorPool = $validatorPool;
146146
$this->string = $string;
147147
parent::__construct(
@@ -182,7 +182,7 @@ protected function _construct()
182182
*/
183183
public function addValue(Option\Value $value)
184184
{
185-
$this->_values[$value->getId()] = $value;
185+
$this->values[$value->getId()] = $value;
186186
return $this;
187187
}
188188

@@ -194,8 +194,8 @@ public function addValue(Option\Value $value)
194194
*/
195195
public function getValueById($valueId)
196196
{
197-
if (isset($this->_values[$valueId])) {
198-
return $this->_values[$valueId];
197+
if (isset($this->values[$valueId])) {
198+
return $this->values[$valueId];
199199
}
200200

201201
return null;
@@ -206,7 +206,7 @@ public function getValueById($valueId)
206206
*/
207207
public function getValues()
208208
{
209-
return $this->_values;
209+
return $this->values;
210210
}
211211

212212
/**
@@ -216,7 +216,7 @@ public function getValues()
216216
*/
217217
public function getValueInstance()
218218
{
219-
return $this->_productOptionValue;
219+
return $this->productOptionValue;
220220
}
221221

222222
/**
@@ -227,7 +227,7 @@ public function getValueInstance()
227227
*/
228228
public function addOption($option)
229229
{
230-
$this->_options[] = $option;
230+
$this->options[] = $option;
231231
return $this;
232232
}
233233

@@ -238,7 +238,7 @@ public function addOption($option)
238238
*/
239239
public function getOptions()
240240
{
241-
return $this->_options;
241+
return $this->options;
242242
}
243243

244244
/**
@@ -249,7 +249,7 @@ public function getOptions()
249249
*/
250250
public function setOptions($options)
251251
{
252-
$this->_options = $options;
252+
$this->options = $options;
253253
return $this;
254254
}
255255

@@ -260,7 +260,7 @@ public function setOptions($options)
260260
*/
261261
public function unsetOptions()
262262
{
263-
$this->_options = [];
263+
$this->options = [];
264264
return $this;
265265
}
266266

@@ -271,7 +271,7 @@ public function unsetOptions()
271271
*/
272272
public function getProduct()
273273
{
274-
return $this->_product;
274+
return $this->product;
275275
}
276276

277277
/**
@@ -282,7 +282,7 @@ public function getProduct()
282282
*/
283283
public function setProduct(Product $product = null)
284284
{
285-
$this->_product = $product;
285+
$this->product = $product;
286286
return $this;
287287
}
288288

@@ -294,7 +294,7 @@ public function setProduct(Product $product = null)
294294
*/
295295
public function getGroupByType($type = null)
296296
{
297-
if (is_null($type)) {
297+
if ($type === null) {
298298
$type = $this->getType();
299299
}
300300
$optionGroupsToTypes = [
@@ -324,7 +324,7 @@ public function groupFactory($type)
324324
{
325325
$group = $this->getGroupByType($type);
326326
if (!empty($group)) {
327-
return $this->_optionFactory->create(
327+
return $this->optionTypeFactory->create(
328328
'Magento\Catalog\Model\Product\Option\Type\\' . $this->string->upperCaseWords($group)
329329
);
330330
}
@@ -451,24 +451,24 @@ public function getPrice($flag = false)
451451
/**
452452
* Delete prices of option
453453
*
454-
* @param int $option_id
454+
* @param int $optionId
455455
* @return $this
456456
*/
457-
public function deletePrices($option_id)
457+
public function deletePrices($optionId)
458458
{
459-
$this->getResource()->deletePrices($option_id);
459+
$this->getResource()->deletePrices($optionId);
460460
return $this;
461461
}
462462

463463
/**
464464
* Delete titles of option
465465
*
466-
* @param int $option_id
466+
* @param int $optionId
467467
* @return $this
468468
*/
469-
public function deleteTitles($option_id)
469+
public function deleteTitles($optionId)
470470
{
471-
$this->getResource()->deleteTitles($option_id);
471+
$this->getResource()->deleteTitles($optionId);
472472
return $this;
473473
}
474474

@@ -480,7 +480,8 @@ public function deleteTitles($option_id)
480480
*/
481481
public function getProductOptionCollection(Product $product)
482482
{
483-
$collection = $this->getCollection()->addFieldToFilter(
483+
$collection = clone $this->getCollection();
484+
$collection->addFieldToFilter(
484485
'product_id',
485486
$product->getId()
486487
)->addTitleToResult(
@@ -519,12 +520,12 @@ public function getValuesCollection()
519520
* Get collection of values by given option ids
520521
*
521522
* @param array $optionIds
522-
* @param int $store_id
523+
* @param int $storeId
523524
* @return Collection
524525
*/
525-
public function getOptionValuesByOptionId($optionIds, $store_id)
526+
public function getOptionValuesByOptionId($optionIds, $storeId)
526527
{
527-
$collection = $this->_productOptionValue->getValuesByOption($optionIds, $this->getId(), $store_id);
528+
$collection = $this->productOptionValue->getValuesByOption($optionIds, $this->getId(), $storeId);
528529

529530
return $collection;
530531
}
@@ -563,7 +564,7 @@ public function getSearchableData($productId, $storeId)
563564
protected function _clearData()
564565
{
565566
$this->_data = [];
566-
$this->_values = null;
567+
$this->values = null;
567568
return $this;
568569
}
569570

@@ -574,8 +575,8 @@ protected function _clearData()
574575
*/
575576
protected function _clearReferences()
576577
{
577-
if (!empty($this->_values)) {
578-
foreach ($this->_values as $value) {
578+
if (!empty($this->values)) {
579+
foreach ($this->values as $value) {
579580
$value->unsetOption();
580581
}
581582
}
@@ -848,7 +849,7 @@ public function setImageSizeY($imageSizeY)
848849
*/
849850
public function setValues(array $values = null)
850851
{
851-
$this->_values = $values;
852+
$this->values = $values;
852853
return $this;
853854
}
854855

app/code/Magento/Catalog/Model/Product/Option/Value.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ public function getPrice($flag = false)
238238
return $this->_getData(self::KEY_PRICE);
239239
}
240240

241+
/**
242+
* Return regular price.
243+
*
244+
* @return float|int
245+
*/
246+
public function getRegularPrice()
247+
{
248+
if ($this->getPriceType() == self::TYPE_PERCENT) {
249+
$basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
250+
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
251+
return $price;
252+
}
253+
return $this->_getData(self::KEY_PRICE);
254+
}
255+
241256
/**
242257
* Enter description here...
243258
*

0 commit comments

Comments
 (0)