Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Coupon Based Discounts #10

Merged
merged 2 commits into from
Feb 11, 2024
Merged

Added Coupon Based Discounts #10

merged 2 commits into from
Feb 11, 2024

Conversation

Safemood
Copy link
Owner

This PR implements coupon-based discounts, allowing users to apply various types of coupons to their cart items. It includes tests covering scenarios such as applying time-limited coupons, single-use coupons, restricted user coupons, and limited usage coupons. Additionally, the README file has been updated with code examples demonstrating how to utilize different types of coupons.

Coupon Examples

use Safemood\Discountify\Facades\Coupon;


// Time-Limited Coupon

Coupon::add([
    'code' => 'TIMELIMITED50',
    'discount' => 50,
    'startDate' => now(),
    'endDate' => now()->addWeek(),
]);

$total = Discountify::setItems($items)
    ->applyCoupon('TIMELIMITED50')
    ->total();

// Single-Use Coupon

Coupon::add([
    'code' => 'SINGLEUSE50',
    'discount' => 50,
    'singleUse' => true,
    'startDate' => now(),
    'endDate' => now()->addWeek(),
]);

$total = Discountify::setItems($items)
    ->applyCoupon('SINGLEUSE50')
    ->total();

// Restricted User Coupon

Coupon::add([
    'code' => 'RESTRICTED20',
    'discount' => 20,
    'userIds' => [123, 456], // Restricted to user IDs 123 and 456
    'startDate' => now(),
    'endDate' => now()->addWeek(),
]);

$total = Discountify::setItems($items)
    ->applyCoupon('RESTRICTED20', 123) // Applying to user ID 123
    ->total();

// Limited Usage Coupon

Coupon::add([
    'code' => 'LIMITED25',
    'discount' => 25,
    'usageLimit' => 3, // Limited to 3 uses
    'startDate' => now(),
    'endDate' => now()->addWeek(),
]);

$total = Discountify::setItems($items)
    ->applyCoupon('LIMITED25')
    ->total();

@Safemood Safemood self-assigned this Feb 11, 2024
@Safemood Safemood merged commit d45e649 into main Feb 11, 2024
1 check passed
@Safemood Safemood deleted the coupon-based-discounts branch February 18, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant