Skip to content

Commit 1042cb2

Browse files
Navarr BarnierNavarr Barnier
authored andcommitted
Update the Product Option model and Block to utilize a hasValues() method 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.
1 parent 2c22ac4 commit 1042cb2

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function getJsonConfig()
208208
$config = [];
209209
foreach ($this->getOptions() as $option) {
210210
/* @var $option \Magento\Catalog\Model\Product\Option */
211-
if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) {
211+
if ($option->hasValues()) {
212212
$tmpPriceValues = [];
213213
foreach ($option->getValues() as $valueId => $value) {
214214
$tmpPriceValues[$valueId] = $this->_getPriceConfiguration($value);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,17 @@ public function getValueById($valueId)
218218
return null;
219219
}
220220

221+
/**
222+
* Whether or not the option type contains sub-values
223+
*
224+
* @param string $type
225+
* @return bool
226+
*/
227+
public function hasValues($type = null)
228+
{
229+
return $this->getGroupByType($type) == self::OPTION_GROUP_SELECT;
230+
}
231+
221232
/**
222233
* @return ProductCustomOptionValuesInterface[]|null
223234
*/

app/code/Magento/Catalog/Test/Unit/Model/Product/OptionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function testGetProductSku()
3535
$this->assertEquals($productSku, $this->model->getProductSku());
3636
}
3737

38+
public function testHasValues()
39+
{
40+
$this->model->setType('drop_down');
41+
$this->assertTrue($this->model->hasValues());
42+
43+
$this->model->setType('field');
44+
$this->assertFalse($this->model->hasValues());
45+
}
46+
3847
public function testGetRegularPrice()
3948
{
4049
$priceInfoMock = $this->getMockForAbstractClass(

0 commit comments

Comments
 (0)