Skip to content

Commit 8e28ce0

Browse files
committed
MAGETWO-35264: Unable to request Soap service without plugging in CustomAttributeMap config
- Fixed WSDL generation to use EavCustomAttributeLocator to list all DataInterface classes for complex custom attribute type
1 parent 03239e8 commit 8e28ce0

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

app/code/Magento/Eav/Model/EavCustomAttributeTypeLocator.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,22 @@ public function getType($attributeCode, $serviceClass)
6969

7070
return $dataInterface;
7171
}
72+
73+
/**
74+
* {@inheritdoc}
75+
*/
76+
public function getAllServiceDataInterface()
77+
{
78+
$dataInterfaceArray = [];
79+
if (!$this->serviceBackendModelDataInterfaceMap) {
80+
return [];
81+
} else {
82+
foreach ($this->serviceBackendModelDataInterfaceMap as $serviceArray) {
83+
foreach ($serviceArray as $backendModel => $dataInterface) {
84+
$dataInterfaceArray[] = $dataInterface;
85+
}
86+
}
87+
}
88+
return $dataInterfaceArray;
89+
}
7290
}

app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class Generator
5050
protected $storeManager;
5151

5252
/**
53-
* @var array
53+
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface
5454
*/
55-
protected $customAttributeMapArray = null;
55+
protected $customAttributeTypeLocator = null;
5656

5757
/**
5858
* Initialize dependencies.
@@ -62,22 +62,22 @@ class Generator
6262
* @param \Magento\Framework\App\Cache\Type\Webapi $cache
6363
* @param \Magento\Framework\Reflection\TypeProcessor $typeProcessor
6464
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
65-
* @param \Magento\Framework\Object $customAttributeMap
65+
* @param \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
6666
*/
6767
public function __construct(
6868
\Magento\Webapi\Model\Soap\Config $apiConfig,
6969
WsdlFactory $wsdlFactory,
7070
\Magento\Framework\App\Cache\Type\Webapi $cache,
7171
\Magento\Framework\Reflection\TypeProcessor $typeProcessor,
7272
\Magento\Store\Model\StoreManagerInterface $storeManager,
73-
\Magento\Framework\Object $customAttributeMap
73+
\Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
7474
) {
7575
$this->_apiConfig = $apiConfig;
7676
$this->_wsdlFactory = $wsdlFactory;
7777
$this->_cache = $cache;
7878
$this->_typeProcessor = $typeProcessor;
7979
$this->storeManager = $storeManager;
80-
$this->customAttributeMapArray = array_values($customAttributeMap->getData());
80+
$this->customAttributeTypeLocator = $customAttributeTypeLocator;
8181
}
8282

8383
/**
@@ -178,7 +178,7 @@ protected function _generate($requestedServices, $endPointUrl)
178178
*/
179179
protected function addCustomAttributeTypes($wsdl)
180180
{
181-
foreach ($this->customAttributeMapArray as $customAttributeClass) {
181+
foreach ($this->customAttributeTypeLocator->getAllServiceDataInterface() as $customAttributeClass) {
182182
$typeName = $this->_typeProcessor->register($customAttributeClass);
183183
$wsdl->addComplexType($typeName);
184184
}

app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase
1212
/** @var \Magento\Webapi\Model\Soap\Wsdl\Generator */
1313
protected $_wsdlGenerator;
1414

15-
/** @var \Magento\Framework\Object */
16-
protected $customAttributeMap;
15+
/**
16+
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $customAttributeTypeLocator = null;
1719

1820
/** @var \Magento\Webapi\Model\Soap\Config|\PHPUnit_Framework_MockObject_MockObject */
1921
protected $_soapConfigMock;
@@ -93,7 +95,9 @@ protected function setUp()
9395

9496
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
9597

96-
$this->customAttributeMap = $objectManager->getObject('Magento\Framework\Object');
98+
$this->customAttributeTypeLocator = $objectManager
99+
->getObject('Magento\Eav\Model\EavCustomAttributeTypeLocator');
100+
97101
$this->_wsdlGenerator = $objectManager->getObject(
98102
'Magento\Webapi\Model\Soap\Wsdl\Generator',
99103
[
@@ -102,7 +106,7 @@ protected function setUp()
102106
'cache' => $this->_cacheMock,
103107
'typeProcessor' => $this->_typeProcessor,
104108
'storeManagerMock' => $this->storeManagerMock,
105-
'customAttributeMap' => $this->customAttributeMap
109+
'customAttributeTypeLocator' => $this->customAttributeTypeLocator
106110
]
107111
);
108112

@@ -196,7 +200,7 @@ public function testHandleWithException()
196200
$this->_cacheMock,
197201
$this->_typeProcessor,
198202
$this->storeManagerMock,
199-
$this->customAttributeMap
203+
$this->customAttributeTypeLocator
200204
]
201205
)->getMock();
202206

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Webapi</argument>
2828
</arguments>
2929
</type>
30-
<type name="Magento\Webapi\Model\Soap\Wsdl\Generator">
31-
<arguments>
32-
<argument name="customAttributeMap" xsi:type="object">CustomAttributeMap</argument>
33-
</arguments>
34-
</type>
30+
<type name="Magento\Webapi\Model\Soap\Wsdl\Generator" />
3531
<type name="Magento\Integration\Model\ConfigBasedIntegrationManager">
3632
<plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" />
3733
</type>

dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@
3030
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\Resource\Item</argument>
3131
</arguments>
3232
</type>
33-
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
33+
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
3434
<arguments>
3535
<argument name="data" xsi:type="array">
3636
<item name="customAttributeDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
3737
<item name="customAttributeNestedDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
3838
</argument>
3939
</arguments>
4040
</virtualType>
41+
<type name="Magento\Eav\Model\EavCustomAttributeTypeLocator">
42+
<arguments>
43+
<argument name="serviceEntityTypeMap" xsi:type="array">
44+
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>
45+
</argument>
46+
<argument name="serviceBackendModelDataInterfaceMap" xsi:type="array">
47+
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="array">
48+
<item name="Magento\Sample\BackendType1" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
49+
<item name="Magento\Sample\BackendType2" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
50+
</item>
51+
</argument>
52+
</arguments>
53+
</type>
54+
55+
4156
</config>

lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ interface CustomAttributeTypeLocatorInterface
1919
* @return string|null
2020
*/
2121
public function getType($attributeCode, $serviceClass);
22+
23+
/**
24+
* Get list of all Data Interface corresponding to complex custom attribute types
25+
*
26+
* @return array
27+
*/
28+
public function getAllServiceDataInterface();
2229
}

0 commit comments

Comments
 (0)