Skip to content

Commit

Permalink
Update the Product Option model and Block to utilize a hasValues() me…
Browse files Browse the repository at this point in the history
…thod rather than hardcoded check for SELECT group

This is meant to be a non-breaking stop-gap measure to allow extensions and integrators to create custom customizable options without having to rewrite core Magento classes and without having to replace the Options block.
  • Loading branch information
Navarr Barnier authored and Navarr Barnier committed Sep 28, 2016
1 parent 2c22ac4 commit 1042cb2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/View/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function getJsonConfig()
$config = [];
foreach ($this->getOptions() as $option) {
/* @var $option \Magento\Catalog\Model\Product\Option */
if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) {
if ($option->hasValues()) {
$tmpPriceValues = [];
foreach ($option->getValues() as $valueId => $value) {
$tmpPriceValues[$valueId] = $this->_getPriceConfiguration($value);
Expand Down
11 changes: 11 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ public function getValueById($valueId)
return null;
}

/**
* Whether or not the option type contains sub-values
*
* @param string $type
* @return bool
*/
public function hasValues($type = null)
{
return $this->getGroupByType($type) == self::OPTION_GROUP_SELECT;
}

/**
* @return ProductCustomOptionValuesInterface[]|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function testGetProductSku()
$this->assertEquals($productSku, $this->model->getProductSku());
}

public function testHasValues()
{
$this->model->setType('drop_down');
$this->assertTrue($this->model->hasValues());

$this->model->setType('field');
$this->assertFalse($this->model->hasValues());
}

public function testGetRegularPrice()
{
$priceInfoMock = $this->getMockForAbstractClass(
Expand Down

0 comments on commit 1042cb2

Please sign in to comment.