Developer forum

Forum » Ecommerce - Standard features » Add discount orderlines using /dwapi/ecommerce/carts/{secret}/items

Add discount orderlines using /dwapi/ecommerce/carts/{secret}/items

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I need to create some orderline programmatically to handle some complicated discount scenarios.

I was wondering if I can use the /dwapi/ecommerce/carts/{secret}/items endpoint to do so. I have managed to create an orderline (using an existing productID) but I could not manage to provide price information.

Is this even possible? And one more thing. Can I also set the OrderLineType from the API? I see that OrderLineViewModel does not have a property for it.

Thank you,

Adrian


Replies

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

the property is availble and can be used in the endpoint in fact. Please, find the attachment.

BR, Oleg QA

2022-05-17_11-24-26.png 2022-05-17_11-25-06.png
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Thank you Oleg,

I will try it out.
What about setting the price for the orderline?

Thank you,
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Oleg,

I will try to be more specific about what I am trying to do.

I am using this POST endpoint:

/dwapi/ecommerce/carts/{secret}/items

and I am trying to send this Payload:


{
      "ProductId": "SOMEID",
      "ProductVariantId": "",
      "ProductLanguageId": "LANG17",
      "ProductName": "Discount TEST",
      "Quantity": 1,
      "UnitPrice": "0.25",
      "OrderLineType": "ProductDiscount",
       "UnitPrice": {
        "Price": 1.4,
        "VATPercent": 20,
        "CurrencyCode": "EUR"
      }
 }

No matter what I do, I cannot add a discount orderline.

I have tried various approaches for the Price and also for the OrderLineType but without any luck.

I have noticed that an empty ProductID will not generate an orderline, with a fake ProductID I can create the orderline but wthout OrderLineType and Price.

Can you please suggest how I can accomplish this action?

Thank you,

Adrian 

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi Adrian,

I see the same results with code above except if use 'Fixed' orderlinetype (orderlinetype=2 in db) and 'OrderDiscount' (0). Prices are zero in the both cases. I've asked our expert to comment the issue here, so let't wait for the feedback.

BR, Oleg QA   

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Adrian,

It is not possible to set a price using web api.

 

Best regards,

Vladimir

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Oleg, Vladimir,

Thank you both for the details.

@Vladimir is this just a limitation of the POST method or is it valid also for PATCH method? Is this going to be supported in the future?

Thank you,

Adrian

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Yes, this limit is valid for PATCH method too.
Note that all your discount manipulations should be supported by existing discount types: https://doc.dynamicweb.com/documentation-9/ecommerce/discounts/discounts-offers

There is a posibility to create a discount extention, see 'DiscountExtenderBase' example: https://doc.dynamicweb.com/training/t3-platform-developer/t3-platform-developer/3-3-extending-ecommerce

Is this could be a solution?

 

Best regards,
Vladimir

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Vladimir,

I was trying to avoid using the discount logic since our scenario is a bit complicated and I was trying to manipulate the cart from the interface instead.

But I guess I will have to fall back to the discount logic.

Thank you very much for all your replies.

Adrian

 

You must be logged in to post in the forum