如何解决如何通过API在Shopware 6中创建订单
我正在将商店从旧平台迁移到Shopware6。我需要转移订单,但这样做有困难。我正在使用可以访问旧平台数据库的脚本所调用的API。我已经使用API推送了几乎所有其他实体(客户,产品,媒体,类别,它们之间的链接),并且效果很好。 在文档中,似乎应该首先创建一个购物车,然后通过一个操作将其创建为订单,然后添加订单地址,付款并通过操作将状态转换为所需状态。
没有确切的指导,所以我最终尝试将带有订单数据的POST请求推送到order
端点,如下所示:
array:12 [
"orderNumber" => "100000546"
"price" => array:6 [
"netPrice" => 47.3519
"totalPrice" => 50.32
"positionPrice" => 50.32
"calculatedTaxes" => array:1 [
0 => array:3 [
"tax" => 3.314633
"taxRate" => 7
"price" => 50.32
]
]
"taxRules" => array:1 [
0 => array:2 [
"taxRate" => 7
"percentage" => 100
]
]
"taxStatus" => "gross"
]
"shippingCosts" => array:5 [
"unitPrice" => 4.95
"totalPrice" => 4.95
"quantity" => 1
"calculatedTaxes" => array:1 [
0 => array:3 [
"tax" => 0.3465
"taxRate" => 7
"price" => 4.95
]
]
"taxRules" => array:1 [
0 => array:2 [
"taxRate" => 7
"percentage" => 100
]
]
]
"billingAddressId" => "9f27c3c98dfe4e47ad2a9493da5807bc"
"currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca"
"languageId" => "2fbb5fe2e29a4d70aa5854ce7ce3e20b"
"salesChannelId" => "d1d7fc6faedb4600afd0cfe68f627f6d"
"orderDateTime" => "2014-11-03 08:27:43"
"currencyFactor" => 1
"stateId" => "8089405ce1e046f1819823d847125d25"
"lineItems" => array:1 [
0 => array:6 [
"identifier" => "5158757ba32b489faf70fcd7c4578604"
"productId" => "5158757ba32b489faf70fcd7c4578604"
"quantity" => 10
"label" => "Some product"
"position" => 1
"price" => array:5 [
"unitPrice" => 3.64
"totalPrice" => 36.3551
"quantity" => 10
"calculatedTaxes" => array:1 [
0 => array:3 [
"tax" => 0.2548
"taxRate" => 7
"price" => 36.3551
]
]
"taxRules" => array:1 [
0 => array:2 [
"taxRate" => 7
"percentage" => 100
]
]
]
]
]
"orderCustomer" => array:6 [
"customerId" => "cafedb542f2f488e99375192092c9032"
"salutationId" => "08f9cf197c0643ac98590948cf5dd9f8"
"firstName" => "xx
"lastName" => "xx
"email" => "xx
"customerNumber" => "10020"
]
]
这会在数据库中创建一个订单,但是我无法在admin(admin#/sw/order/index
)的订单列表中看到它-实际上,当我尝试更改列表页面时,它破坏了列表。如果我打开另一个订单,然后用我创建的订单ID替换订单ID,则可以打开它,但它没有详细信息框。我只能看到项目,状态和文档。我怀疑这是由于没有链接的付款和货运信息,因此我也通过API在order_address
实体中添加了实体,然后尝试创建order_delivery
,因此我有货运状态。不幸的是,当我尝试创建具有状态的实体时,我得到了这个信息:
0 => {#8643
+"code": "FRAMEWORK__WRITE_CONSTRAINT_VIOLATION"
+"status": "400"
+"detail": "This field is write-protected. (Got: "crud" scope and "system" is required)"
+"template": "This field is write-protected. (Got: "%s" scope and "%s" is required)"
+"meta": {#8655
+"parameters": array:2 [
0 => "crud"
1 => "system"
]
}
+"source": {#8664
+"pointer": "/0/stateIdstateId"
}
}
我被困住了。我需要帮助。我可以在请求中添加一些开关以强制向system
字段中写入(创建具有stateId
范围的令牌吗?)吗?还是我应该采取行动?但是再说一次,如果没有将order_delivery
实体设置为值open
...
我反正正确吗?通过尝试直接创建实体(这些订单仅作为存档,它们已经全部完成)了?
解决方法
也许您应该将Shopware的迁移插件用于sw5和sw6。 它们在Migration process中进行了描述。 您可以在GitHub上找到这些插件 https://github.com/shopware/SwagMigrationAssistant 和 https://github.com/shopware/SwagMigrationConnector
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。