-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes
146 lines (113 loc) · 5.67 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Dancer2::Plugin::Cart
Hi, my name is Andrew Baerg
A little bit about myself
I like to ride bikes... to work, in the rocky mountains, and also in vienna
I am married and have 3 awesome boys
I work for SOLE who is the maker of world famous heat mouldable insoles and soon to be world famous shoes made with recycled wine corks!
I developed their web store in 2002 - what I like to call the golden age of interchange5 - and have been building their systems since then.
Most recently the team at SOLE has written Dancer2:Plugin::Cart to run a new webstore for their cork recycling program.
Why did we write Dancer2::Plugin::Cart?
Frankly It is no longer the golden age of Interchange5.
I'd like to say it is the golden age of Dancer2
Bottom line is we really want to start developing with Dancer2 - and that means we needed a Cart
However, we have an existing database in Interchange5
on top of which is built a valuable erp and crm system
we also have a lot of existing business logic within various Perl modules and DBIx classes
simply put we don't want to throw this away
so we asked the questions
what if we had an ecommerce platform that didn't provide a schema
that didn't have a source of product data
that didn't provide functions to calculate shipping, taxes, or discounts
not even payment processing
what would it do?
it would need to manage the cart session
it would need functions for adding and removing items, and changing quantities
it would need to calculate the order subtotal and total
it would need to provide a checkout flow
a shipping and billing form
and a place order routine
and at a minimum, it would need to store all of this in the session so that we could actually do something with it.
and most importantly, it would need to provide a way to hook into all of this
to use or modify the session data that is being collected
it would need a hook to inject product data
source of data may simply be hard coded, it may be a single item
maybe it's coming from a data source, like your accounting system
maybe it's coming from an external source, for example, you can set up products within the Stripe payment gateway and fetch them using their API.
it would need a hook to add adjustments to total
for things like taxes, shipping, discounts
it would need hooks to provide Validation of shipping and billing Forms
and finally it would need hooks into the place order routine
to process the payment
send a receipt
and do order logging
Ecommerce is really complicated mostly because every business is unique
there is no way to sugar coat this fact
unless you have blinders on and are simply ignoring the complexity, you will know that a single ecommerce platform simply cannot do everything or handle every situation.
BUT we CAN make it easy
to do everything
How do we make it easy?
out of the box demo
clean slate to work with
you don't have to peel back the layers of copmlexity to do something simple
hooks for maintainability
complexity is not hidden, it's in a separate plugin or your own modules
ecosystem of plugins
most cases you can simply use a CPAN module in your hook
but I also see plugins under the Plugin::Cart namespace which provide standard hooks to things like payment gateways
Why should anyone other than us at SOLE care?
Doesn't everyone want a clone of Amazon for their store?
not even close
from my experience, the majority of new web stores being built are quite simple
they are either selling a small number of items
or they are selling a subscription to a service
payment processors like Stripe are common which provide the customer and order schema
there is no need to duplicate this schema or even provide an admin
So, I am happy to let you know that the cart plugin is ready to use!
Let's check it out!
Live Demo
1 Base Dancer App
2 Use Plugin
3 Add link to /products
- no products, we need to add some. Let's use the products hook
4 Add a Product
- a Dancer2 Book!
- Let's place an order, that was quick!
5 Create the view files
- use the script provided with the Plugin, currently creates Template Toolkit views
- this allows us to start customizing the data that is stored and displayed from the session
6 Display the description we added in Step 4
- edit all of the view files
7 Send an Email receipt
- use the after_checkout hook
- we are simply sending the receipt view template
- note that currently the order is only in the session, we could also add a hook to email the order to the admin
8 Add a coupon input
- by simply adding an input to the shipping form, it is now accessible from the hooks and part of the order in the session
9 Check if we have a valid coupon
- use the validate_shipping_params hook
- error is displayed on the shipping view
10 Clear default adjustments
- default adjustmenst are added for discounts, shipping, and taxes
- we could add our discount into the discounts, but we want to display the coupon description
- use the adjustments hook
11 Add coupon discount to adjustments
- use the adjustments hook - again! hooks are run in the order they are defined
- simply push an adjustment!
- let's take a look
12 Use Cart::Stripe Plugin
- add stripe api_key, public_api_key, and currency to config
- this plugin provides some new keywords we can use in our hooks
13 Use DefaultHooks
- one of the default hooks brings plans in from Stripe
- but our products hook is overwriting the products list
14 let's push our products instead
- Now we have Stripe plans in our cart!
15 Add Stripe form to checkout view
- now we can accept payments by cc!
What's Next?
Start using it!
Cart::Shipment
Cart::VAT
Cart::Interchange5
Cart::Stripe
Will you join us? github.com/YourSole/Cart