Insert Discount - Coupon with SQL in NopCommerce

256 views Asked by At

I do use nopCommerce 3.9 and I would like to insert coupon code from my C# program code. There are requirements such as
"Has shopping cart amount"
and "Blocked on product".
The insert is working fine, I can see the inserted records and I think there are logically right. (The same process happening if I create Discount from Nop admin panel.)
When I open the inserted coupon from Nop admin the "Discount info" tab is perfect, on the "Requirements" tab I see the requirements
"Requirement Customer has x.xx amount in their shopping cart"
and the "Requirement Block Discount on Product", but without value.
If I modify the shopping cart value only (I don't modify the "blocked products" on purpose) and save it and reload the page, than everything is good. The blocked products are appeared too.
When I check the data tables I don't see any changes there. The records are the same as I inserted.
I guess there is another table(s), where I have to update something, but I cannot find which one it is.

I would appreciate for any help.

2

There are 2 answers

4
Divyang Desai On

From the comments, I believe OP want to insert the new discount rule with two things:

  1. Cart has minimum total X.
  2. Cart has specific product(s) Y.

And the issue is,

Its working properly if they apply discount rule from admin panel, however, applying it programmatically couldn't store specific products on a single call.

There are different tables for discount in nopCommerce.

Discount - main table
DiscountRequirement - stores requirement information
Discount_AppliedToProducts - stores discounted products information

Creating a discount rule first time will add entry in discount table only. Then the id of discount table will be used for reference to the DiscountRequirement and Discount_AppliedToProducts table.

1
Zoltan On

It was everything good with my process. The issue was the nopCommerce cache. The nopCommerce keeps the discounts in cache. After I clear the cache I can see my values.

Thanks for everyone who tried to help or had a thought!