Spree Commerce

Try It Now

Core Extensions

Posted on May 14, 2008 by Sean Schofield

Now that the basic extension mechanism is in place I am experimenting with the concept of so-called “core extensions.” These are extensions that will ship with the gem and provide core functionality. They reside in #{SPREE_ROOT}/vendor/extensions. NOTE: This is not the same as #{RAILS_ROOT}/vendor/extensions. So far we have a PaymentGateway and TaxCalculator extension. The idea behind core extensions is to make it easier for developers to customize Spree to fit their own needs. Taxes in particular are likely to differ depending on your client and/or location. It will soon be a simple matter of turning off the default extension and dropping in your own replacement.

The payment gateway extension is not very interesting at the moment. Right now it always returns the BogusGateway, but in another day or two it will be possible to configure the Ã…ctiveMerchant gateway of your choice through a nice admin interface. No more configuring the gateways in environment.rb! The other cool thing it does is to mixin a payment_gateway method into Spree::BaseController. This is the method that returns the gateway to be used for processing credit cards. If for some reason you don’t want to use ActiveMerchant to talk to your gateway you could plug in something else here.

While it’s unlikely you will need to scrap ActiveMerchant (since you can always write your own ActiveMerchant implementation for your new gateway), you will probably have a definite need to customize your tax logic. The current TaxCalculator extension will allow you to set tax rates for individual states. If the order ships to that state then all items will be taxed at that rate. There is no admin menu item for this yet, but you can see the rate interface at admin/tax_rates if you are running the latest source (demo has yet to be upgraded.)

Although this is fairly crude, it’s also pretty much what you’re stuck with in many of the existing commerce platforms. Even though we will be adding to this basic calculator over time, we fully expect that your needs will go beyond this. This is where you unfortunately have to earn your money as a programmer and do a little programming. Its a fairly easy process to create your own extension. Documentation on extensions is ongoing but there is an in-progress tutorial in the Developer’s Guide. Stay tuned for more information on making your own extensions. We are also working on some interesting taxonomy features that should make it possible to mark only certain items as being taxable.