PHPackages                             tourze/order-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. tourze/order-core-bundle

ActiveSymfony-bundle

tourze/order-core-bundle
========================

综合订单管理核心模块 - 提供购物车、订单创建、支付处理、发货追踪等完整电商订单功能

1.0.5(6mo ago)01705MITPHPCI failing

Since Nov 5Pushed 4mo agoCompare

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

READMEChangelog (6)Dependencies (98)Versions (7)Used By (5)

Order Core Bundle
=================

[](#order-core-bundle)

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

A comprehensive order management core module for Symfony applications that provides complete e-commerce order functionality including shopping cart, order creation, payment processing, and delivery tracking.

Features
--------

[](#features)

### 🛒 Complete Order Lifecycle Management

[](#-complete-order-lifecycle-management)

- **Order Creation**: Full shopping cart to order conversion workflow
- **Payment Processing**: Multi-payment method support with status tracking
- **Order States**: Comprehensive state management (Created, Paid, Shipped, Received, Canceled, etc.)
- **Automated Processing**: Scheduled tasks for order expiration and cancellation

### 📦 Order Components

[](#-order-components)

- **Contract**: Main order entity with comprehensive metadata
- **OrderProduct**: Product line items with quantity and pricing
- **OrderPrice**: Price breakdown and cost calculation
- **OrderContact**: Customer contact and shipping information
- **PayOrder**: Payment transaction records
- **OrderLog**: Complete order history and audit trail

### 🔄 Event-Driven Architecture

[](#-event-driven-architecture)

- **Order Events**: Comprehensive event system for order lifecycle changes
- **Payment Events**: Payment status and refund event handling
- **Stock Events**: Automatic stock management integration
- **Credit Events**: User credit/points integration

### 🛡️ Enterprise Features

[](#️-enterprise-features)

- **Optimistic Locking**: Prevents concurrent modification conflicts
- **Audit Trail**: Complete change tracking with user attribution
- **IP Tracking**: Network address logging for security
- **Snowflake IDs**: Distributed unique identifier generation

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 7.3+
- Doctrine ORM 3.0+
- MySQL/PostgreSQL database

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

[](#installation)

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

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

[](#configuration)

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

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

Console Commands
----------------

[](#console-commands)

### `order:cancel-expired`

[](#ordercancel-expired)

Automatically cancels expired unpaid orders and releases stock.

**Class**: `OrderCoreBundle\Command\CancelExpiredOrdersCommand`

**Usage**:

```
# Run normally
php bin/console order:cancel-expired

# Dry run to see what would be cancelled
php bin/console order:cancel-expired --dry-run

# Process specific number of orders
php bin/console order:cancel-expired --limit=500

# Custom batch size
php bin/console order:cancel-expired --batch-size=50
```

**Features**:

- Runs every minute via cron job
- Batch processing for memory efficiency
- Comprehensive logging and error handling
- Stock release through event system
- Progress tracking with configurable limits

### `order:expire-no-received`

[](#orderexpire-no-received)

Processes orders that have been shipped but not received within the timeout period.

**Class**: `OrderCoreBundle\Command\ExpireNoReceivedOrderCommand`

**Usage**:

```
php bin/console order:expire-no-received
```

**Features**:

- Runs every 15 minutes via cron job
- Automatic order state transition to EXPIRED
- Event dispatch for customer notifications
- System user attribution for automated operations

### `order:sync-sku-sales-real-total`

[](#ordersync-sku-sales-real-total)

Synchronizes actual sales totals for all SKU products.

**Class**: `OrderCoreBundle\Command\SyncSkuSalesRealTotalCommand`

**Usage**:

```
php bin/console order:sync-sku-sales-real-total
```

**Features**:

- Calculates real sales from completed orders
- Updates SKU sales metrics
- Efficient batch processing
- Only updates when sales have increased

Order States
------------

[](#order-states)

The bundle supports comprehensive order state management:

StateCodeDescriptionCreated`init`Order has been created, awaiting paymentPaying`paying`Payment is being processedPaid`paid`Payment completed, awaiting shipmentPartially Shipped`part-shipped`Some items have been shippedShipped`shipped`All items have been shippedReceived`received`Order has been completedCanceled`canceled`Order has been cancelledExpired`expired`Order has expired (timeout)After Sales Processing`aftersales-ing`Return/refund in progressAfter Sales Success`aftersales-success`Return/refund completedAfter Sales Failed`aftersales-failed`Return/refund failedAuditing`auditing`Order is under reviewAccepted`accept`Order has been acceptedRejected`reject`Order has been rejectedException`exception`Order processing failedEvents
------

[](#events)

The bundle provides a rich event system for integration:

### Order Lifecycle Events

[](#order-lifecycle-events)

- `BeforeOrderCreatedEvent`: Fired before order creation
- `AfterOrderCreatedEvent`: Fired after order creation
- `OrderPaidEvent`: Fired when order is paid
- `OrderReceivedEvent`: Fired when order is received
- `AfterOrderCancelEvent`: Fired after order cancellation

### Payment Events

[](#payment-events)

- `BeforePriceRefundEvent`: Fired before price refund
- `AfterPriceRefundEvent`: Fired after price refund

### Supplier Events

[](#supplier-events)

- `SupplierOrderReceivedEvent`: Supplier order received
- `SupplierExpireAcceptOrderEvent`: Supplier acceptance timeout

### Special Events

[](#special-events)

- `AutoExpireOrderStateEvent`: Automatic order expiration
- `OrderCheckoutEvent`: Order checkout process
- `ViewOrderEvent`: Order viewing (for permissions/logging)

Entities
--------

[](#entities)

### Contract (Main Order)

[](#contract-main-order)

```
use OrderCoreBundle\Entity\Contract;

$order = new Contract();
$order->setState(OrderState::INIT);
$order->setUser($user);
$order->setSn('C1234567890');
```

### Order Product

[](#order-product)

```
use OrderCoreBundle\Entity\OrderProduct;

$product = new OrderProduct();
$product->setContract($order);
$product->setSku($sku);
$product->setQuantity(2);
$product->setPrice(99.99);
```

### Order Price

[](#order-price)

```
use OrderCoreBundle\Entity\OrderPrice;

$price = new OrderPrice();
$price->setContract($order);
$price->setAmount(199.98);
$price->setType('total');
```

Services
--------

[](#services)

### Core Services

[](#core-services)

- `OrderService`: Main order management operations
- `PriceService`: Price calculation and management
- `ContractService`: Contract/order lifecycle management
- `CollectionService`: Order collection and reporting

### Price Services

[](#price-services)

- `PriceCalculationHelper`: Complex price calculations
- `PriceFormatter`: Price formatting and display
- `PriceAggregator`: Price aggregation for reporting
- `ProductPriceValidator`: Price validation logic

### Administration

[](#administration)

- `AdminMenu`: EasyAdmin integration for order management
- `AttributeControllerLoader`: Dynamic controller loading

Integration Examples
--------------------

[](#integration-examples)

### Creating an Order

[](#creating-an-order)

```
use OrderCoreBundle\Service\OrderService;
use OrderCoreBundle\DTO\ProductCheckoutItem;

class OrderController
{
    public function __construct(
        private OrderService $orderService,
    ) {}

    public function createOrder(): Contract
    {
        $items = [
            new ProductCheckoutItem($sku1, 2),
            new ProductCheckoutItem($sku2, 1),
        ];

        return $this->orderService->createOrder($user, $items, $contactInfo);
    }
}
```

### Processing Payment

[](#processing-payment)

```
use OrderCoreBundle\Event\OrderPaidEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class PaymentController
{
    public function __construct(
        private EventDispatcherInterface $eventDispatcher,
    ) {}

    public function handlePaymentSuccess(Contract $order): void
    {
        $order->setState(OrderState::PAID);

        $event = new OrderPaidEvent();
        $event->setContract($order);
        $this->eventDispatcher->dispatch($event);
    }
}
```

### Event Listener for Stock Management

[](#event-listener-for-stock-management)

```
use OrderCoreBundle\Event\OrderPaidEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

class StockManager
{
    #[AsEventListener(event: OrderPaidEvent::class)]
    public function onOrderPaid(OrderPaidEvent $event): void
    {
        $order = $event->getContract();

        foreach ($order->getProducts() as $product) {
            $this->stockService->reserveStock(
                $product->getSku(),
                $product->getQuantity()
            );
        }
    }
}
```

EasyAdmin Integration
---------------------

[](#easyadmin-integration)

The bundle provides EasyAdmin controllers for order management:

- `OrderOrderCrudController`: Main order management
- `OrderOrderPriceCrudController`: Price management
- `OrderOrderProductCrudController`: Product line items
- `OrderOrderContactCrudController`: Contact information
- `OrderOrderLogCrudController`: Order history
- `OrderPayOrderCrudController`: Payment records

JsonRPC Procedures
------------------

[](#jsonrpc-procedures)

The bundle exposes JsonRPC procedures for remote integration:

- `ReceiveUserOrder`: Order receiving operations
- `CancelUserOrder`: Order cancellation
- `CancelUserProduct`: Product-level cancellation
- `UserCheckoutOrder`: Checkout process
- `GetOrderTrackLogs`: Order tracking information

Testing
-------

[](#testing)

The bundle includes comprehensive test fixtures:

```
# Load test fixtures
php bin/console doctrine:fixtures:load --group=OrderCoreBundle
```

Available fixtures:

- `OrderProductFixtures`: Product data
- `OrderLogFixtures`: Order history
- `PayOrderFixtures`: Payment records
- `OrderContactFixtures`: Contact information
- `OrderPriceFixtures`: Price data

Statistics
----------

[](#statistics)

The bundle provides metrics for order statistics:

- `OrderCountMetricProvider`: Order count metrics
- `RevenueMetricProvider`: Revenue calculation metrics

Cron Job Configuration
----------------------

[](#cron-job-configuration)

Add to your crontab:

```
# Cancel expired orders (every minute)
* * * * * php /path/to/bin/console order:cancel-expired

# Process non-received orders (every 15 minutes)
*/15 * * * * php /path/to/bin/console order:expire-no-received

# Sync sales data (daily at 2 AM)
0 2 * * * php /path/to/bin/console order:sync-sku-sales-real-total
```

Performance Considerations
--------------------------

[](#performance-considerations)

- **Batch Processing**: All commands use configurable batch sizes
- **Memory Management**: Entity manager clearing in long-running processes
- **Database Indexing**: Strategic indexes on frequently queried fields
- **Caching**: Integrates with Symfony cache contracts
- **Background Processing**: Async event handling for non-blocking operations

Security
--------

[](#security)

- **User Attribution**: All operations track the performing user
- **IP Logging**: Network address logging for security audit
- **Optimistic Locking**: Prevents concurrent modifications
- **Input Validation**: Comprehensive validation using Symfony constraints
- **Rate Limiting**: Compatible with Symfony rate limiting components

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

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Submit a pull request

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

For questions and support, please open an issue in the repository.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance71

Regular maintenance activity

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity39

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 ~1 days

Total

6

Last Release

185d 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 (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

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

7310.3k29](/packages/open-dxp-opendxp)[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)

PHPackages © 2026

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