Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ti Ext Coupons Laravel Package

tastyigniter/ti-ext-coupons

TastyIgniter Coupons extension adds fixed or percentage discounts with advanced rules like minimum spend, day/time limits, and location targeting. Create time-sensitive or seasonal promotions to boost sales and reward customers.

View on GitHub
Deep Wiki
Context7

title: "Coupons" section: "extensions" sortOrder: 50

Installation

You can install the extension via composer using the following command:

composer require tastyigniter/ti-ext-coupons -W

Run the database migrations to create the required tables:

php artisan igniter:up

Getting started

This extension provides a cart condition that allows you apply coupons to the cart.

To enable the coupon condition, go to Manage > Settings > Cart Settings, toggle on the coupon cart condition.

To create a new coupon, navigate to Marketing > Coupons and click the New Coupon button. You can configure the coupon details, such as the discount type, amount, and usage restrictions.

Once you have created a coupon, customers can apply it during checkout by entering the coupon code in the cart.

Usage

This section covers how to integrate the Coupons extension into your own extension if you need to apply your custom coupons to the cart or redeem them on orders. The Coupons extension provides a simple API for managing coupons, applying them to the cart, and redeeming them on orders.

Applying coupons to the cart

You can apply a coupon to a cart instance by using the coupon cart condition. Here is an example of how to apply a coupon to the cart from your frontend component:

use Igniter\Cart\Facades\Cart;

$couponCondition = Cart::getCondition('coupon');

$couponCondition->setMetaData(['code' => $code]);

Cart::loadCondition($couponCondition);

And check if the coupon condition is valid and has been applied to the cart totals using the isValid method:

if (Cart::getCondition('coupon')->isValid()) {
    // Do something...
}

You can also clear the coupon from the cart using the removeCondition method:

Cart::removeCondition('coupon');

Redeeming coupons

You may want to programmatically redeem a coupon when a customer completes an order. You can do this by using the redeemCoupon method on the order model:

use Igniter\Cart\Models\Order;

// A new pending order is created
$order = Order::create($attributes);

// Log the coupon history using the coupon cart condition
$couponCondition = Cart::conditions()->get('coupon');
$order->logCouponHistory($couponCondition);

// Add a coupon total to the order_totals table, required for the coupon to be redeemed
$order->addOrUpdateOrderTotal([
    'code' => 'coupon',
    'title' => 'Coupon',
    'value' => -10.0,
    'priority' => 100,
    'is_summable' => true,
]);

// Redeem the coupon by setting the status on the coupon history to true
$order->redeemCoupon();

Permissions

The Coupons extension registers the following permission:

  • Admin.Coupons: Control who can manage coupons in the admin area.

For more on restricting access to the admin area, see the TastyIgniter Permissions documentation.

Events

The Coupons extension triggers the following events:

  • igniter.cart.beforeApplyCoupon: Triggered before applying a coupon to the cart. Passes the coupon code as argument.
  • couponHistory.beforeAddHistory: Triggered before adding a coupon history record. Passes the coupon history model, coupon cart condition object, customer model, coupon model as arguments.
  • admin.order.couponRedeemed: Triggered after a coupon has been redeemed on an order. Passes the coupon history model as argument.

Here is an example of hooking an event in the boot method of an extension class:

use Illuminate\Support\Facades\Event;

public function boot()
{
    Event::listen('igniter.cart.beforeApplyCoupon', function ($code) {
        // ...
    });
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor