PHPackages                             tourze/product-ranking-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/product-ranking-bundle

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

tourze/product-ranking-bundle
=============================

产品排行榜管理系统，支持自动计算和手动调整排名

0.0.1(5mo ago)01MITPHPCI failing

Since Nov 13Pushed 4mo agoCompare

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

READMEChangelog (1)Dependencies (42)Versions (2)Used By (0)

Product Ranking Bundle
======================

[](#product-ranking-bundle)

\[[![PHP Version Require](https://camo.githubusercontent.com/a9b78e12ba0f9f6c151d98b307e984aff7b2ddac9561d690501174b160703f24/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f70726f647563742d72616e6b696e672d62756e646c652f726571756972652f706870)](https://camo.githubusercontent.com/a9b78e12ba0f9f6c151d98b307e984aff7b2ddac9561d690501174b160703f24/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f70726f647563742d72616e6b696e672d62756e646c652f726571756972652f706870)\] ()
\[[![License](https://camo.githubusercontent.com/5b71e0243ff53dee0e95ec1a1372462f5acd6321c5bf3676fa7ce55eec079b9f/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f70726f647563742d72616e6b696e672d62756e646c652f6c6963656e7365)](https://camo.githubusercontent.com/5b71e0243ff53dee0e95ec1a1372462f5acd6321c5bf3676fa7ce55eec079b9f/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f70726f647563742d72616e6b696e672d62756e646c652f6c6963656e7365)\] ()
\[[![Build Status](https://github.com/tourze/php-monorepo/workflows/CI/badge.svg)](https://github.com/tourze/php-monorepo/workflows/CI/badge.svg)\] ()
\[[![Coverage Status](https://camo.githubusercontent.com/597d3736c612eb152d4c13a37f4e87afd6af836788df1857d930b70903f9553d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f62616467652e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/597d3736c612eb152d4c13a37f4e87afd6af836788df1857d930b70903f9553d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f62616467652e7376673f6272616e63683d6d6173746572)\] ()

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

A Symfony bundle for managing product rankings with automatic calculation and flexible positioning.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Entities](#entities)
- [Commands](#commands)
- [API Procedures](#api-procedures)
- [Admin Interface](#admin-interface)
- [Dependencies](#dependencies)
- [License](#license)

Features
--------

[](#features)

- **Dynamic Rankings**: Create multiple ranking lists with custom calculation SQL
- **Position Management**: Assign rankings to different display positions
- **Fixed Rankings**: Support for manually fixed product positions
- **Automatic Updates**: Scheduled command to refresh rankings
- **Admin Interface**: EasyAdmin CRUD controllers for management
- **JSON-RPC APIs**: Access ranking data via API procedures

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

[](#installation)

```
composer require tourze/product-ranking-bundle
```

Quick Start
-----------

[](#quick-start)

1. Install the bundle:

    ```
    composer require tourze/product-ranking-bundle
    ```
2. Create a ranking list:

    ```
    $rankingList = new RankingList();
    $rankingList->setTitle('Top Products');
    $rankingList->setValid(true);
    $entityManager->persist($rankingList);
    ```
3. Run ranking calculation:

    ```
    php bin/console product:ranking-list:calc
    ```
4. Access via API:

    ```
    $lists = $jsonRpc->call('GetProductRankingLists');
    ```

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

[](#configuration)

Register the bundle in your Symfony application:

```
// config/bundles.php
return [
    // ...
    ProductRankingBundle\ProductRankingBundle::class => ['all' => true],
];
```

Basic Usage
-----------

[](#basic-usage)

### Creating a Ranking List

[](#creating-a-ranking-list)

```
use ProductRankingBundle\Entity\RankingList;

$rankingList = new RankingList();
$rankingList->setTitle('Top Selling Products');
$rankingList->setSubtitle('Best sellers this month');
$rankingList->setValid(true);
$rankingList->setCount(10); // Top 10 products
$rankingList->setScoreSql('
    SELECT
        p.id,
        COUNT(o.id) as score,
        "High sales volume" as reason
    FROM product_spu p
    JOIN order_item oi ON oi.spu_id = p.id
    JOIN orders o ON o.id = oi.order_id
    WHERE o.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)
    GROUP BY p.id
    ORDER BY score DESC
');
```

### Accessing Rankings via API

[](#accessing-rankings-via-api)

```
// Get all ranking lists
$lists = $jsonRpc->call('GetProductRankingLists');

// Get rankings for homepage position
$homepageLists = $jsonRpc->call('GetProductRankingLists', [
    'position' => 'homepage'
]);

// Check if a product is ranked
$rankings = $jsonRpc->call('GetRankingListBySpu', [
    'spuId' => '123456'
]);
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom SQL Ranking Algorithms

[](#custom-sql-ranking-algorithms)

You can create sophisticated ranking algorithms using SQL:

```
-- Sales performance ranking
SELECT
    p.id,
    (COUNT(o.id) * 0.7 + AVG(r.rating) * 0.3) as score,
    CONCAT('Sales: ', COUNT(o.id), ', Avg Rating: ', ROUND(AVG(r.rating), 2)) as reason
FROM product_spu p
LEFT JOIN order_item oi ON oi.spu_id = p.id
LEFT JOIN orders o ON o.id = oi.order_id AND o.status = 'completed'
LEFT JOIN product_review r ON r.spu_id = p.id
WHERE p.valid = 1
GROUP BY p.id
HAVING COUNT(o.id) >= 5
ORDER BY score DESC
```

### Managing Fixed Positions

[](#managing-fixed-positions)

Manually set fixed positions for specific products:

```
use ProductRankingBundle\Entity\RankingItem;

$item = new RankingItem();
$item->setList($rankingList);
$item->setSpuId('special-product-id');
$item->setNumber(1); // Fixed at position 1
$item->setFixed(true);
$item->setScore(999);
$item->setTextReason('Featured product');
```

### Scheduling Updates

[](#scheduling-updates)

The ranking calculation is automatically scheduled but can also be triggered manually:

```
# Manual update
php bin/console product:ranking-list:calc

# Add to crontab for custom scheduling
*/15 * * * * php /path/to/project/bin/console product:ranking-list:calc
```

Performance Optimization
------------------------

[](#performance-optimization)

For large datasets, consider:

1. **Index optimization**: Ensure proper database indexes on fields used in your SQL
2. **Batch processing**: Use query builders for large result sets
3. **Caching**: Implement caching for frequently accessed rankings

```
// Example: Optimized query with pagination
$items = $this->itemRepository->createQueryBuilder('i')
    ->where('i.list = :list')
    ->setParameter('list', $list)
    ->setMaxResults(100)
    ->getQuery()
    ->toIterable();
```

Entities
--------

[](#entities)

### RankingList

[](#rankinglist)

Represents a product ranking list with title, subtitle, logo, and calculation SQL.

### RankingItem

[](#rankingitem)

Individual items within a ranking list, including product SPU, score, and position.

### RankingPosition

[](#rankingposition)

Display positions where ranking lists can be shown (e.g., homepage, category page).

Commands
--------

[](#commands)

### product:ranking-list:calc

[](#productranking-listcalc)

Calculates and updates all active ranking lists based on their SQL formulas.

```
php bin/console product:ranking-list:calc
```

This command:

- Runs every 30 minutes via cron (configured with `@AsCronTask`)
- Processes all active ranking lists
- Executes custom SQL to calculate product scores
- Updates ranking positions while preserving fixed items
- Removes items exceeding the list count limit

API Procedures
--------------

[](#api-procedures)

### GetProductRankingLists

[](#getproductrankinglists)

Retrieve all active ranking lists, optionally filtered by position.

### GetRankingListBySpu

[](#getrankinglistbyspu)

Get ranking information for a specific product SPU.

Admin Interface
---------------

[](#admin-interface)

The bundle provides EasyAdmin CRUD controllers for:

- Managing ranking lists
- Viewing and editing ranking items
- Configuring display positions

Dependencies
------------

[](#dependencies)

- Symfony 7.3+
- Doctrine ORM 3.0+
- Doctrine DBAL 4.0+
- tourze/doctrine-snowflake-bundle
- tourze/doctrine-timestamp-bundle
- tourze/doctrine-user-bundle
- tourze/product-core-bundle
- tourze/json-rpc-core
- tourze/json-rpc-cache-bundle
- tourze/symfony-cron-job-bundle
- tourze/easy-admin-extra-bundle

License
-------

[](#license)

This bundle is licensed under the MIT License.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance72

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity25

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

Unknown

Total

1

Last Release

179d 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-product-ranking-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/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.4k](/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)
