Skip to content

colibri-software/locomotive_ecommerce_plugin

Repository files navigation

Locomotive Ecommerce Plugin

This is a plugin for LocomotiveCMS. It was created to allow LocomotiveCMS designers to add Ecommerce Functionality.

It provides several Ecommerce features such as: managing shopping carts, assigning shipping and taxes values and managing extra disscounts and price breaks.

Installation

To use this plugin you must be using a version of LocomotiveCMS that has the plugins feature designed by Colibri Software. You can do this by making the following changes to the Gemfile in you app:

  • Remove or comment out the following line:
    gem 'locomotive_cms', '~> 2.X.X', require: 'locomotive/engine'
  • Add the following line:
    gem 'locomotive_cms', require: 'locomotive/engine', git: 'https://github.com/colibri-software/locomotive_engine.git', branch: 'plugins'

Then add the following lines in your Gemfile to include the plugin:

group :locomotive_plugins do
  gem 'locomotive_ecommerce_plugin'
end

Usage

Configuring Plugin

This plugin provides many configuration options which are as follows:

  • Stripe Public Key – Public key of the Stripe account connected to the application
  • Stripe Secret Key – Secret key of the Stripe account connected to the application
  • Cart URL – The path to the cart page
  • Checkout URL – The path to the checkout page
  • Post Checkout URL – The path to which the user should be taken after the checkout
  • Purchases URL – The path to the purchases page
  • Only in Stock Items – To show only items that are in stock
  • Estimated Tax Rate (in percent) – The estimated tax percentage to be applied to orders (Default: 15)
  • Tax Model – Slug of the model recording tax rates
  • Country Code Slug – Slug field of the country code of the Tax model
  • Province/State Code Slug – Slug field of the province/state code of the Tax model
  • Precentage Slug – Slug field of the percentage of the Tax model
  • Shipping Model – Slug of the model recording shipping rates
  • Name Slug – Slug field of the name from the Shipping Model
  • Over Price Break Slug – Slug field of the over price break
  • Under Price Break Slug – Slug field of the under price break
  • Price Break – The value at wich price breakes are applied
  • Apply extras – Use Javascript to integrate extra charges to total price
    The extra charges should be returned as a array of key/value pairs where keys represent the name of the extra charge and the value is the amount it represents. The “purchase_total” and “orders” are also passed in to the configuration, and can be utilized to calculate order specific extra charges.
    Example:
    if (purchase_total > 100) {
    	order = {
    	    'Special Discount' : 10, 
    	    'Offer' : -purchase_total/10
    	}
    } else {
    	order = {
    	    'Special Discount' : 20, 
    	    'Offer' : -purchase_total
    	}
    }
  • Shop Name – The name of the shop using the plugin
  • Shop Inventory Items – Excecuted in a javascript_context and returns a mongoid criteria of all line_items
  • Shop Inventory Items Class – Excecuted in a javascript_context and returns a mongoid criteria of all line_items classes
  • Contact – The email address of the main shop contact

Liquid Drops

This plugin provides multiple liquid drops to access various attributes of the Cart, Order, Purchases and their state.

The main plugin drop is accessed like this:

{{ plugins.ecommerce }}

It has the following attributes:

  • products – All inventory items. Through products you can access all the following params for each item (see the line_items attribute in the Cart drop for details)
  • cart – The current cart of the currently signed in user (see the Cart drop below for details)
  • purchase – The current purchase of the currently signed in user (see the Purchace drop below for details)
  • purchases – All purchaces made by the currently signed in user
  • show_out_of_stock – A boolean to check if products that are out of stock should be shown. Can be adjusted through the “Only in Stock Items” configuration option (see the configuration section above)

The plugin also provides an Cart drop, which is accessed like this:

{{ plugins.ecommerce.cart }}

It has the following attributes:

  • line_items – Reference to all the orders in the current cart
    Through line_items you can access the orders model which provides the following attributes:
    • id – The current order ID
    • price – The current order price rounded to to 2 decimal places
    • size – The size of the current product
    • color – The color of the currentb product
    • sku – The sku of the current product
    • product – The class of the current product retrived by sku
    • out_of_stock – A boolean that is true if the product is out of stock
    • quantity – The quantity of the current product in order
    • product_quantity – The available quantity of the current product
    • cart – Reference to the cart the product belongs to
  • id – ID of the current Cart
  • extras – A hash containing all the extra charges passed in through “Apply extras” configuration
  • extras_total – The total of all the extra charges in “extras”
  • purchase_total – Total for all orders in the current cart
  • estimated_tax – The estimated taxes to be applied on the currrent cart retrieved from “Estimated Tax Rate” configuration
  • subtotal_est_tax – Subtotal of the current cart including: purchase_total, estimated_taxes and the total of the extra charges
  • valid_stock – A boolean indecating whether the orders quantities are in stock

The plugin also provides an Purchase drop, which is accessed like this:

{{ plugins.ecommerce.purchase }}

It has the following attributes:

  • id – ID of the current purchase
  • date – Date of the current purchase
  • subtotal_est_tax – Subtotal of the current purchase delegated from the cart
  • shipping_estimate – Estimated shipping amount of the current purchase
  • subtotal_est_shipping – The subtotal of the current purchase including the “subtotal_est_tax” and the “shipping_estimate”
  • tax – The total taxes on the purchase
  • tax_percentage – The percentage taxes applied
  • total – The total coast of the purchase including “purchase_total”, “tax”, “shipping” and “extras_total”
  • cart – Reference to the current cart the products belongs to
  • completed – A boolean indicating whether the purchase is complete
  • shipping_info – A hash containing all the provided shipping information
  • stripe_token – The stripe token utilized in the currrent order

Liquid tags

The plugin provides a stripe tag which creates a button to show non-integrated stripe payment form and can be used as follows:

{% ecommerce_stripe %}

Liquid Filters

Provides a number of liquid filters to help determine the urls for cart updates and checkout and can be utilized as follows:

{{ cart | ecommerce_cart_update_path }}

Provides the cart update path for the passed in cart

{{ product | ecommerce_add_to_cart_path }}

Provides the add to cart path for the passed in product

{{ line_item.sku | ecommerce_remove_from_cart_path }}

Provides the remove from cart path for the product with the passed sku

{{ purchase | ecommerce_checkout_path }}

Provides the checkout path for the passed in purchase

{{ purchase | ecommerce_checkout_update_path }}

Provides the checkout update path for the passed in purchase

This project rocks and uses MIT-LICENSE.