A Ecommerce site normally consists of several parts: Product page, Cart (Basket) displaying purchased items, Checkout with payment options, user Form forwarding, and purchase Confirmation.
The dynamic processes (e.g., adding to cart, calculating price) on a static site (no PHP) are archived via JavaScript and currently there are two available libraries: Snipcart (2% payment fee) and simpleCart.js (open source).
Snipcart as a commercial product seems quite popular because it’s easy to setup, even for people without much html/javascript experience, fully customisable and supported, and 2% commission fee doesn’t seem a lot.
However, I am an open-source fan and I decided to try simpleCart. Here are some codes for each section:
Product page
To link the product elements (name, price, etc.) to simpleCart function. Define classes as “simpleCart_shelfItem”, “item_name”, “item_image”, “item_price”, and “item_add”.
1
2
3
4
5
6
<liclass="simpleCart_shelfItem"><a><center><imgsrc="{{.image}}"alt="{{.title}}"/></center></a><br><imgstyle="display:none;"class="item_image img-responsive"src="{{.thumb}}"/><!--hidden image can be shown in the cart for each item--><pclass="item_name">{{.title}}</p><br><p>€<spanclass="item_price"align="left">{{.price}}</span><spanstyle="padding: 0 10px; float: right;"><ahref="javascript:;"class="item_add"><imgsrc="/images/cart.png"height="18px;"></a></span></p></li>
Which looks like this:
When you click the cart icon you got a confirmation through the following script (add to simpleCart.js)
You need a form for the user to input their name, email/phone and address, and payment options to select. Once they submit, you will receive an email with the form information (I used formspree to receive submission).
<divid="Order-form"><formaccept-charset="UTF-8"action="//formspree.io/YOUR-EMAIL-ADDRESS"class="contact-form"method="post"><fieldset><p>姓名:<br><inputtype='text'name='Name'placeholder='姓名(必填)'required/></p><p>邮箱:<br><inputtype='text'name='Email'placeholder='邮箱(必填)'pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"required/></p><p>电话:<br><inputtype='text'name='Phone'placeholder='手机号(必填)'required/></p><p>地址:<br><inputtype='text'name='Address'placeholder='详细收件地址(必填)'required/></p><p>备注:<br><textareatype='comments'name='Comments'rows="6"placeholder='备注信息'/></textarea></p><inputtype='hidden'name='Order'id='getcartitems'></input><inputtype="hidden"name="_subject"value="New Order from PinWei.DE"/><h4style="color: darkred">请选择付款方式 <selectid="mySelect"name="Payment"required><optionvalue="AliPay">支付宝</option><optionvalue="BankTransfer">银行转账</option></select></h4><small><em>下单后您将会收到账号信息</em></small><hrstyle="border:dashed #666 1px;"><buttonclass="pull-right"type="submit"><h4>确认信息,我要下单!</h4></button></fieldset><inputtype="hidden"name="_next"value="/success/"/><spanclass="pull-right"style="font-size: 65%;">
点击'下单'代表您已阅读并接受相关<aalt="terms and policy"href="/terms/"><strong>条款及条件</strong></a></span></form><br></div>
Note that I used an hidden <input> element class (“getcartitems”) to get the items in the cart, for which you need a script:
And you will receive an email forwarded by formspree with all input from the user:
The downside is that the user will not automatically received and confirmation email from the website, but you can direct them to a page after the form had been successfully submitted by define the <input> (type=“hidden” name="_next" value="/success/").
Submission Confirmaion
The confirmation page is returned upon submission of the form. On Amazon it normally shows some similar products. Here we can simply show a thank you sentence and tell the user how to pay.
Pay by PayPal
Currently simpleCart support direct PayPal payment, but only with US dollors. If you take PayPal, you simply insert your paypal email in the JS file and define a button/text (class=“simpleCart_checkout”).
And lastly, to include the jQuery and simpleCart libraries in the header of each page.