PHPackages                             tourze/coupon-core-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/coupon-core-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/coupon-core-bundle
=========================

优惠券核心模块，提供优惠券管理、券码生成和验证功能

0.1.2(5mo ago)04205MITPHPCI failing

Since Jun 1Pushed 4mo agoCompare

[ Source](https://github.com/tourze/coupon-core-bundle)[ Packagist](https://packagist.org/packages/tourze/coupon-core-bundle)[ RSS](/packages/tourze-coupon-core-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (69)Versions (6)Used By (5)

coupon-core-bundle
==================

[](#coupon-core-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/d06a7a46f746642ce69cf5440675fe234da00c9d54e655273cd7e86948d56e72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f636f75706f6e2d636f72652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-core-bundle)[![Total Downloads](https://camo.githubusercontent.com/3b259d9fa6ac09d4e061340dd88097816d42b2a98e231afca06b2a1970615abe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f636f75706f6e2d636f72652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-core-bundle)[![PHP Version Require](https://camo.githubusercontent.com/8da0c9c843cb9cdf25bd4f191f346831b56364caf36f6d994bf8f97329b006be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f746f75727a652f636f75706f6e2d636f72652d62756e646c652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-core-bundle)[![License](https://camo.githubusercontent.com/5b2172eec8f3d58336a14c1dd2d7b6104d386ceb096d3dfc208c60f30ae60a83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f636f75706f6e2d636f72652d62756e646c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-core-bundle)[![Code Coverage](https://camo.githubusercontent.com/547089e4e915b61c44ab6efe685110dd86397252908ad168c3e15f84995968ce/68747470733a2f2f636f6465636f762e696f2f67682f746f75727a652f636f75706f6e2d636f72652d62756e646c652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tourze/coupon-core-bundle)

A Symfony bundle providing core functionality for coupon management, including coupon categories, batches, codes, discounts, and channel management.

Features
--------

[](#features)

- **Coupon Management**: Comprehensive coupon lifecycle management
- **Batch Operations**: Create and manage coupon batches
- **Channel Integration**: Multi-channel coupon distribution
- **Discount Rules**: Flexible discount configurations
- **Automatic Expiration**: Scheduled tasks for handling expired coupons
- **Statistics Tracking**: Built-in coupon usage statistics

Installation
------------

[](#installation)

```
composer require tourze/coupon-core-bundle
```

Bundle Registration
-------------------

[](#bundle-registration)

Register the bundle in your `config/bundles.php`:

```
return [
    // ...
    Tourze\CouponCoreBundle\CouponCoreBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

### Database Migration

[](#database-migration)

Run migrations to create the necessary database tables:

```
php bin/console doctrine:migrations:migrate
```

### Console Commands

[](#console-commands)

The bundle provides the following console commands:

#### Check Expired Categories

[](#check-expired-categories)

```
php bin/console coupon:check-expired-category
```

This command checks coupon categories for expiration and marks expired categories as invalid. It runs as a cron task every minute to ensure categories are automatically invalidated when they expire.

**Features:**

- Automatically marks categories as invalid when outside their valid time range
- Runs every minute via cron task integration
- Ensures coupon availability is properly controlled by time constraints

#### Revoke Expired Codes

[](#revoke-expired-codes)

```
php bin/console coupon:revoke-expired-code
```

This command automatically revokes expired coupon codes that haven't been used. It processes up to 500 codes per execution to manage system load.

**Features:**

- Finds unused coupon codes that have passed their expiration date
- Marks expired codes as invalid
- Processes in batches of 500 codes per run
- Prevents expired coupons from being redeemed

Core Entities
-------------

[](#core-entities)

### Category

[](#category)

Represents coupon categories with validation time ranges.

### Batch

[](#batch)

Groups coupons for batch operations and management.

### Code

[](#code)

Individual coupon codes with unique identifiers and validation status.

### Coupon

[](#coupon)

The main coupon entity linking categories, batches, and codes.

### Channel

[](#channel)

Distribution channels for coupon allocation.

### Discount

[](#discount)

Discount rules and configurations for coupons.

### CouponStat

[](#couponstat)

Statistical data for coupon usage tracking.

Usage Examples
--------------

[](#usage-examples)

### Creating a Coupon Category

[](#creating-a-coupon-category)

```
use Tourze\CouponCoreBundle\Entity\Category;
use Doctrine\ORM\EntityManagerInterface;

$category = new Category();
$category->setName('Summer Sale');
$category->setStartTime(new \DateTime('2024-06-01'));
$category->setEndTime(new \DateTime('2024-08-31'));
$category->setValid(true);

$entityManager->persist($category);
$entityManager->flush();
```

### Generating Coupon Codes

[](#generating-coupon-codes)

```
use Tourze\CouponCoreBundle\Entity\Code;
use Tourze\CouponCoreBundle\Entity\Batch;

$batch = new Batch();
$batch->setName('SUMMER2024');
$batch->setCategory($category);

for ($i = 0; $i < 100; $i++) {
    $code = new Code();
    $code->setCode(generateUniqueCode()); // Your code generation logic
    $code->setBatch($batch);
    $code->setValid(true);
    $code->setExpireTime(new \DateTime('+30 days'));

    $entityManager->persist($code);
}

$entityManager->flush();
```

Integration with Other Bundles
------------------------------

[](#integration-with-other-bundles)

This bundle integrates with:

- `tourze/benefit-bundle` - For benefit calculations
- `tourze/condition-system-bundle` - For conditional coupon rules
- `tourze/doctrine-snowflake-bundle` - For unique ID generation
- `tourze/symfony-cron-job-bundle` - For scheduled tasks

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/coupon-core-bundle/tests
```

Contributing
------------

[](#contributing)

Please ensure all tests pass and code meets PHPStan level 8 standards before submitting pull requests.

License
-------

[](#license)

This bundle is released under the MIT License.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance72

Regular maintenance activity

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Total

5

Last Release

172d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-coupon-core-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-coupon-core-bundle/health.svg)](https://phpackages.com/packages/tourze-coupon-core-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
