Hello devs
I have some weird behaviour mixing form-data based cart endpoint (/add
) with B2B quantity rules.
When adding multiple items using inputs e.g. name="items[0][id]"
add.js
stops working when the variant has a minimum quantity break set.
The following is an image of two request payloads, whereas the left one has quantity breaks (minimum 12, increment 4) and fails and the right one has no quantity breaks and succeeds.
# Error message
{
"status": 422,
"message": "Denne vare skal mindst have 12.", # "This items request at least 12"
"description": "Denne vare skal mindst have 12."
}
-
If I remove the secondary item (
items[0][id]
) references in the payload, the request succeeds. -
The secondary item has no quantity breaks set, ever.
-
If I remove quantity breaks from the product, the left request payload succeeds.
- If I then add quantity 20 of this request, then re-enables quantity breaks and start using it, it now succeeds (cart already has the minimum, so itβs not relevant factor)
- If I then clear cart and try to do the exact same request, it now fails
Update
Funny enough, I tried testing with the ajax API /add.js
using the same data, and this works.
multipart/form-data
request
form_type: product
utf8: β
id: 54684107145551
quantity: 20
product-id: 15224089117007
section-id: template--25234391040335__main
properties[_engraving]: on
items[1][id]: 54974323360079
items[1][quantity]: 20
items[1][properties][_engraving_id]: engraving_Wg3GXa1745488537
items[1][properties][_is_engraving_component]: true
properties[_engraving_id]: engraving_Wg3GXa1745488537
properties[Indgraverings tekst #1]: rtwqtwq
properties[Indgraverings tekst #2]: twq
properties[Indgraverings tekst #3]: yqwe
properties[Indgraverings tekst #4]: hsa
properties[Indgraverings font]: Segoe print
sections: template--25234391040335__quick_order_list_EH7CdY,sections--25234391204175__cart-drawer
sections_url: /products/breeze52-orehaengere-hjerte
# => returns
{
"status": 422,
"message": "Denne vare skal mindst have 12.", # "This items request at least 12"
"description": "Denne vare skal mindst have 12."
}
application/json
request
{
"items": [
{
"id": 54684107145551,
"quantity": 20,
"properties": {
"_engraving_id": "test",
"Indgraverings tekst #1": "test1",
"Indgraverings tekst #2": "test2",
"Indgraverings tekst #3": "test3",
"Indgraverings tekst #4": "test4",
"Indgraverings font": "test"
}
},
{
"id": 54974323360079,
"quantity": 20,
"_engraving_id": "test",
"_is_engraving_complete": true
}
]
}
# => returns 200 and adds to cart
Itβs not the property names. Serializing them does nothing.