我们已将 Magento 版本从 2.3.5p2 升级到 2.4.3 P1。 之后,在下订单时我们遇到了问题。 错误:
Object of class Magento\Quote\Api\Data\AddressExtension could not be converted to string in vendor\magento\module-checkout-staging\Plugin\GuestPaymentInformationManagementPlugin.php:106
我们观察到以下扩展属性的问题是代码
<extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
<attribute code="tm_address_id" type="string" />
如何解决错误?
最佳答案
我今天遇到了同样的问题,问题发生在 vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
这里的错误是在比较送货地址和帐单地址时,扩展属性不能转换为字符串。
在我的例子中,扩展属性只添加到账单地址,在送货地址与账单地址比较中无关紧要。
这似乎是 Adobe/Magento 团队未涵盖的意外案例。
我找不到任何修复此问题的官方补丁,因此我创建了这个补丁,它只是在与运输数据进行比较之前从 $billingData
中删除了 extension_attributes
键。
diff --git a/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php b/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
index 7f0de541..c8444df2 100644
--- a/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
+++ b/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
@@ -117,7 +117,7 @@ class PaymentInformationManagementPlugin
$billingData = $this->convertAddressValueToFlatArray($billingAddressData);
$billingKeys = array_flip(array_keys($billingData));
$shippingData = array_intersect_key($quoteShippingAddressData, $billingKeys);
- $removeKeys = ['region_code', 'save_in_address_book'];
+ $removeKeys = ['region_code', 'save_in_address_book', 'extension_attributes'];
$billingData = array_diff_key($billingData, array_flip($removeKeys));
$difference = array_diff($billingData, $shippingData);
$sameAsBillingFlag = empty($difference);
编辑:
同样的错误发生在 vendor/magento/module-checkout-staging/Plugin/GuestPaymentInformationManagementPlugin.php
相同的解决方案,两者的单个补丁:
diff --git a/vendor/magento/module-checkout-staging/Plugin/GuestPaymentInformationManagementPlugin.php b/vendor/magento/module-checkout-staging/Plugin/GuestPaymentInformationManagementPlugin.php
index 2728b160..ee8afacd 100644
--- a/vendor/magento/module-checkout-staging/Plugin/GuestPaymentInformationManagementPlugin.php
+++ b/vendor/magento/module-checkout-staging/Plugin/GuestPaymentInformationManagementPlugin.php
@@ -101,7 +101,7 @@ class GuestPaymentInformationManagementPlugin
$billingData = $this->convertAddressValueToFlatArray($billingAddress->getData());
$billingKeys = array_flip(array_keys($billingData));
$shippingData = array_intersect_key($quoteShippingAddressData, $billingKeys);
- $removeKeys = ['region_code', 'save_in_address_book'];
+ $removeKeys = ['region_code', 'save_in_address_book', 'extension_attributes'];
$billingData = array_diff_key($billingData, array_flip($removeKeys));
$difference = array_diff($billingData,$shippingData);
return empty($difference);
diff --git a/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php b/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
index 7f0de541..c8444df2 100644
--- a/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
+++ b/vendor/magento/module-checkout-staging/Plugin/PaymentInformationManagementPlugin.php
@@ -117,7 +117,7 @@ class PaymentInformationManagementPlugin
$billingData = $this->convertAddressValueToFlatArray($billingAddressData);
$billingKeys = array_flip(array_keys($billingData));
$shippingData = array_intersect_key($quoteShippingAddressData, $billingKeys);
- $removeKeys = ['region_code', 'save_in_address_book'];
+ $removeKeys = ['region_code', 'save_in_address_book', 'extension_attributes'];
$billingData = array_diff_key($billingData, array_flip($removeKeys));
$difference = array_diff($billingData, $shippingData);
$sameAsBillingFlag = empty($difference);
关于magento - 错误 : Object of class Magento\Quote\Api\Data\AddressExtension could not be converted to string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70260118/