Degica on Spree

Degica on Spree

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

05fdba1ae381f24512e977f8fe2697b4?s=128

Chris Salzberg

May 14, 2014
Tweet

Transcript

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

    Degica on Spree Chris Salzberg
  2. 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
  3. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    About Me
  4. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

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

    @shioyama
  6. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Degica and Spree
  7. 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
  8. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Partners & Products
  9. 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
  10. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

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

    Spree: the before
  12. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree: the before
  13. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree: the before
  14. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree: the after
  15. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Spree: the after
  16. 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
  17. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    3. Spree and State Machines
  18. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    State Machine
  19. 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
  20. 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
  21. 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 ...
  22. 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
  23. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Order State Machine
  24. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

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

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

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

    Payment Flow
  28. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Payment Flow
  29. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Shipment Flow
  30. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Shipment Flow
  31. 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
  32. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    4. Extending Spree
  33. 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
  34. 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
  35. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Transition Callbacks app/models/spree/shipment_observer.rb
  36. 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
  37. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    View Overrides • Hooks to override elements of core views • Uses Deface gem
  38. 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!
  39. Copyright 2005 - 2014 Degica Co. Ltd. All rights reserved.

    Thanks!