예제 #1
0
    protected void applyCoupon_Click(object sender, EventArgs e)
    {
        //Get the coupon.
        try {
            Commerce.Promotions.Coupon selectedCoupon = Commerce.Promotions.Coupon.GetCoupon(couponCode.Text);
            //we have the coupon .. validate the order.
            Commerce.Promotions.CouponValidationResponse valid =
                selectedCoupon.ValidateCouponForOrder(currentOrder);
            if (valid.IsValid)
            {
                //apply the coupon to the order
                selectedCoupon.ApplyCouponToOrder(currentOrder);
                couponMessage.Text       = "Coupon code " + selectedCoupon.CouponCode + " was applied to your order!";
                currentOrder.CouponCodes = selectedCoupon.CouponCode;

                //add a note to the order that the coupon was applied
                OrderController.AddNote("Applied coupon " + selectedCoupon.CouponCode + " to order during checkout", currentOrder);

                //re-display the order
                lblOrderItems.Text = currentOrder.ItemsToString(true);
            }
            else
            {
                couponMessage.Text = "The selected coupon could not be applied to your order.  " + valid.ValidationMessage;
            }
        }
        catch (ArgumentException ex) {
            couponMessage.Text = "The code you entered could not be found or verified.";
        }
        couponMessage.Visible = true;
        EnsurePanelsHidden();
    }
예제 #2
0
        public override void ApplyCouponToOrder(Commerce.Common.Order order)
        {
            //Validate the order to make sure it's good.
            CouponValidationResponse validationResponse =
                ValidateCouponForOrder(order);

            if (!validationResponse.IsValid)
            {
                throw new ArgumentException("Coupon is not valid for order: " + validationResponse, "order");
            }

            //updated by Spook, 11-5-2006


            //The logic for this coupon is to apply a Percent off to the order items
            //this does not include shipping/tax since those items are not

            //first, make sure this coupon hasn't been used
            if (!order.CouponCodes.Contains(CouponCode))
            {
                //calculate the discount
                order.DiscountAmount = CalculateDiscountAmount(order.CalculateSubTotal());

                //add a comment to the order
                order.CouponCodes += CouponCode;

                //save the order
                order.Save("Coupon System");
            }
        }