Discount

I want to change a price based on the quantity chosen for the product. (In essence: give the user a discount for ordering more.)

If a quantity of 1-99 is chosen then do nothing (go with the default price) which is $8
If a 100 or more is ordered, then I want to drop the price to $5.

I think I would use the AddToCartEvent. I could check the quantity in that object, and then set the price based on the quantity. I’d use code something like the below:

if(AddToCartEvent.quantity >= 100) {
AddToCartEvent.price = 5.00
}
But on what page would I use the AddToCartEvent? I looked for examples in the forum on this event and couldn’t find it.
My product page is:
https://fedorjoseph.wixsite.com/mysite/product-page/i-m-a-product-27

Hi, fedor_joseph .

At the very least, it appears that you will need to call the addToCart() method from:

  • [ADD TO CART] click event on product-page page
  • Quantity spinner on cart page

I couldn’t find anything in the properties panel for the [ADD TO CART] click event on the product page. Or for the quantity button or the price field. But if the adjusting can take place after the user has made their choice, that should be fine.

So, using the properties panel, I found that I can call code when the user exits the viewport.
My generated function looks like this:

export function productPage1_viewportLeave(event) {
var myProduct = $w(‘#productPage1’).getProduct()

}

I would like to get a hold of the Products object, and change price based on what the quantity was. (Above was my best guess on how to access the properties of the product object.)

I can’t seem to find any code completion help for price and quantity though. Is there a better way to access and modify the product object?