Skip to content

Commit 0c03986

Browse files
author
Tulika,Eugene(etulika)
committed
Merge pull request #152 from magento-api/MAGETWO-34416-Extension-Attributes-Squash
[API] Sprint 44 - Part 2 : MAGETWO-34416 Refactor Extensible Models and Objects to use Extended Attributes
2 parents 766f060 + d33a39c commit 0c03986

File tree

325 files changed

+5525
-1552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+5525
-1552
lines changed

.php_cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
1515
->exclude('dev/tests/functional/vendor')
1616
->exclude('dev/tests/integration/tmp')
1717
->exclude('dev/tests/integration/var')
18-
->exclude('lib/internal/Apache')
1918
->exclude('lib/internal/CardinalCommerce')
2019
->exclude('lib/internal/Cm')
2120
->exclude('lib/internal/Credis')

app/code/Magento/Bundle/Api/Data/LinkInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,19 @@ public function getCanChangeQuantity();
144144
* @return $this
145145
*/
146146
public function setCanChangeQuantity($canChangeQuantity);
147+
148+
/**
149+
* Retrieve existing extension attributes object or create a new one.
150+
*
151+
* @return \Magento\Bundle\Api\Data\LinkExtensionInterface|null
152+
*/
153+
public function getExtensionAttributes();
154+
155+
/**
156+
* Set an extension attributes object.
157+
*
158+
* @param \Magento\Bundle\Api\Data\LinkExtensionInterface $extensionAttributes
159+
* @return $this
160+
*/
161+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\LinkExtensionInterface $extensionAttributes);
147162
}

app/code/Magento/Bundle/Api/Data/OptionInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,19 @@ public function getProductLinks();
113113
* @return $this
114114
*/
115115
public function setProductLinks(array $productLinks = null);
116+
117+
/**
118+
* Retrieve existing extension attributes object or create a new one.
119+
*
120+
* @return \Magento\Bundle\Api\Data\OptionExtensionInterface|null
121+
*/
122+
public function getExtensionAttributes();
123+
124+
/**
125+
* Set an extension attributes object.
126+
*
127+
* @param \Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes
128+
* @return $this
129+
*/
130+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes);
116131
}

app/code/Magento/Bundle/Api/Data/OptionTypeInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,19 @@ public function getCode();
3737
* @return $this
3838
*/
3939
public function setCode($code);
40+
41+
/**
42+
* Retrieve existing extension attributes object or create a new one.
43+
*
44+
* @return \Magento\Bundle\Api\Data\OptionTypeExtensionInterface|null
45+
*/
46+
public function getExtensionAttributes();
47+
48+
/**
49+
* Set an extension attributes object.
50+
*
51+
* @param \Magento\Bundle\Api\Data\OptionTypeExtensionInterface $extensionAttributes
52+
* @return $this
53+
*/
54+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\OptionTypeExtensionInterface $extensionAttributes);
4055
}

app/code/Magento/Bundle/Model/Link.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Bundle\Model;
88

99
/**
10+
* Class Link
1011
* @codeCoverageIgnore
1112
*/
1213
class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements
@@ -196,4 +197,25 @@ public function setCanChangeQuantity($canChangeQuantity)
196197
{
197198
return $this->setData(self::KEY_CAN_CHANGE_QUANTITY, $canChangeQuantity);
198199
}
200+
201+
/**
202+
* {@inheritdoc}
203+
*
204+
* @return \Magento\Bundle\Api\Data\LinkExtensionInterface|null
205+
*/
206+
public function getExtensionAttributes()
207+
{
208+
return $this->_getExtensionAttributes();
209+
}
210+
211+
/**
212+
* {@inheritdoc}
213+
*
214+
* @param \Magento\Bundle\Api\Data\LinkExtensionInterface $extensionAttributes
215+
* @return $this
216+
*/
217+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\LinkExtensionInterface $extensionAttributes)
218+
{
219+
return $this->_setExtensionAttributes($extensionAttributes);
220+
}
199221
}

app/code/Magento/Bundle/Model/Option.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,26 @@ public function setProductLinks(array $productLinks = null)
269269
{
270270
return $this->setData(self::KEY_PRODUCT_LINKS, $productLinks);
271271
}
272+
273+
/**
274+
* {@inheritdoc}
275+
*
276+
* @return \Magento\Bundle\Api\Data\OptionExtensionInterface|null
277+
*/
278+
public function getExtensionAttributes()
279+
{
280+
return $this->_getExtensionAttributes();
281+
}
282+
283+
/**
284+
* {@inheritdoc}
285+
*
286+
* @param \Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes
287+
* @return $this
288+
*/
289+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes)
290+
{
291+
return $this->_setExtensionAttributes($extensionAttributes);
292+
}
272293
//@codeCoverageIgnoreEnd
273294
}

app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ class BundleLoadOptions
1515
protected $productOptionList;
1616

1717
/**
18-
* @var \Magento\Framework\Api\AttributeValueFactory
18+
* @var \Magento\Catalog\Api\Data\ProductExtensionFactory
1919
*/
20-
protected $customAttributeFactory;
20+
protected $productExtensionFactory;
2121

2222
/**
2323
* @param \Magento\Bundle\Model\Product\OptionList $productOptionList
24-
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
24+
* @param \Magento\Framework\Api\AttributeDataBuilder $customAttributeBuilder
25+
* @param \Magento\Catalog\Api\Data\ProductExtensionFactory $productExtensionFactory
2526
*/
2627
public function __construct(
2728
\Magento\Bundle\Model\Product\OptionList $productOptionList,
28-
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
29+
\Magento\Catalog\Api\Data\ProductExtensionFactory $productExtensionFactory
2930
) {
3031
$this->productOptionList = $productOptionList;
31-
$this->customAttributeFactory = $customAttributeFactory;
32+
$this->productExtensionFactory = $productExtensionFactory;
3233
}
3334

3435
/**
@@ -50,11 +51,12 @@ public function aroundLoad(
5051
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
5152
return $product;
5253
}
53-
$customAttribute = $this->customAttributeFactory->create()
54-
->setAttributeCode('bundle_product_options')
55-
->setValue($this->productOptionList->getItems($product));
56-
$attributes = array_merge($product->getCustomAttributes(), ['bundle_product_options' => $customAttribute]);
57-
$product->setData('custom_attributes', $attributes);
54+
55+
$productExtension = $this->productExtensionFactory->create();
56+
$productExtension->setBundleProductOptions($this->productOptionList->getItems($product));
57+
58+
$product->setExtensionAttributes($productExtension);
59+
5860
return $product;
5961
}
6062
}

app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ public function aroundSave(
4444
return $result;
4545
}
4646

47-
/* @var \Magento\Framework\Api\AttributeValue $bundleProductOptionsAttrValue */
48-
$bundleProductOptionsAttrValue = $product->getCustomAttribute('bundle_product_options');
49-
if (is_null($bundleProductOptionsAttrValue) || !is_array($bundleProductOptionsAttrValue->getValue())) {
50-
$bundleProductOptions = [];
51-
} else {
52-
$bundleProductOptions = $bundleProductOptionsAttrValue->getValue();
53-
}
47+
/* @var \Magento\Bundle\Api\Data\OptionInterface[] $options */
48+
$bundleProductOptions = $product->getExtensionAttributes()->getBundleProductOptions();
5449

5550
if (is_array($bundleProductOptions)) {
5651
foreach ($bundleProductOptions as $option) {

app/code/Magento/Bundle/Model/Source/Option/Type.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
namespace Magento\Bundle\Model\Source\Option;
1010

1111
use Magento\Framework\Api\AttributeValueFactory;
12-
use Magento\Framework\Api\MetadataServiceInterface;
12+
use Magento\Framework\Api\ExtensionAttributesFactory;
1313

14+
/**
15+
* Class Type
16+
*
17+
*/
1418
class Type extends \Magento\Framework\Model\AbstractExtensibleModel implements
1519
\Magento\Framework\Option\ArrayInterface,
1620
\Magento\Bundle\Api\Data\OptionTypeInterface
@@ -30,7 +34,7 @@ class Type extends \Magento\Framework\Model\AbstractExtensibleModel implements
3034
/**
3135
* @param \Magento\Framework\Model\Context $context
3236
* @param \Magento\Framework\Registry $registry
33-
* @param MetadataServiceInterface $metadataService
37+
* @param ExtensionAttributesFactory $extensionFactory
3438
* @param AttributeValueFactory $customAttributeFactory
3539
* @param array $options
3640
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
@@ -40,7 +44,7 @@ class Type extends \Magento\Framework\Model\AbstractExtensibleModel implements
4044
public function __construct(
4145
\Magento\Framework\Model\Context $context,
4246
\Magento\Framework\Registry $registry,
43-
MetadataServiceInterface $metadataService,
47+
ExtensionAttributesFactory $extensionFactory,
4448
AttributeValueFactory $customAttributeFactory,
4549
array $options,
4650
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
@@ -51,7 +55,7 @@ public function __construct(
5155
parent::__construct(
5256
$context,
5357
$registry,
54-
$metadataService,
58+
$extensionFactory,
5559
$customAttributeFactory,
5660
$resource,
5761
$resourceCollection,
@@ -111,5 +115,26 @@ public function setCode($code)
111115
{
112116
return $this->setData(self::KEY_CODE, $code);
113117
}
118+
119+
/**
120+
* {@inheritdoc}
121+
*
122+
* @return \Magento\Bundle\Api\Data\OptionTypeExtensionInterface|null
123+
*/
124+
public function getExtensionAttributes()
125+
{
126+
return $this->_getExtensionAttributes();
127+
}
128+
129+
/**
130+
* {@inheritdoc}
131+
*
132+
* @param \Magento\Bundle\Api\Data\OptionTypeExtensionInterface $extensionAttributes
133+
* @return $this
134+
*/
135+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\OptionTypeExtensionInterface $extensionAttributes)
136+
{
137+
return $this->_setExtensionAttributes($extensionAttributes);
138+
}
114139
//@codeCoverageIgnoreEnd
115140
}

app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Copyright © 2015 Magento. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
8+
// @codingStandardsIgnoreFile
9+
710
namespace Magento\Bundle\Test\Unit\Model;
811

912
class OptionRepositoryTest extends \PHPUnit_Framework_TestCase
@@ -71,6 +74,7 @@ protected function setUp()
7174
$this->optionFactoryMock = $this->getMockBuilder('\Magento\Bundle\Api\Data\OptionInterfaceFactory')
7275
->disableOriginalConstructor()
7376
->setMethods(['create'])
77+
->disableOriginalConstructor()
7478
->getMock();
7579
$this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper')
7680
->disableOriginalConstructor()

0 commit comments

Comments
 (0)