-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
This issue is automatically created based on existing pull request: #33003: add missing PaymentMethodInterface
Description (*)
During checkout payment information details can be requested via
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/PaymentInformationManagement.php#L185
which uses
$paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
According to https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Api/Data/PaymentDetailsInterface.php#L25 this should be an array of \Magento\Quote\Api\Data\PaymentMethodInterface
Any Payment Methods based on https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Payment/Model/Method/Adapter.php would technically not be valid due to the missing interface. The interface methods are already implemented. As the Adapter class already includes these methods this should not be a breaking change.
Related Pull Requests
Fixed Issues (if relevant)
- Fixes N/A
Manual testing scenarios (*)
- Test checkout with different payment methods
Additional Information to reproduce the issue
we have tried to debug the code. According to the interface app/code/Magento/Checkout/Api/Data/PaymentDetailsInterface.php
:
/** | |
* @return \Magento\Quote\Api\Data\PaymentMethodInterface[] | |
*/ | |
public function getPaymentMethods(); |
The overriding/implemented method should return the object of the class \Magento\Quote\Api\Data\PaymentMethodInterface[]
. And we can see it is implemented in the below class:
magento2/app/code/Magento/Checkout/Model/PaymentDetails.php
Lines 17 to 20 in 84e7dfa
public function getPaymentMethods() | |
{ | |
return $this->getData(self::PAYMENT_METHODS); | |
} |
Which internally calls the $this->getData(self::PAYMENT_METHODS);
:
magento2/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php
Lines 276 to 305 in 84e7dfa
public function getData($key = '', $index = null) | |
{ | |
if ($key === self::CUSTOM_ATTRIBUTES) { | |
throw new \LogicException("Custom attributes array should be retrieved via getCustomAttributes() only."); | |
} elseif ($key === '') { | |
/** Represent model data and custom attributes as a flat array */ | |
$customAttributes = isset($this->_data[self::CUSTOM_ATTRIBUTES]) | |
? $this->_data[self::CUSTOM_ATTRIBUTES] | |
: []; | |
$this->convertCustomAttributeValues($customAttributes); | |
$data = array_merge($this->_data, $customAttributes); | |
unset($data[self::CUSTOM_ATTRIBUTES]); | |
} else { | |
$data = parent::getData($key, $index); | |
if ($data === null) { | |
/** Try to find necessary data in custom attributes */ | |
$data = isset($this->_data[self::CUSTOM_ATTRIBUTES][$key]) | |
? $this->_data[self::CUSTOM_ATTRIBUTES][$key] | |
: null; | |
if ($data instanceof \Magento\Framework\Api\AttributeValue) { | |
$data = $data->getValue(); | |
} | |
if (null !== $index && isset($data[$index])) { | |
return $data[$index]; | |
} | |
} | |
} | |
return $data; | |
} |
Which is returning the mixed array as shown in the below screenshot:
I think you are talking about the same thing it should return the object of \Magento\Quote\Api\Data\PaymentMethodInterface[]
but it is returning the mixed array.
Questions or comments
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)