Developer forum

Forum » Development » no validation when adding a product to the cart via the dwapi/ecommerce/carts/{cartSecrect}/items/ endpoint

no validation when adding a product to the cart via the dwapi/ecommerce/carts/{cartSecrect}/items/ endpoint

Mikkel Hammer
Mikkel Hammer
Reply

Hi DW :)

We've been playing around with the dwapi, and noticed there's no validation when adding a product to the cart via the dwapi/ecommerce/carts/{cartSecrect}/items/ endpoint.
Naming 5 examples we've tried out, i've added the orderlines from the cart below so you can reference them.

OL327043 is just for reference, its an expected/correct result, as it was added with a variant that exists in the database.
The request body for OL327043:

{
    "ProductId""SGK089",
    "ProductVariantId""SP1239.SP1240.SP1298",
    "Quantity"1
}

OL327044 here we removed the ProductId from the body, and end up getting only the ProductVariantName set on the orderline. 
The request body for OL327044:

{
    "ProductVariantId""SP1239.SP1240.SP1298",
    "Quantity"1
}

OL327045 here we changed the last part of the ProductVariantId combination, to a random combination that does'nt exists, and we end of getting a part of the variant name generated from the VariantCombo that do exists, and most of the other information is from the main product. 
Variant info from DB:

The request body for OL327045:

{
    "ProductId""SGK089",
    "ProductVariantId""SP1239.SP1240.TEST",
    "Quantity"1
}

OL327046 here we just added quantity and ends up with a empty orderline where quantity is set to 1. 
The request body for OL327046:

{
    "Quantity"1
}

The request when you try with a empty request body { }, also just return OK without doing anything to the cart.


Here is the Orderlines taken from the Cart after running the above request againts the /items endpoint, so you can se what they each return.

"OrderLines": [
        {
            "Id""OL327043",
            "ProductId""SGK089",
            "ProductVariantId""SP1239.SP1240.SP1298",
            "ProductLanguageId""LANG1",
            "ProductName""SANDEEL 12.5CM 23G SINKING BLUE/SILVER 2+1PCS",
            "ProductNumber""42203",
            "ProductVariantName""12.5CM - SINKING / 23G - BLUE/SILVER",
            "ProductImage""/Files/Images/missing_image.jpg",
            "PrimaryOrDefaultGroup": {
                "Id""SPSHOP12-77",
                "Name""Jigs"
            },
            "Quantity"1.0,
            "UnitName""",
            "OrderLineFields": {},
            "Price": {
                "Price"9.49,
                "PriceFormatted""kr. 9,49",
                "PriceWithoutVat"9.49,
                "PriceWithoutVatFormatted""kr. 9,49",
                "PriceWithVat"11.6727,
                "PriceWithVatFormatted""kr. 11,67",
                "Vat"2.1827,
                "VatFormatted""kr. 2,18",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "UnitPrice": {
                "Price"9.49,
                "PriceFormatted""kr. 9,49",
                "PriceWithoutVat"9.49,
                "PriceWithoutVatFormatted""kr. 9,49",
                "PriceWithVat"11.6727,
                "PriceWithVatFormatted""kr. 11,67",
                "Vat"2.1827,
                "VatFormatted""kr. 2,18",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "UnitPriceBeforeDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "TotalDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            }
        },
        {
            "Id""OL327044",
            "ProductId""",
            "ProductVariantId""",
            "ProductLanguageId""",
            "ProductName""",
            "ProductNumber""",
            "ProductVariantName""12.5CM - SINKING / 23G - BLUE/SILVER",
            "ProductImage""/Files/Images/missing_image.jpg",
            "PrimaryOrDefaultGroup": {},
            "Quantity"1.0,
            "UnitName""",
            "OrderLineFields": {},
            "Price": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPrice": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPriceBeforeDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "TotalDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            }
        },
        {
            "Id""OL327045",
            "ProductId""SGK089",
            "ProductVariantId""SP1239.SP1240.TEST",
            "ProductLanguageId""LANG1",
            "ProductName""SANDEEL",
            "ProductNumber""SGK089",
            "ProductVariantName""12.5CM - SINKING / 23G - ",
            "ProductImage""/Files/Images/missing_image.jpg",
            "PrimaryOrDefaultGroup": {
                "Id""SPSHOP12-77",
                "Name""Jigs"
            },
            "Quantity"1.0,
            "UnitName""",
            "OrderLineFields": {},
            "Price": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPrice": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPriceBeforeDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "TotalDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            }
        },
        {
            "Id""OL327046",
            "ProductId""",
            "ProductVariantId""",
            "ProductLanguageId""",
            "ProductName""",
            "ProductNumber""",
            "ProductImage""/Files/Images/missing_image.jpg",
            "PrimaryOrDefaultGroup": {},
            "Quantity"1.0,
            "UnitName""",
            "OrderLineFields": {},
            "Price": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPrice": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            },
            "UnitPriceBeforeDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercent"23.0,
                "VATPercentFormatted""23%",
                "CurrencyCode""EUR"
            },
            "TotalDiscount": {
                "PriceFormatted""kr. 0,00",
                "PriceWithoutVatFormatted""kr. 0,00",
                "PriceWithVatFormatted""kr. 0,00",
                "VatFormatted""kr. 0,00",
                "VATPercentFormatted""0%",
                "CurrencyCode""EUR"
            }
        }
    ]


We're thinking maybe there should be some sort of validation like:

ProductId is required, since it can't handle it not being there. (atleast with our data)
If a ProductVariantId is given, it should check if there's a product with that ProductId and ProductVariantId so it doesn't return "half" true data.
And maybe some changes to the return Code so it's not always 200 Ok

Ofc you can check first if the product exist via some of the other endpoints, and using that returned data as input for adding a product.
But we still think it could be usefull with some form of validation when adding a product, to prevent a scenario where you're using cached data or something similar

Hope this can be useful for the further development for the dwapi :)

EDIT:
After rereading my post and looking closer at the endpoint, i can see why you wouldn't always want the validation,
since it's /items and not /products, so you should be allowed to add "anything".

So instead of forcing the validation we requested, maybe it could be added as a property on the OrderlineViewModel that's being used for the body of the request,
to force it to validate that it's a existing product, maybe with a validitateExistingProduct boolean or something similar. Or even a specific endpoint for it


Best regards,
Mikkel Hammer


Replies

 
Mikkel Hammer
Mikkel Hammer
Reply

Hi DW,

Any news on this? :)

Best regards,
Mikkel

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Mikkel

Thank you for this test. We will create a feature request on this so we can get some validation on tha data being posted to this endpoint.

Did you encounter production issues with this?

BR Nicolai

Votes for this answer: 1
 
Mikkel Hammer
Mikkel Hammer
Reply

Hi Nicolai,

Glad we can help, and thanks for creating a feature request! :)

Well sort of, we're going live with an app soon that uses the dwapi, so we're in the final testing phase.
And we stumpled across this because we used "old" product data, where we tried to add a variant that wasn't available anymore, so we experienced the bug where the VariantCombination is partly true and added a "weird" product to the cart.

This testing did also lead us onto another bug where you can't add a product to the cart that's not available to the anonymous assortment. But the product is available to the user via another assortment, but we have another thread for that here

Best regards,
Mikkel

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

New task 7348 has been submitted to implement the validation per the request above.

BR, Oleg QA

 

You must be logged in to post in the forum