This content originally appeared on DEV Community and was authored by Rashid Ali
I am thrilled to unveil an exciting new feature for the Cart package: Coupons! This update brings enhanced flexibility and functionality to your Laravel-based e-commerce solutions, making it easier than ever to offer discounts and promotions to your customers.
What’s New?
With the new Coupon feature, you can now:
- Apply Discounts: Add both percentage-based and fixed amount coupons to your cart.
- Create Custom Coupons: Develop your own coupon classes to suit your unique business needs.
- Manage Coupons Efficiently: Apply, remove, and get details of applied coupons with ease.
Key Features
1. Apply Coupons with Ease
Integrate discount promotions effortlessly with our new methods. You can apply a coupon to your cart using a simple method call:
use RealRashid\Cart\Facades\Cart;
use App\Coupons\PercentageCoupon;
// Create a percentage-based coupon
$percentageCoupon = new PercentageCoupon('PERCENT20', 20, '2024-12-31');
// Apply it to the cart
Cart::instance('cart')->applyCoupon($percentageCoupon);
2. Custom Coupon Classes
Design and implement custom coupon classes by implementing the Coupon
interface. Here’s a sample of a fixed amount coupon:
<?php
namespace App\Coupons;
use RealRashid\Cart\Coupon\Coupon as CouponContract;
use App\Models\Coupon as CouponModel;
class FixedAmountCoupon implements CouponContract
{
protected $coupon;
public function __construct(CouponModel $coupon)
{
$this->coupon = $coupon;
}
public function getCode(): string
{
return $this->coupon->code;
}
public function isValid(): bool
{
return $this->coupon->isValid();
}
public function getDiscountType(): string
{
return 'fixed_amount';
}
public function getExpiryDate(): string
{
return $this->coupon->expiry_date;
}
public function getDiscountAmount(): float
{
return $this->coupon->amount;
}
}
3. Manage Applied Coupons
Easily manage your applied coupons with new methods to apply, remove, and retrieve details about your coupons:
-
Apply Coupon:
Cart::applyCoupon($coupon);
-
Remove Coupon:
Cart::removeCoupon();
-
Get Coupon Details:
Cart::getAppliedCouponDetails();
How to Get Started
Ready to add discounts to your cart? Follow the updated usage documentation for detailed instructions on how to leverage the new Coupon feature.
Why This Matters
Coupons are a powerful tool for increasing sales and enhancing customer satisfaction. By integrating this feature into the Cart package, we aim to make it easier for you to run effective promotions and manage discounts, ultimately driving more value to your customers and business.
Join the Conversation
I would love to hear your feedback! Share your thoughts and experiences with the new Coupon feature by joining our community forums or connecting with us on social media.
Check It Out
Explore the Cart package and contribute to its development on our GitHub repository.
Thank you for your continued support. Stay tuned for more exciting updates and features!
Happy discounting! 🎉
This content originally appeared on DEV Community and was authored by Rashid Ali
Rashid Ali | Sciencx (2024-08-11T14:31:46+00:00) 🎉 Announcing Cart Package Coupon Feature!. Retrieved from https://www.scien.cx/2024/08/11/%f0%9f%8e%89-announcing-cart-package-coupon-feature/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.