magento - 错误 : Object of class Magento\Quote\Api\Data\AddressExtension could not be converted to string

标签 magento magento2.4

我们已将 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

这里的错误是在比较送货地址和帐单地址时,扩展属性不能转换为字符串。

在我的例子中,扩展属性只添加到账单地址,在送货地址与账单地址比较中无关紧要。

这似乎是 Adob​​e/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/

相关文章:

php - Getimagesize() - 读取错误

linux - 我应该迁移到 windows azure 以节省 magento 的成本吗?

magento2 - 将 Magento2 版本 2.4.3-p2 更新到 2.4.4

docker - Opensearch 端口 (9200) 表示没有证书,导致运行 Magento2 命令时出现错误 "No alive nodes found in your cluster"

php - magento-警告: require_once(app/Mage.php): failed to open stream: No such file or directory

MySQL 查询 - Magento 在一行中指定属性

Magento 2 如何根据条件禁用类别属性?