ecommerce as an engine
DESCRIPTION
An examination of ecommerce in Ruby on Rails as an engine as compared to traditional ecommerce frameworks.TRANSCRIPT
![Page 1: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/1.jpg)
Puppies & Ecommerce as an Engine
Steph Skardal
All photos Copyright Steph Skardal
![Page 2: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/2.jpg)
Outline
● Traditional MonolithicEcommerce
● Ecommerceas an Engine
● Rails Goodness● Example Code● Piggybak● Cute puppies
I'm cute!
![Page 3: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/3.jpg)
TME: Traditional Monolithic Ecommerce:
Assumptions made:● shopping cart & checkout● products, product attributes● product navigation● product features: cross-sell, upsell, reviews● admin: various features● access control: admin, users
![Page 4: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/4.jpg)
Problems with TME:● Heavy on assumptions can make it difficult
to customize● Add-on features are not always maintained● Heavily dependent on direction of platform
Feeling Trapped?
![Page 5: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/5.jpg)
TME Positives:● Can get a site up and running quickly● For a simple site with minimal customization,
assumptions made by TME may be acceptable
It's notall bad.
![Page 6: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/6.jpg)
How do we make things easier?● Ecommerce as an Engine
But what doesthat mean?
![Page 7: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/7.jpg)
What are Rails Engines?● Rails 3 introduced a major rewrite in
Engines, allowing mountability of mini-applications.
● A Rails engine contains models, views, controllers, modules, and routes that plug-in to the main application
Rails application
Engine #1
Engine #2
Engine #3
![Page 8: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/8.jpg)
Why is Rails a good fit?● And Rails also now has some powerful
Admin tools (RailsAdmin, ActiveAdmin) comparable to Django's core.
● Generally, Rails is a good framework to be doing efficient development on (as are other MVC frameworks). "Mountability" may be a trickier thing to accomplish in Perl, but may be possible in catalyst.
![Page 9: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/9.jpg)
Ecommerce as an Engine● Assumptions of shopping cart and checkout● Items are added to the cart, which contain a
quantity, description, subtotal● Standard order and line item data model
![Page 10: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/10.jpg)
No Product Model
There is no product model. This is important. Why is there no product model?● mountability: turn existing models into products● TMEs tend to overengineer and bloat
assumptions built around the product model● In custom sites, products tend to be piled on
with custom attributes that don't apply to all products, adding cruft
![Page 11: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/11.jpg)
Variants Table
● variants table: with polymorphism
● Variant.find(1).item = Book.find(1)● Variant.find(2).item = CompactDisc.find(1)
id item_id item_type qty ...1 1 Book 102 1 CompactDisc 4
![Page 12: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/12.jpg)
The "Guts"
class Book < ActiveRecord::Base acts_as_variantend
acts_as_variant does two things:● has_one :variant, :as => "item", :class_name
=> "::Piggybak::Variant"● accepts_nested_attributes_for :variant, :
allow_destroy => true
![Page 13: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/13.jpg)
The "Guts"
class CompactDisc < ActiveRecord::Base acts_as_variantend
![Page 14: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/14.jpg)
The "Guts"
![Page 15: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/15.jpg)
Cart Form and Cart● included as Rails partial view (include)
● passes variant id and quantity to cart
![Page 16: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/16.jpg)
Line Item Structure● Order has many line_items:
● Line item copies description and price at the time order is created to preserve product information at the time of purchase
● Cart and order logic exercises inventory management if specified per variant
id qty variant_id description price total
1 1 1 Book Title 3.00 3.00
2 2 2 CD Title 3.00 6.00
![Page 17: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/17.jpg)
Photo Break
Stop! Tell me it's Almost Over!!
![Page 18: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/18.jpg)
Checkout
● Checkout doesn't care what item types are in the cart
● Shipping, Tax, and Payments have common APIs for calculating to cover cost of line items
![Page 19: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/19.jpg)
Authorize.NETclass AuthorizeNet KEYS = ["login", "password"] KLASS = ::ActiveMerchant::Billing::AuthorizeNetGatewayend
ActiveMerchant: A popular open-source gem released by Shopify.com that includes Payment gateway support for 40+ popular payment gateways.
Integration: Payment method directly integrates with ActiveMerchant, but specifies required payment gateway key value pairs that are stored in a table that maps to payment method.
![Page 20: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/20.jpg)
USPS Shippingclass Usps Shipping KEYS = ["login", "password", "service_name"] def self.request_rates(method, order) #returns rate end def self.available?(method, order) #returns boolean end def self.rate(method, order) #returns rate for order endend
![Page 21: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/21.jpg)
USPS Shipping
![Page 22: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/22.jpg)
What does this all mean?
● No assumptions made on:○ product attributes, features○ taxonomy○ access control
● Works for:○ highly customized sites in need of flexibility○ sites with multiple product types, where the
data model of the product types varies● Doesn't work for:
○ any sites that can evaluate the assumptions of TME to be more valuable than custom development
![Page 23: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/23.jpg)
Piggybak● This "Ecommerce as an Engine" philosophy
is the foundation of Piggybak
Shake off
those assumptions!
![Page 24: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/24.jpg)
Phunk says:
phunk: I might hit this high level idea a little harder: "rails engines are pluggable modules of functionality, and Piggybak is an engine, so that allows someone to plug this in and easily add the ecommerce part"
Rails application
Engine #1
Piggybak
Engine #3
![Page 25: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/25.jpg)
The Future
● More Piggybak work:○ testing○ implementation for more clients○ line items rearchitecture (?)
■ treat everything as a line item■ challenge with this is the admin interface
○ support for ActiveAdmin (?)○ keep up with Rails "trends"
● Continue growing the Piggybak baby with testing, client implementation, minimal features.
![Page 26: Ecommerce as an Engine](https://reader033.vdocument.in/reader033/viewer/2022052910/559a047a1a28abb25c8b4791/html5/thumbnails/26.jpg)
Questions?
/me eyesglaze over