[ECP-9943] Fix installment data loss during GraphQL placeOrder#3291
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the AdyenCcDataAssignObserver to prevent the loss of payment information during checkout by removing unconditional calls to unset additional information. While the change correctly addresses the data loss issue, the newly added conditional unsetting logic is redundant. Since Magento's setAdditionalInformation method automatically overwrites existing keys and skips missing ones, the explicit unsetting of these keys before the update loop is unnecessary and can be removed to simplify the implementation.
| // Remove each CC-specific field from the previous payment only if the incoming | ||
| // data contains a replacement for that specific field. This prevents the placeOrder | ||
| // mutation from clearing data that was set by setPaymentMethodOnCart. | ||
| $ccSpecificKeys = [self::CC_TYPE, self::NUMBER_OF_INSTALLMENTS, self::COMBO_CARD_TYPE]; | ||
| foreach ($ccSpecificKeys as $ccKey) { | ||
| if (array_key_exists($ccKey, $additionalData)) { | ||
| $paymentInfo->unsAdditionalInformation($ccKey); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
This block is redundant and can be removed. The primary fix for the data loss issue is the removal of the unconditional unsAdditionalInformation calls at the start of the execute method (previously lines 103-105).
In Magento 2, setAdditionalInformation (called later in this method at line 155) automatically overwrites existing values for the same key. Therefore, explicitly unsetting the keys before setting them again provides no benefit. If a key is missing from the current request's $additionalData, it will simply be skipped by the loop at line 154, effectively preserving the existing value in $paymentInfo, which is the desired behavior to prevent data loss.
|



Description
This PR fixes an issue in GraphQL headless checkout where the placeOrder mutation re-triggers AdyenCcDataAssignObserver without the original additional payment data, causing fields like number_of_installments to be cleared.
Fixes #2346