Modern PerlCommerce
Past and Future
API
Development & Deployment

Modern PerlCommerce
Stefan Hornburg (Racke)

racke@linuxia.de

Pittsburgh Perl Workshop, 8th October 2011

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Perl Buzzwords
Modern Perl
PerlCommerce Choices

racke

Modern PerlCommerceNitesiModern PerlCommerce
Past and Future
API
Development & Deployment

Perl Buzzwords
Modern Perl
PerlCommerce Choices

Perl Buzzwords

I Marketing PerlI Modern PerlI Postmodern Perlracke

Modern PerlCommerceModern PerlCommerce
Past and Future
APIDevelopment & Deployment

Perl Buzzwords
Modern Perl
PerlCommerce Choices

Modern Perl

I CPANI Best Practices
I Tests
I Separation (Modules, Plugins, Hooks, Templates)
I PSGI/Plackracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Perl Buzzwords
Modern Perl
PerlCommerce Choices

PerlCommerce Choices

I Interchange
I HandelI AgoraI Business::Cart::Genericracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Past

I 1995 CGI
I 1995 MiniVend
I 1998 http://www.materialboerse.de/
I 2001 Interchangeracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFutureInterchange Development

I Lot of things
I Small community
I Same codebase

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Past
FutureStatus quo

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Past
FutureReferences

I Backcountry http://www.backcountry.com/
I FragnanceNet http://www.fragrancenet.com/

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Past
FutureFutureracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Principles

I KISS
I Components
I Agnostic
I Expressive

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

AgnosticCart
I Session
I DBI
I Webservice *racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Agnostic

Account Manager
I DBI
I LDAP *I OpenID *racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Agnostic

Templating Engine
I Template::Toolkit
I Template::Fluteracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Agnostic

Web framework
I Catalyst
I MojoI Dancerracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Past
FuturePreferences

I Dancer
I Template::FluteI DBI

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Framework

I Dispatching requests
I Parameter parsing
I Session handling
I Template engine
I I18N

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Extensions

I Bundles
I Plugins
I Hooks

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

PastFuture

Features

I Navigation
I CartI Checkout
I Accounts

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Cart

I SKU, Name, Quantity, Price
I Price > 0
I Combines automatically
I Multiple carts
I Storage everywhere
I Price cachingracke

Modern PerlCommerceModern PerlCommerce
Past and FutureAPI
Development & Deployment

CartCheckout
Accounts and Access Control
Forms

Nitesi::Cart Methods
use Dancer : : P l u g i n : : N i t e s i ;c a r t −>add ( sku => ’POM253 ’ , name => ’ Pomelo ’ ,p r i c e => 3 . 0 0 , q u a n t i t y => 1 0 ) ;c a r t −>remove ( sku => ’POM253 ’ ) ;c a r t −>count ( ) ;c a r t −>c l e a r ( ) ;c a r t −> t o t a l ( ) ;c a r t −>s u b t o t a l ( ) ;racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Everything is a Cart

I Saved Carts
I Wishlists
I Collections

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Multiple Cartsc a r t ( ’ w i s h l i s t ’ )−>add ( sku => ’ORA322 ’ , name => ’ Orange ’ ,p r i c e => 2 . 0 0 , q u a n t i t y => 5 ) ;racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Cart Backends

I Session
I DBI

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Inventory Check

MinQuantityField min_quantity
MaxQuantityField inventory : q u a n t i t yracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Inventory Check Hook

hook ’ b e f o r e _ c a r t _ a d d ’ => sub {my ( $ c a r t , $item ) = @_;my ( $ i n v e n t o r y ) ;$ i n v e n t o r y = query −> s e l e c t _ f i e l d ( t a b l e => ’ p r o d u c t s ’ ,f i e l d => ’ i n v e n t o r y ’ ,where => { sku => $item −>{sku } } ) ;i f ( $item −>{ q u a n t i t y } > $ i n v e n t o r y ) {$item −>{ e r r o r } = ’ Out o f s t o c k ’ ;}};

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Cart Hooks

I before_cart_add
I after_cart_add

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Cart Hooks

I before_cart_remove
I after_cart_remove

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Checkout

I Taxes
I Shipping
I Payment
I Invoiceracke

Modern PerlCommerceModern PerlCommerce
Past and Future
APIDevelopment & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Payment

I Business::OnlinePayment

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Tax Modules on CPAN

I Business::Tax::Canada
I Business::CA::GST
I Business::Tax::VAT
I Business::Tax::VAT::Validation

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
APIDevelopment & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Shipping

I Simple Shipping
I Crazy Shipping
I Shipping API

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Costs

$ c a r t −>a p p l y _ c o s t ( amount => 5 ) ;$ c a r t −>a p p l y _ c o s t ( amount => 0 . 1 9 , r e l a t i v e => 1 ) ;racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

PDF Invoices

I HTML template
I Template::Flute::PDFracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Accounts

p o s t ’ / l o g i n ’ => sub {i f ( account −>l o g i n ( username => params ( ’ body ’ ) − >{username } ,password => params ( ’ body ’ ) − >{password } ) ) {r e d i r e c t ’ / customerservice ’ ;}else {
redirect ’ / login ’ ;}};

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

CartCheckout
Accounts and Access Control
Forms

Accountsg e t ’ / checkout ’ => sub {i f ( account −>a c l ( check => ’ s u b m i t _ o r d e r s ’ ) ) {r e t u r n t e m p l a t e ’ checkout ’ ;}redirect’ / access_denied ’ ;};racke

Modern PerlCommerceModern PerlCommerce
Past and Future
APIDevelopment & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Account manager

I Account Providers
I Login/Logout
I Account Information
I Login status
I Forgot password
I Registration

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Account Provider

I DBI
I LDAP *I Htpasswd *I OpenID *I OAuth *racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Access Control

I UserI Roles
I Permissions

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

Cart
Checkout
Accounts and Access Control
Forms

Forms

I Display
I Validation
I Storage

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

DancerContribution
The EndRoutes

I Categories
I Products
I CartI Checkout
I Login/Logout
I Customer Serviceracke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

DancerContribution
The EndDefault Routeg e t q r { / ( . ∗ ) } => sub {my ( $sku ) = s p l a t ;my $ p r o d u c t ;# check f o r e x i s t i n g p r o d u c ti f ( $ p r o d u c t = database −>q u i c k _ s e l e c t ( ’ p r o d u c t s ’ , { sku => $sku } ) )# display flypage
template ’ flypage ’ , $product ;}else {# d i s p l a y n o t found pages t a t u s ’ not_found ’ ;f o r w a r d ’ 404 ’ ;}
};

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

DancerContribution
The End

CPAN/GitHub

I http://search.cpan.org/dist/Nitesi/
I http://search.cpan.org/dist/Nitesi-DBI/
I http://search.cpan.org/dist/

Dancer-Plugin-Nitesi/
I https://github.com/racke/Nitesi
I https://github.com/racke/Nitesi-DBI
I https://github.com/racke/Dancer-Plugin-Nitesi

racke

Modern PerlCommerceModern PerlCommerce
Past and Future
API
Development & Deployment

DancerContribution
The End

The End

Slides: http://www.linuxia.de/talks/perlcommerce/

perlcommerce-beamer.pdf
Project: https://vsc.state.gov/

racke

Modern PerlCommerce