We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22656
    • 121 Posts

    I have a requirement to build a pricing system which will employ complex pricing rules like so:

    Product "Widget" cost $100

    Price Reduction Rules:

    If date between Jan & Mar 10% off
    5% off if > 2 items purchased
    -$10 if buyer spent $1000 in past

    Extra Charge Rules

    Europe + $50 shipping
    USA + $10 shipping
    If something = 'whatever' add 5% charge

    Main requirement is ability to quickly add a new rule without having to modify coding or at least minimal coding changes. Also the ability to execute lots of rules on the price in the most efficient manner possible. I have come across the following post: http://www.jonathanlevin.co.uk/2008/02/using-business-rules-in-mysql-overview.html, describing the use of decision trees and tables to accomplish such a task.

    The whole concept of business rules and business logic in PHP is slightly "underdeveloped" for the lack of a better word, as it seems most systems use java/.net to implement such logic & rule systems, particularly the banking industry for example.

    Would anyone have any experience or insight into how this could be applied to MODx or PHP in general?

    I have come across some other resources, ie
    in .net - http://rule.codeeffects.com/
    in .php - http://www.devx.com/webdev/Article/42441/0/page/3
    http://stackoverflow.com/questions/2069887/php-business-rule-engine
    http://www.swindle.net/php-rules/
    http://en.wikipedia.org/wiki/Rete_algorithm
    http://sourceforge.net/projects/phprules/

    I keep thinking simple decision tables in MYSQL will suffice for this, however I am attracted by these big rule engines which could in essence ensure this rule processing is as efficient as possible, and the ability to scale it up is only restricted by memory.

    Thoughts?
      • 22656
      • 121 Posts
      Hmmm, there is really not a lot out there in php.

      Now I am thinking setting up drools (java) http://www.jboss.org/drools/
      Theoretically - install a tomcat server on port 8080, alongside IIS/Apache on port 80. Let php communicate with drools using XML and a rule engine is born.

      Well... either that or http://www.swindle.net/php-rules/.

      I really do not want to migrate to .net for this project, and it all seems to be pointing that way (lots of rule engines to use)...
        • 33968
        • 863 Posts
        Out of curiosity, who will be creating the new business rules? It seems that, even if they don't go into the php code they will still need to have the technical know-how to either add rules to the database or in whatever engine you end up using.

        Is the main reason you're heading this way just that - to avoid further developer input? Is it not possible to think through the possible rule scenarios and then add some kind of interface to allow an admin to adjust or create different permutations of them to fit different circumstances? I've done something along those lines (although perhaps a bit more restricted than your requirements) with a discount rules component in xPDO.

        I'm very interested to hear of some other ways about it, and especially if you manage to integrate one of those rules engines with MODX smiley [ed. note: okyanet last edited this post 14 years, 1 month ago.]
          • 22656
          • 121 Posts
          Main reason for using a rule engine is the complexity of these rules, and the fact a new rule might come along at any time to be added and used, with varying level of complexity.

          Integrating these rules directly in PHP code possibly equals pointing a loaded shotgun in ones head. After a while you are bound to end up with very unmanageable, spaghetti code which takes forever to run. In theory, these rule engines will allow you to add 10, 100 rules to an item and still experience no slowdown. This is my main reason for attempting to use a rule engine.

          Project requirement is to have rules of varying complexity attached to products housed in MYSQL.

          Rule management would hopefully be used by non-techies (at least once all the new ones have been setup by devs)

          Currently stuck between choosing:

            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Could MIGxDB and a custom manager page be used for this?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4172
              • 5,888 Posts
              I can't think, how you want to create a decision-table for this conditions:

              Price Reduction Rules:
              If date between Jan & Mar 10% off
              5% off if > 2 items purchased
              -$10 if buyer spent $1000 in past

              for stuff like that I create a MIGX-TV (on a special setting-resource or in a special setting-table) with fields like that:

              reduction (amount)
              reduction_type (total or percent)
              snippet (a snippet which calculates the reduction for this rule)
              active (if the rule is active)
              properties (additional properties you'l send to the snippet, examples: 'minitems:2' or 'startmonth:1,endmonth:3' or 'minspend:1000' )

              then you'll have a loop, which runs the snippets.

              you can add multiple rules and order them by dragging.
              for new calculation-types, just create a new snippet.






              [ed. note: Bruno17 last edited this post 14 years, 1 month ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!