Simple Cart

Introduction

Simple Cart enable a simple shopping cart based on your existing Entries. Simply add your entries to the Simple Cart by the powerfull sets of tags. No fancy FieldType (use the native custom field to set the price), no order management, no payment providera, no settings, just a couple of powerfull cart tags to do the task.

The following features are supported

old v1 docs can be found here

Installation

Prerequisites

Make sure your system meets the minimum requirements:

Installation Instructions

Update instructions

Add to Cart tag

{exp:simple_cart:add_to_cart}

Tag Parameters

Below are the Tag Parameters. Those parameters can be used in the tag described above

entry_id

Set the entry_id

entry_id=""

unique_id

Set the unique_id. Used when you are using multiple entries in the cart, with different meta data

unique_id="{entry_id}-{current_time}"

price

Set the price for your entry

price="110.90"

tax

Set your tax for the entry.
The example shows a 21% tax.

tax="21"

return_url

The return url

return_url="21"

direct

By setting the direct param to yes, the entry will be added directly to the cart.

direct="yes"

timer

The time in seconds that an entry will be stays in an cart

timer="1200"

custom_param

You can set as many custom variable with the entry by setting any custom param with a prefix extra:. See the examples for how to use.

extra:your_custom_var="some data"
extra:more_custom_vars="more data"

Input fields

You can also define the extra fields via input fields. Use the prefix extra: for your names. Those data will be validated and added to the extra data for this item.

<jnput type="text" name="extra:custom_field" value="test" />

Edit Cart Item Tag

This tag currently work as a direct call instead of producing a form to edit your qty for an item. Use the {exp:simple_cart:cart} tag for producing a form for updating your qty by the user.

{exp:simple_cart:edit_cart_item}

Tag Parameters

Below are the Tag Parameters. Those parameters can be used in the tag described above

entry_id

Set the entry_id

entry_id=""

price

Set the price for your entry

price="110.90"

tax

Set your tax for the entry.
The example shows a 21% tax.

tax="21"

return_url

The return url

return_url="21"

timer

The time in seconds that an entry will be stays in an cart

timer="1200"

custom_param

You can set as many custom variable with the entry by setting any custom param. See the examples for how to use.

your_custom_var="some data"
more_custom_vars="more data"

The Cart Tag

{exp:simple_cart:cart}

Tag Parameters

Below are the Tag Parameters. Those parameters can be used in the tag described above

prefix

Prefix the variables

{exp:simple_cart:cart prefix="sc"}
  {sc:qty_total}
{/exp:simple_cart:cart}

return_url

The url to return after submission

return_url=""

fields_to_update

register the field you want to update in the cart. also when using this, use the row_id to determine the row you are in. name="custom_field[{row_id}]"

{exp:simple_cart:cart
    prefix="sc"
    fields_to_update="custom_field"
}
    {entries}
        <input name="custom_field[{sc:row_id}]" value="{sc:custom_field"/>
    {/entries}

{/exp:simple_cart:cart}

Tag Variable

Below are the Tag Variables. Those Variables can be used in the tag described above

entries

Loop over the entries who are inside the cart

{entries}...{/entries}

entries - row_id

The row id inside the loop

used inside the {entries}...{/entries} tag

{entries}
  {row_id}
{/entries}

entries - price_raw

Show the raw price for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {price_raw}
{/entries}

entries - price_tax

Show the tax price for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {price_tax}
{/entries}

entries - price_include_tax

Show the price include the tax price for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {price_include_tax}
{/entries}

entries - qty

Show the quantity for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {qty}
{/entries}

entries - qty:input

Show the quantity for an entry inside a input element for updating

used inside the {entries}...{/entries} tag

{entries}
  {qty:input}
{/entries}

entries - subtotal_raw

Show the raw subtotal for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {price_subtotal_raw}
{/entries}

entries - subtotal_tax

Show the tax subtotal for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {subtotal_tax}
{/entries}

entries - subtotal_include_tax

Show the subtotal price include the tax for an entry.

used inside the {entries}...{/entries} tag

{entries}
  {subtotal_include_tax}
{/entries}

entries - Default Fields

All other custom fields can also be used. e.g. {title}

used inside the {entries}...{/entries} tag

{entries}
  {title}
  {entry_id}
  {entry_date}
  etc...
{/entries}

entries - custom_fields

any custom fields, defined in the add_cart tag can be use here. Simply use the name of the param with the prefix extra:.

e.g. When you use the param extra:your_var="test" in the add_cart tag, you can use the name of the param {extra:your_var} as variable.

used inside the {entries}...{/entries} tag

{entries}
  {extra:your_custom_var}
{/entries}

entries - delete

Show the delete link

used inside the {entries}...{/entries} tag

{entries}
  {delete}
{/entries}

entries - current_timer

Shows estimated time in seconds for how long the entry will stays in the cart.

used inside the {entries}...{/entries} tag

{entries}
      {current_timer} in seconds 
    {current_timer:seconds} in seconds 
      {current_timer:minutes} in minutes
{/entries}

subtotal_include_tax

Show the subtotal price include the tax for the whole cart.

{subtotal_include_tax}

subtotal_raw

Show the raw price for the whole cart.

{subtotal_raw}

subtotal_tax

Show the tax for the whole cart.

{subtotal_tax}

qty_total

Show the total items of the cart

{qty_total}

submit

Submit the form for updating the qty.

{submit}

Conditionals

Below are the conditionals you can use for the cart method.

simple_cart_no_results

detect when there is no result in the cart

{if simple_cart_no_results}
    There are no items in the Simple cart
{/if}

Remove from Cart tag

This tag produce a link, that remove a specified entry from the Cart.

{exp:simple_cart:remove_from_cart_link}

Tag Parameters

Below are the Tag Parameters. Those parameters can be used in the tag described above

entry_id

The entry_id

entry_id="100"

return_url

The url to return after submission

return_url=""

The empty Cart

This tag produce a link, that remove all the items from the cart.

{exp:simple_cart:empty_cart}

Tag Parameters

By setting the direct param to yes, the cart will be trucated directly. without generating a link

direct

The entry_id

direct="no"

return_url

The url to return url.

return_url="site/home"

Remove an item from the cart

{exp:simple_cart:remove_from_cart}

Tag Parameters

By setting the direct param to yes, the cart will be trucated directly. without generating a link

entry_id

The entry_id

{exp:simple_cart:remove_from_cart
      entry_id="4"
}

Global Variables

Global Variables can be used anywhere in your templates

simple_cart:qty_total

The total qty of items in the cart

{simple_cart:qty_total}

simple_cart:subtotal_raw

The total amount of cart without tax

{simple_cart:subtotal_raw}

simple_cart:subtotal_include_tax

The total amount of the cart including the tax

{simple_cart:subtotal_include_tax}

simple_cart:subtotal_tax

The total amount of tax based on the subtotal

{simple_cart:subtotal_tax}

Remove an item from the cart

simple_cart_add_to_cart

(added in v1.0)
This hook is called right before adding an entry to the Simple Cart

if (ee()->extensions->active_hook('simple_cart_add_to_cart') === TRUE)
{
    $data = ee()->extensions->call('simple_cart_add_to_cart', $data);
}

simple_cart_empty_cart

(added in v1.0)
This hook is called right berfore empty the Simple Cart.

if (ee()->extensions->active_hook('simple_cart_empty_cart') === TRUE)
{
    ee()->extensions->call('simple_cart_empty_cart', $cart_data);
}

simple_cart_remove_cart_entry

(added in v1.0)
This hook is called right before removing an entry from the Simple Cart.

if (ee()->extensions->active_hook('simple_cart_remove_cart_entry') === TRUE)
{
    ee()->extensions->call('simple_cart_remove_cart_entry', $cart_data);
}

simple_cart_modify_data

(added in v2.0.0)
This hook is called right before removing an entry from the Simple Cart.

if (ee()->extensions->active_hook('simple_cart_modify_data') === TRUE)
{
    $new_cart_data = ee()->extensions->call('simple_cart_modify_data', $cart_data);
}

PHP API

add_cart_entry

Add a new entry to the cart

$entry_id : the entry id $price : the price $qty : The qty $tax : Tax ammount $time : Time available in the cart $extra_param : (array) of extra values $increment : Do we need to increment the qty when his entry is already in the cart

ee()->load->add_package_path(PATH_THIRD . 'simple_cart/');
ee()->load->library('simple_cart_api');
ee()->load->remove_package_path(PATH_THIRD . 'simple_cart/');

//save_cart_entry
ee()->simple_cart_api->add_cart_entry(34, '15,95', 1, 21, 1200, array(), true);

update_cart_entry

Update a cart entry

$entry_id : the entry id $price : the price $qty : The qty $tax : Tax ammount $time : Time available in the cart $extra_param: (array) of extra values

ee()->load->add_package_path(PATH_THIRD . 'simple_cart/');
ee()->load->library('simple_cart_api');
ee()->load->remove_package_path(PATH_THIRD . 'simple_cart/');

//save_cart_entry
ee()->simple_cart_api->update_cart_entry(34, '15,95', 1, 21, 1200, array());

delete_cart_entry

Delete an entry from the cart

$entry_id : the entry id

ee()->load->add_package_path(PATH_THIRD . 'simple_cart/');
ee()->load->library('simple_cart_api');
ee()->load->remove_package_path(PATH_THIRD . 'simple_cart/');

//delete_cart_entry
ee()->simple_cart_api->delete_cart_entry(4);

empty_cart

Empty the cart

ee()->load->add_package_path(PATH_THIRD . 'simple_cart/');
ee()->load->library('simple_cart_api');
ee()->load->remove_package_path(PATH_THIRD . 'simple_cart/');

//empty_cart
ee()->simple_cart_api->empty_cart();

Changelog

3.0.0 (00-00-2017)

2.0.0 (26-06-2016)

1.0