Skip to content

Commit 4a1f3ab

Browse files
committed
Renamed options and groups properties. PHPUnit changed Option object creation by adding option groups. (#24726)
1 parent de97b0a commit 4a1f3ab

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Magento\Catalog\Api\Data\ProductCustomOptionValuesInterfaceFactory;
1212
use Magento\Catalog\Api\Data\ProductInterface;
1313
use Magento\Catalog\Model\Product;
14-
use Magento\Catalog\Model\Product\Option\Type\DefaultType;
1514
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
1615
use Magento\Catalog\Pricing\Price\BasePrice;
16+
use Magento\Framework\DataObject;
1717
use Magento\Framework\EntityManager\MetadataPool;
1818
use Magento\Framework\Exception\LocalizedException;
1919
use Magento\Framework\Model\AbstractExtensibleModel;
@@ -100,14 +100,14 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
100100
protected $validatorPool;
101101

102102
/**
103-
* @var DefaultType[]
103+
* @var string[]
104104
*/
105-
private $groupsPool;
105+
private $optionGroups;
106106

107107
/**
108108
* @var string[]
109109
*/
110-
private $typesPool;
110+
private $optionGroupsToTypes;
111111

112112
/**
113113
* @var MetadataPool
@@ -131,8 +131,8 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
131131
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
132132
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
133133
* @param array $data
134-
* @param array $groupsPool
135-
* @param array $typesPool
134+
* @param array $optionGroups
135+
* @param array $optionGroupsToTypes
136136
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
137137
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
138138
*/
@@ -148,18 +148,18 @@ public function __construct(
148148
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
149149
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
150150
array $data = [],
151-
array $groupsPool = [],
152-
array $typesPool = [],
153-
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null
151+
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
152+
array $optionGroups = [],
153+
array $optionGroupsToTypes = []
154154
) {
155155
$this->productOptionValue = $productOptionValue;
156156
$this->optionTypeFactory = $optionFactory;
157157
$this->string = $string;
158158
$this->validatorPool = $validatorPool;
159-
$this->groupsPool = $groupsPool;
160-
$this->typesPool = $typesPool;
161159
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
162160
\Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
161+
$this->optionGroups = $optionGroups;
162+
$this->optionGroupsToTypes = $optionGroupsToTypes;
163163

164164
parent::__construct(
165165
$context,
@@ -332,21 +332,21 @@ public function getGroupByType($type = null): string
332332
$type = $this->getType();
333333
}
334334

335-
return $this->typesPool[$type] ?? '';
335+
return $this->optionGroupsToTypes[$type] ?? '';
336336
}
337337

338338
/**
339339
* Group model factory
340340
*
341341
* @param string $type Option type
342-
* @return DefaultType
342+
* @return DataObject
343343
* @throws LocalizedException
344344
*/
345-
public function groupFactory($type): DefaultType
345+
public function groupFactory($type)
346346
{
347347
$group = $this->getGroupByType($type);
348-
if (!empty($group) && isset($this->groupsPool[$group])) {
349-
return $this->optionTypeFactory->create($this->groupsPool[$group]);
348+
if (!empty($group) && isset($this->optionGroups[$group])) {
349+
return $this->optionTypeFactory->create($this->optionGroups[$group]);
350350
}
351351
throw new LocalizedException(__('The option type to get group instance is incorrect.'));
352352
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ protected function setUp()
2424
{
2525
$this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
2626
$objectManager = new ObjectManager($this);
27-
$this->model = $objectManager->getObject(\Magento\Catalog\Model\Product\Option::class);
27+
$this->model = $objectManager->getObject(
28+
\Magento\Catalog\Model\Product\Option::class,
29+
[
30+
'optionGroupsToTypes' => [
31+
'field' => 'text',
32+
'drop_down' => 'select',
33+
'file' => 'file',
34+
]
35+
]
36+
);
2837
$this->model->setProduct($this->productMock);
2938
}
3039

app/code/Magento/Catalog/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,13 @@
412412
</type>
413413
<type name="Magento\Catalog\Model\Product\Option">
414414
<arguments>
415-
<argument name="groupsPool" xsi:type="array">
415+
<argument name="optionGroups" xsi:type="array">
416416
<item name="date" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Date</item>
417417
<item name="file" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\File</item>
418418
<item name="select" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Select</item>
419419
<item name="text" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Text</item>
420420
</argument>
421-
<argument name="typesPool" xsi:type="array">
421+
<argument name="optionGroupsToTypes" xsi:type="array">
422422
<item name="field" xsi:type="string">text</item>
423423
<item name="area" xsi:type="string">text</item>
424424
<item name="file" xsi:type="string">file</item>

0 commit comments

Comments
 (0)