Dancer2::Plugin::Cart - Cart interface for Dancer2 applications
version 1.0001
use Dancer2; use Dancer2::Plugin::Cart;
This plugin provides a easy way to manage a shopping cart in dancer2. All the information and data structure of the plugin will be manage by the session, so a good idea is to use a plugin in order to store the session data in the database.
It was designed to be used on new or existing database, providing a lot of hooks in order to fit customizable solutions.
By default, the plugin is going to search default templates on the views directory, if the view doesn't exists, the plugin will render and inline templates provided by the plugin.
An script file has been added in order to generate the template views of each stage of a checkout, and the user will be able to adapt it to their needs.
The script is create_cart_views and needs to be run on the root directory of the dancer2 app. The default views assume that you are using "Template Toolkit" as the template engine.
environment
plugins: Cart: product_list: - ec_sku: 'SU02' ec_price: 16 - ec_sku: 'SU02' ec_price: 21
Options
products_view_template - Define a template to use to show the products cart_view_template - Define a template to use to show cart info cart_receipt_template - Define a template to use to show receipts shipping_view_template - Define a template to use to show shipping form billing_view_template - Define a template to use to show billing form review_view_template - Define a template to use to show review page receipt_view_template - Define a template to use to show receipt page default_routes - default 1, to exclude all routes, set to 0 excluded_routes - Array defining the routes to be excluded.
List of products
Cart info
To add a product to the cart
To reset the cart
To show shipping form
To store data on session variable
To show billing form
To show a summary of the cart
To place orders
To show the results of placing an order
Return the list of products and fill the ec_cart->{products} session variable.
Return a ec_cart Hashref with the updated info.
Use: subtotal, quantity, and total keywords
Call hooks: before_cart, after_cart
Add product to the cart
Process cart_add form and check errors on session('ec_cart')->{add}->{error}
Delete session('ec_cart')->{add} after success
Call hooks: validate_cart_add_params, before_cart_add, after_cart_add
Check if the product exists, adn add/sub the quantity
Calculate ec_subtotal for each item
Return product added
Delete ec_cart session variable
Call hooks: before_clear_cart, after_clear_cart
Calculate and return the subtotal (sum of ec_subtotal of each product)
Call hooks: before_subtotal, after_subtotal
Calculate and return the quantity (sum of ec_quantity of each product)
Call hooks: before_quantity, after_quantity
Load the ec_cart structure and check if there is any error on ec_cart->{billing}->{error}.
In case of error, the user is redirected to the billing route, other wise pass to the
Call hooks: validate_billing_params, before_bililng, after_billing_
Load the ec_cart structure and check if there is any error on ec_cart->{shipping}->{error}
In case of error, the user is redirected to the shipping route.
Call hooks: validate_shipping_params, before_shipping, after_shipping
Load the ec_cart structure check if there is any error on ec_cart->{checkout}->{error};
Call hook: checkout
Add status 1 to the ec_cart structure.
Call hooks: before_close_cart and after_close_cart
Add default adjustments to the ec_cart structure. The default adjustments are: Discounts, Shipping, Taxes. Call hook adjustments
Hooks are called before|after|as a function. The purpose of the hooks is to manipulate the data structure defined to ec_cart.
To implement the checkout step.
Add adjustments (This hook is called is called by cart function).
Andrew Baerg Ruben Amortegui
YourSole Core Developers
Josh Lavin
This software is copyright (c) 2016 by Ruben Amortegui.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer2::Plugin::Cart, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer2::Plugin::Cart
CPAN shell
perl -MCPAN -e shell install Dancer2::Plugin::Cart
For more information on module installation, please visit the detailed CPAN module installation guide.