Insert Discount - Coupon with SQL in NopCommerce - nopcommerce

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.

From the comments, I believe OP want to insert the new discount rule with two things:
Cart has minimum total X.
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.

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!

Related

Woocommerce Modify or Reset total_sales

I want to change or reset the total_sales to 0 at worst.
When I modify in phpMyAdmin (wc_product_meta_lookup) nothing happens and everything goes back to the way it was before after a new order.
I searched for 2 hours without finding anything.
thank you in advance.
total_sales is a post meta field, a row in postmeta table. wc_product_meta_lookup just contains consolidated data from postmeta to avoid making multiple postmeta selects when product data are needed.
postmeta is the source of truth in this case, you need to set your desired value in there. Either directly in the database or using a custom field in the product edit view.
Reports (including total sales value in the dashboard widget) are dynamically generated, so I believe the value your setting in the database will just be set back to it's true value when WordPress runs.
According to the docs, you need to delete all prior orders (permanently) and clear your browser cache for new reports.
More info: https://docs.woocommerce.com/document/reports/#section-12

Drupal 8: Only add to cart if user has enough credits

I've a site where transactions are based purely on credits. No actual money is exchanged. In such a case, I want to restrict users from adding products to cart if they do not have credits to do so.
In steps of how this should be accomplished, here is the sequence of events which I think should work :
Whenever somebody tries to add a product :
Use Rule "Before adding product to cart"
I need to get the value of the following :
Get user credits
Get sum of current product + cart value
Check for condition if credits is greater than product + cart.
If true, add product to cart else display "Not enough credits".
I use the loyalty points module for the user credits.
How can I set up the rules for this scenario?
Instead of using a module I just used a custom_validation function on commerce_add_to_card_form as suggested by lamp5

Customer segmentation price list does not work as expected in basket and checkout

The problem
We have created a customer segment and linked both a customer and a price list to this customer segment. The linked price list defines a special price of $5 for one of the products. This product has a 'default' price of $10.
When I login to the storefront with a user that belongs to customer segment, I see the correct price of $5 on the PDP. However once this product is added to the basket, it shows the 'default' product price of $10 in the minicart and on the cart page. I would expect to see $5 there as well.
Technical information
The (correct) price on the PDP is retrieved directly from the ProductBO by using the default ISProductPrice module which links to the default ProductPrice.isml.
<ISProductPrice
ProductBO="#ProductBO#"
Currency="#CurrentRequest:Currency#"
ShowInformationalPrice="true"
RichSnippetsEnabled="#RichSnippetsEnabled#"
>
The (wrong) price on the cart page is retrieved from the BasketComputedProductLineItemBO with the following (default ISH) code
<isif condition="#PriceDisplayType EQ 'net'#">
<isprint value="#PLI:SingleBasePriceNet#">
<iselse/>
<isprint value="#PLI:SingleBasePriceGross#">
</isif>
What I've tried so far
Clear cookies/cache to make sure we have a completely new basket
Made sure the Customer Segmentation Service is enabled (default ISH service).
Tried all the different methods to fetch a price from the BasketComputedProductLineItemBO
Added a couple of different products to the price list
Added a couple of different customers to the customer segment
Ran a search index
Tried to reproduce the issue on the ISH demo server
Checked the documentation on customer segmentation from the ISH support page
Tried to add a customer to the price list directly instead of a customer segment. When doing it this way, everything seems to work as expected.
At this point I'm completely stuck. Any help on how to go from here would be greatly appreciated.
Check this
https://support.intershop.com/kb/index.php/Display/IS-22923
If you search on segment on the support for version 7.9 then you get few bugs. Disable the dynamic segment service because it is buggy. See if that work or else i think you really do have a platform bug here.
Also a good idea to upgrade to the lastest minor version.

Custom loop for getting products flagged as new

I was looking for a way to build a custom loop to get the products flagged with the "new" label.
I could use the sort from the insert time, but that would always include a certain number of products, my goal here is to get those products that conform to the WooCommerce setting that says the product is considered new for a given number of days.
i have a free plugin - WooCommerce Product Badge, it has your requested feature to display "New" label with certain days defined.

Reserve items in shopping cart

Question has been asked with no answers over a month ago:
Shopping Cart reserve product
I have a shopping cart for my site in ASP.NET using SQL Server. When a user adds an item to the shopping cart I need to set a value in the product table to reserve the item (in order to avoid more people reserving the item, or buying it). Now, if the current user decides to abandon their cart by closing the browser, then how am I to restore the product record to being 'unreserved'?
Is there another way of reserving the item globally?
When a user "reserves" an item give the reservation an end date/time (e.g. DateTime.Now + 6 hrs, or whatever), by which they must have purchased the reserved item, otherwise after that date/time the reservation becomes void - I believe this is how the vast majority of bricks-and-mortar shops would work as well.
If you're worried about having a tbReservations table with loads of deprecated rows you can setup a SQL job to clear the table of old/invalid reservations each night or whenever is suitable for the business case.
Read the post by Benson Yu in this thread. In the Session_End method you can "unreserve" the products that were not checked out.

Resources