adyen-magento2
adyen-magento2 copied to clipboard
[PW-6733] Item (XXX) with the same ID "YYY" already exists in Order Collection (with multiple payments)
Describe the bug
In the case of an order with multiple payments, \Magento\Sales\Model\OrderRepository::getList()
return following error Item (XXX) with the same ID "YYY" already exists
.
To Reproduce
Steps to reproduce the behavior:
- Create guest order with Adyen CC method
- Capture payment
- Create manually row in
sales_order_payment
table (simulate order with multiple payments) - Go to http://my-site.dev/sales/guest/view/
- Log In
- 💥
It's also possible to create order with multiple sales_order_payment
rows and try load order with this code :
$records = $this->orderRepository->getList(
$this->searchCriteriaBuilder
->addFilter('increment_id', $incrementId)
->create()
);
$items = $records->getItems();
The problem
The problem comes from the vendor/adyen/module-payment/etc/extension_attributes.xml
file which adds a join to the Order collection. We thus find ourselves with the following query:
SELECT `main_table`.*, `extension_attribute_payment_method`.`method` AS `extension_attribute_payment_method_method`,
FROM `sales_order` AS `main_table`
LEFT JOIN `sales_order_payment` AS `extension_attribute_payment_method` ON main_table.entity_id = extension_attribute_payment_method.parent_id
WHERE ((`increment_id` = 'PRE-UK-2022040249'))
In the case of an order with multiple payments, this query can output multiple lines. All rows have the same order ID (entity_id
), here is an example of the result of the query:

If I test to remove this join, everything works perfectly!

Magento version
ver. 2.4.3-p1
Plugin version
adyen/module-payment : "8.1.1"
Hi @dimitriBouteille,
Thank you for opening this issue and the clear description of the problem. We will be investigating whether it is safe to remove the join or if it should be resolved in a different way.
Cheers, Titus
(Similar but in different place to #1432)
Hello @tnaber ,
Do you have any news ?
Hi @dimitriBouteille,
There has not been any progress on this issue yet. Is this a blocker for you?
In your steps, you manually add a row to the sales_order_payment
table, were you also able to trigger this issue without manually adding a row. E.g. just using multiple payments (could you provide the instructions for this)?
Additionally, I can find the code you mentioned here: https://github.com/magento/magento2/blob/fde55517ff5bc79aacc64d4c08411e0112356e17/app/code/Magento/Sales/Helper/Guest.php#L320 Is that indeed the code you were talking about? This also filters on the 'store_id' which might change the situation?
Cheers, Titus
Hello @tnaber
It is blocking for me because I can no longer access the list of commands http://my-site.dev/admin/sales/order/, the user can no longer see this page http://my-site.dev/sales/guest/view/. Generally, several pages are in error ... While there is this problem, I can’t deploy the adyen module in production.
To reproduce the bug, I am talking about adding several sales_order_payment
lines in the database. This is the easiest way to reproduce the bug. However, I do not need to create these lines manually because it is a custom feature that does this.
To quickly explain the functionality: the user must be able to pay in several times the order. The first time he will pay for example 20% of the order amount, then 3 weeks after he will have to pay the rest. For each payment, a new sales_order_payment
line is created.
Concerning this point :
https://github.com/magento/magento2/blob/fde55517ff5bc79aacc64d4c08411e0112356e17/app/code/Magento/Sales/Helper/Guest.php#L320
I have this bug when I use \Magento\Sales\Model\ResourceModel\Order\Collection
, the OrderRepository
that uses the collection, ...
This bug does not concern just the guest form:(
For me, you have to modify this join and go through another method. Do you know where this column payment_method
is used?
https://github.com/Adyen/adyen-magento2/blob/5d6b157887eb3c4c810cad882d1c17b356309e23/etc/extension_attributes.xml#L28
Hi @tnaber
Do you know where the payment_method
column is used? In the code I don’t see any reference to this join.
If the column is no longer used or not required, I can manually delete the extension_attributes.xml
file via composer, but this is not the best solution ...
+1
We have the same issue with multiple payments.
It's not only frontend issue like @dimitriBouteille said, the issue happen also in REST API rest/all/V1/orders
curl --location -g --request GET 'https://www.example.com/rest/all/V1/orders?searchCriteria[filterGroups][0][filters][0][field]=increment_id&searchCriteria[filterGroups][0][filters][0][value]=10000999&searchCriteria[filterGroups][0][filters][0][conditionType]=eq' --header 'Authorization: Bearer xxxx'
ETL cannot retrieve orders anymore, it's a huge problem.
@tnaber you need to group by order but I don't know how to do that in XML.
Note: Same issue on Adyen 7.x and 8.x
@FredericMartinez
Hey, I found a little patch until I get a fix, you can add this lines in composer.json
but this is not the best solution ...
"scripts": {
"post-install-cmd": [
"rm -f vendor/adyen/module-payment/etc/extension_attributes.xml"
]
}
In my case, no more problems even in the production environment.
@dimitriBouteille I like your style 🤘🤘
I have done the same hotfix with a good old patch (passion patch)
Index: vendor/adyen/module-payment/etc/extension_attributes.xml
===================================================================
diff --git a/vendor/adyen/module-payment/etc/extension_attributes.xml b/vendor/adyen/module-payment/etc/extension_attributes.xml
deleted file mode 100644
--- a/vendor/adyen/module-payment/etc/extension_attributes.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0"?>
-<!--
-/**
- * ######
- * ######
- * ############ ####( ###### #####. ###### ############ ############
- * ############# #####( ###### #####. ###### ############# #############
- * ###### #####( ###### #####. ###### ##### ###### ##### ######
- * ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
- * ###### ###### #####( ###### #####. ###### ##### ##### ######
- * ############# ############# ############# ############# ##### ######
- * ############ ############ ############# ############ ##### ######
- * ######
- * #############
- * ############
- *
- * Adyen Payment module (https://www.adyen.com/)
- *
- * Copyright (c) 2021 Adyen NV (https://www.adyen.com/)
- * See LICENSE.txt for license details.
- *
- * Author: Adyen <[email protected]>
- */
--->
-<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
- <extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
- <attribute code="payment_method" type="string">
- <join reference_table="sales_order_payment" reference_field="parent_id" join_on_field="entity_id">
- <field>method</field>
- </join>
- </attribute>
- </extension_attributes>
-</config>