Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Degica on Spree

Degica on Spree

Talk at Tokyo Rubyist Meetup, May 14, 2014. http://trbmeetup.doorkeeper.jp/events/10739

Chris Salzberg

May 14, 2014
Tweet

More Decks by Chris Salzberg

Other Decks in Programming

Transcript

  1. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Outline 1. About Me 2. Degica and Spree 3. Spree and the State Machine 4. Extending Spree
  2. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    About me Montreal, Canada Amsterdam Tokyo
  3. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Company Profile • Leading E-Commerce Solutions Provider in Japan • Over 50 stores serving thousands of products • Partnerships with Valve, AVG, Kadogawa Games • Offices in Kichojoji, Victoria, Paris, San Francisco • Over $16 million to partners
  4. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Degica Stack Customer Support Customer Support Marketing Marketing Design / Localization Design / Localization Full-stack E-Commerce Solutions Provider Logistics Logistics Technology Platform Technology Platform Cart System Cart System Payment Processing Payment Processing Website Hosting Website Hosting
  5. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree: the after spree-flexible-weight-rate spree-license-key spree-multi-domain spree-i18n spree-kana spree-payment-method-fee spree-add-on spree-auth-devise
  6. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    RESTful Rails SELECT CREATE UPDATE GET /items POST /item/123 PUT /item/123 GET /item/123 Item 1 Item 3 Item 20 Item 15 Item 123 Item 123 Item 123 SELECT
  7. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Stateful Spree • Spree breaks RESTful conventions to create a stateful checkout flow • Checkout GET and PUT requests processed according to session cookie and state of order core/config/routes.rb
  8. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Checkout State • State persistence: – Session cookie stores current order_id – Database stores current state of the order order_id: 123 order_id: 123 GET /checkout redirect_to '/checkout/cart/edit' SELECT session id state 122 ... 123 'cart' 124 ...
  9. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    StateMachine • Spree uses StateMachine to persist state • Spree ActiveRecord models with state machines: – Spree::Order – Spree::Payment – Spree::Shipment
  10. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Order Checkout Flow core/app/models/spree/order.rb
  11. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Transition Callbacks core/app/models/spree/order/checkout.rb
  12. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Transition Callbacks core/app/models/spree/order/checkout.rb
  13. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Like Clockwork • Core components linked together via state transitions • Each part extendible, and also their connections Order Shipment Payment
  14. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Flexibile and Extendible • Modular – api, frontend, backend, cmd, core, sample • Extendible – Checkout flow DSL, custom transition callbacks – Custom User class – Override elements of views – Extend base classes with class decorators v
  15. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree License Key • Support for electronic license keys – No shipping cost, immediate delivery by email – License keys pulled from database or external API app/models/spree/license_key.rb
  16. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Transition Callbacks app/models/spree/shipment_observer.rb
  17. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Model Decorators • Add methods to core Spree classes • Override core class methods app/models/spree/shipment_decorator.rb
  18. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    View Overrides • Hooks to override elements of core views • Uses Deface gem
  19. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Built to Last • Designed based on feedback from real deployments • Imposes reasonable constraints, to give you maximum flexibility • Supported by large and growing open source community • And built on Ruby/Rails!