on ‎2020 Dec 23 12:24 PM
Hi, friends.
I've written a Global Script which should add product "Delivery" to a Quote if "Total" is less than 15$ and delete "Delivery" if "Total" is more than 15$.
At the moment, adding works fine, but not deleting. When I add some new product to Quote and the "Total" is more than 15$ "Delivery" isn't deleted.
Total calculated according to the formula: Total = Total - Delivery_Price.
P.S: When I change the quantity of a product in Quote or when I reopen the Quote deleting works fine.
I'll be grateful for any useful feedback.
The Global Script code:
free_delivery_threshold = 15
query = SqlHelper.GetSingle("SELECT product_price AS price FROM products WHERE product_name like 'Delivery'")
delivery_price = query.price
if Quote.ContainsAnyProductType("Fast-food_cpq"):
if ( Quote.Total.TotalAmount - delivery_price ) > free_delivery_threshold and Quote.ContainsAnyProductByName('Delivery'):
for item in Quote.MainItems:
if item.ProductName == 'Delivery':
item.Delete()
Quote.Messages.Add("Order amount is more than {0}$. Free delivery!".format(free_delivery_threshold))
Quote.Save()
if ( Quote.Total.TotalAmount - delivery_price ) <= free_delivery_threshold and not Quote.ContainsAnyProductByName('Delivery'):
Quote.AddItem('Delivery_cpq')
Quote.Messages.Add("Order amount is less than {0}$. Paid delivery!".format(free_delivery_threshold))
Quote.Save()
Global Script Events:

Quote Total less than 15$:

Quote Total more than 15$:

Request clarification before answering.
Hi Sigy,
Please add below code after Quote.Save() method in first if loop.
Quote.Reconfigure();
So final code would look like,
for item in Quote.MainItems:
if item.ProductName == 'COILS':
item.Delete()
Quote.Save()
Quote.Reconfigure()Hope this will solve your problem.
Best,
Nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 7 | |
| 6 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.