Jan 17

Frtrains Shop – promotion support

It’s been a year since the V2 of Frtrains Shop has been deployed in production. A lot of updates and fixes has been made, but not a lot of new features.

Christmas approaching, I decided to implement a promotion system support, and a smart enough to allow specific object promotion and category – price range or even  member role promotion.

What is a promotion ?

First of all, a promotion can be divided in two things : the conditions that has to be respected for the promotion to be applied and the discount applied to the object with this promotion.

Promotion discount

The discount applied is quite simple : it’s a percent of the object/cart’s price or it’s an absolute value (ex. 10 euros) which is used to reduce the original price.

Promotion conditions

The conditions used to determine if a promotion is applied to an object is a little more complex object. I used a tree with a strategy pattern.

Every node of the tree is a condition and can have sub-conditions (sub-trees or leafs). A typical leaf is an comparision condition (object’s price is less than 100 euros). A sub-tree is a condition agregations, tipycally the and or the or keywords used in PHP. There is two of those agregations implemented : the or agregation and the and agregation.

For the strategy pattern, I took a look at Doctrine 2’s Strategy pattern. In DB, every tree node and leafs are the same entity. This entity contains two fields to determine it’s behavior : a strategy field that determine which strategy has to be used to do the comparison, and a parameter field containing a map of parameter => value to set more specifically the strategy behavior. For example, if the condition to check is object’s price < 100, the strategy used will be comparisonStrategy and the parameters will be  {type => less_than, value => 100}.

User interface

This promotion system can target every specific object or a wide range of objects, depending on the configuration. To allow every possible configurations, I used a dynamic JS interface with AngularJS. The user can set every conditions and can create sub-conditions.

The user interface (in french, because Frtrains.com is mainly a french website) :

Shop promotion interface

Shop promotion interface

As you can see, there is four blocs. The first one (Nouvelle promotion) has promotion-specific configuration (date of validity, possibly a code limiting the access to specific users). The second one (Conditions pour l’application de la promotion) is the promotion conditions. The third one (Rabais à appliquer) is the promotion discount and the last one is used to save / remove a promotion.

Here an example of agregated conditions :

Conditions in shop promotions

Conditions in shop promotions


This promotion system has been successfully used during last december. It’s smart enough to allow a really find granularity in object selection and the interface is still quite simple.

You can try it when promotions are available in the Frtrains’Shop website 😉


Jan 17

Widget management bundle 0.2.0 now support annotations

I didn’t had much time to work on my personal projects this past year, but I had time to make a really useful update.

The Widget management bundle now support a Widget annotation. There is two ways to use it.

  1. The service way : any method in any service with the Widget annotation in automatically added to the list of active widgets.
  2. The directory way : every class in the MyBundle/Widget directory is parsed to find any method with a Widget annotation is automatically added to the list of active widgets.

Those two new behaviors can be disabled through the configuration.

More informations in the Github repository.


Feb 20

Widget management bundle for Symfony 2 / Twig

Like every developer, I like to have the most beautiful architecture when I work on a project.

For me, a beautiful architecture allow me to add useful informations on views withouth dependencies. For example : an administration page show every action possible, like simple member edition features. When a new bundle is added to the project, it should automatically add possible actions (widgets) in administration page, like the Parameters app in iOS. This bundle should also be removable withouth any modifications on other bundles code.

To do so, I created ElendevWidgetBundle, This bundle provide a simple twig method which include widgets in templates. The widgets are identified with a tag and are added to specifics places on views.


<div>My template with some html...</div>
<div>My widgets place : {{ widgets('my_tag') }}</div>
<div>End of my template...</div>

In the example above, every widget with the tag my_tag is added in the view. The widget is a simple tagged service method.

This bundle allow to create widgets places in existing views and when a new feature is added, it can plug widgets everywhere it’s needed withouth current view modification.

For more informations, you can take a look at the ElendevWidgetBundle’s GitHub.

Jan 16

Frtrains’ e-commerce : Shop v2

Frtrains.com is a website about trains (mainly french and swiss trains). You will find some articles about trains, but first of all, you’ll be able to buy trains through the Shop.

The first version was quite old and I’ve worked hard to develop a version 2. Now the Shop v2 is out and in production, using Symfony2.

For more informations, you can read this.

Take a look and maybe buy something ^^



Dec 11



The AppManager help you manage your application. You can have multiple versions of an application online (for tests and rollback purpose), the App Manager allow you to choose which one is the one in production.

This application is really useful in mutual hosting, where you can’t go with SSH to launch Symfony2 commands. You are able to clear/warmup cache, dump assets, install assetics directly from the web interface.

In other words : you can easily have a good control of your application.

Current status

The AppManagerBundle is actually under heavy developments but is already used on production. I will provide a standalone application (provide a symfony2 application including AppManagerBundle) as soon as the bundle is table enough.

Official informations

To keep as much as possible informations in the same place, I decided to create the official application page on GitHub instead of having a page on my blog. For more informations, you can go to the official project page or access directly the GitHub repository.

Enjoy !



Older posts «