Discount by payment type
Discount by payment type
We are looking at a discount type by single credit card used. Is it possible to enable a 10% discount for consumers who only use American Express with AbleCommerce?
Re: Discount by payment type
I think you need to make some smal customization to accomplish this. This is not possible out of the box. First create new user group let say it Credit Card Discount Group. Then create a coupon with 10% discount amount. Now edit website/checkout/paymentforms/CreditCardPaymentForms.ascx file and add following method to it just above closing </script> tag
Then locate following line of code
and update it as
Now for payment method name specify the payment method for whom you want to give 10% discount. For groupId you need to provide the GroupId of your newly created group. You can quickly check it by just after creating new group click the user icon and it will take you to a page for group member listing. You can see GroupId value in query string just copy that integer value and replace it here. Finally for couponcode provide the coupon code of 10% discount coupon. Now try placing an order with desired payment method for testing.
Code: Select all
private void ApplyCoupon(string couponCode)
{
if (String.IsNullOrEmpty(couponCode))
return;
Coupon coupon = CouponDataSource.LoadForCouponCode(couponCode);
String couponValidityMessage = String.Empty;
if (coupon != null)
{
if (!CouponCalculator.IsCouponAlreadyUsed(Token.Instance.User.Basket, coupon))
{
if (CouponCalculator.IsCouponValid(Token.Instance.User.Basket, coupon, out couponValidityMessage))
{
Basket basket = Token.Instance.User.Basket;
BasketCoupon recentCoupon = new BasketCoupon(Token.Instance.UserId, coupon.CouponId);
basket.BasketCoupons.Add(recentCoupon);
// APPLY COUPON COMBINE RULE
//THE RULE:
//If most recently applied coupon is marked "do not combine", then all previously
//entered coupons must be removed from basket.
//If most recently applied coupon is marked "combine", then remove any applied
//coupon that is marked "do not combine". (Logically, in this instance there
//could be at most one other coupon of this type...)
string previousCouponsRemoved = "";
if (recentCoupon.Coupon.AllowCombine)
{
//IF ALLOW COMBINE, REMOVE ALL PREVIOUS NOCOMBINE COUPONS
for (int i = (basket.BasketCoupons.Count - 1); i >= 0; i--)
{
if (!basket.BasketCoupons[i].Coupon.AllowCombine)
{
if (previousCouponsRemoved.Length > 0)
{
previousCouponsRemoved += "," + basket.BasketCoupons[i].Coupon.Name;
}
else
{
previousCouponsRemoved = basket.BasketCoupons[i].Coupon.Name;
}
basket.BasketCoupons.DeleteAt(i);
}
}
}
else
{
//IF NOT ALLOW COMBINE, REMOVE ALL EXCEPT THIS COUPON
for (int i = (basket.BasketCoupons.Count - 1); i >= 0; i--)
{
if (basket.BasketCoupons[i] != recentCoupon)
{
if (previousCouponsRemoved.Length > 0)
{
previousCouponsRemoved += "," + basket.BasketCoupons[i].Coupon.Name;
}
else
{
previousCouponsRemoved = basket.BasketCoupons[i].Coupon.Name;
}
basket.BasketCoupons.DeleteAt(i);
}
}
}
basket.Save();
basket.Recalculate();
}
else
{
//Invalid Coupon
//Output couponValidityMessage here
}
}
else
{
//"The coupon code you've entered is already in use.<br /><br />";
}
}
else
{
//"The coupon code you've entered is invalid.<br /><br />";
}
}
Code: Select all
Payment payment = GetPayment();
Code: Select all
if (CardType.SelectedItem.Text == "payment method name")
{
if (!Token.Instance.User.IsInGroup(groupId))
{
Token.Instance.User.UserGroups.Add(new UserGroup(Token.Instance.User.UserId, groupId));
Token.Instance.User.Save();
ApplyCoupon("couponcode");
}
}
Payment payment = GetPayment();
Re: Discount by payment type
This would be great! I'm trying it out for our new bitcoin plug-in. Since we are not using a credit card type can you please tell me what would this line need to be changed to:
if (CardType.SelectedItem.Text == "payment method name")
maybe PaymentMethod?
if (CardType.SelectedItem.Text == "payment method name")
maybe PaymentMethod?