簡體   English   中英

Shopware 6 API Bulk Update entity product and other issue single error don't update all

[英]Shopware 6 API Bulk Update entity product and other issue single error dont update all

在 API 更新產品中需要一點幫助

https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#performance

  • 我們有產品 1、2、3..... 最多 100 種,我們從我們的 ERP 中批量更新數量(單次操作)
  • 由於某種原因(假設)而不是 integer 我們將字符串發送到第 80 個產品 --- 所以 API 響應給出錯誤(沒關系)
  • 但不僅第 80 個產品無法更新,而且整個批次都失敗,因此 1 到 100 個產品失敗 - 沒有一個被更新

如果我們錯了,請幫助解決這個問題或糾正我們??

使用參考https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#performance

- We are updating "entity": "product", and "action": "upsert" with headers
// --header 'single-operation: 1'
// --header 'indexing-behavior: use-queue-indexing'

一切都很好,但是因為我們正在批量使用實體,如果任何一個實體失敗,完整的批量會給出錯誤,並且批量列表中的產品都不會更新

如果我們要發送 1 到 100 件產品,而問題僅出現在第 80 件產品上,那么只有那件產品不會得到更新——但 rest 99 件產品應該得到更新

您描述的行為是您使用single-operation: 1時的預期行為,如您鏈接的參考中所述。

使用single-operation: 1您發送的所有操作都在單個數據庫事務中執行,因此當其中一個操作失敗時,其他操作也會回滾。

根據你的描述,你想使用single-operation: 0 ,這意味着你發送的每個操作都有它自己的數據庫事務,所以當一個操作失敗時,其他操作仍然 go 通過。

參考 URL https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#examples

Update product stocks
{
    "stock-updates": { // Name of the transaction, choose freely 
        "entity": "product", // Name of the entity you would like to update
        "action": "upsert", // Available actions are upsert and delete,
        "payload": [ // A list of objects, each representing a subset of the entity scheme referenced in `entity`. `id` is required for upsert operations.
            {
                "id": "c197170c60ab472b8dc1218acaba220e",
                "stock": 41
            },
            {
                "id": "a10c59fce8214fdaa552d74e0c6347ff",
                "stock": 'XXXXX'
            },
            {
                "id": "1b13176b6e0f4bb496c9a31b4fd7e97b",
                "stock": 43
            }
        ]
    }
}

我們嘗試了以下方法來更新庫存——但不是 integer 批量發送一個產品的字符串 XXXXX,這樣我們就可以看到一個產品沒有更新其他產品的錯誤。 (完整批量未更新)

以下是我們庫存中的情景 1 和情景 2 均未更新。 我們想要一種使用單一操作的方法:0 並且應該更新非錯誤產品庫存

==========

場景一:單操作:1

Response 1: Array
(
    [error] => 1
    [message] => Array
        (
            [errors] => Array
                (
                    [0] => Array
                        (
                            [code] => ba785a8c-82cb-4283-967c-3cf342181b40
                            [status] => 400
                            [detail] => This value should be of type int.
                            [template] => This value should be of type {{ type }}.
                            [meta] => Array
                                (
                                    [parameters] => Array
                                        (
                                            [{{ value }}] => "XXXXX"
                                            [{{ type }}] => int
                                        )

                                )

                            [source] => Array
                                (
                                    [pointer] => /product/2/stock
                                )

                        )

                )

        )

)

==========

場景二:單次操作:0

Response 2: Array
(
    [error] => 1
    [message] => Array
        (
            [success] => 
            [data] => Array
                (
                    [product] => Array
                        (
                            [result] => Array
                                (
                                    [0] => Array
                                        (
                                            [entities] => Array
                                                (
                                                )

                                            [errors] => Array
                                                (
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [entities] => Array
                                                (
                                                )

                                            [errors] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [code] => ba785a8c-82cb-4283-967c-3cf342181b40
                                                            [status] => 400
                                                            [detail] => This value should be of type int.
                                                            [template] => This value should be of type {{ type }}.
                                                            [meta] => Array
                                                                (
                                                                    [parameters] => Array
                                                                        (
                                                                            [{{ value }}] => "XXXXX"
                                                                            [{{ type }}] => int
                                                                        )

                                                                )

                                                            [source] => Array
                                                                (
                                                                    [pointer] => /2/stock
                                                                )

                                                        )

                                                )

                                        )

                                    [2] => Array
                                        (
                                            [entities] => Array
                                                (
                                                )

                                            

                                        )

                                )

                            [extensions] => Array
                                (
                                )

                        )

                )

        )

)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM