Examples

Below are a couple of examples to quick start with the Simple Cart module

Add to Cart with direct param

{exp:simple_cart:add_to_cart 
    entry_id="176" 
    price="15"
    tax="21"
    direct="yes"
}

Add to Cart

{exp:simple_cart:add_to_cart 
    entry_id="{entry_id}" 
    price="15"
    tax="21"
}
    <input type="text" name="qty" size="1" />
    <input type="submit" value="Add to cart"/>
{/exp:simple_cart:add_to_cart}

Add to Cart with direct param

{exp:simple_cart:add_to_cart 
    entry_id="176" 
    price="15"
    tax="21"
    extra:custom_param="some data"
    extra:more_custom_param="more data"
    extra:your_custom_param="more more more data"
}

Read out the extra data

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

    {entries}
        {extra:custom_param} //output 'some data'
        {extra:more_custom_param} //output 'more data'
        {extra:your_custom_param} //output 'more more more data'
    {/entries}

{/exp:simple_cart:cart}

Cart Example with update fields

The example below use the {sc:qty:input} as input field for the qty and the {sc:submit} for the submit button.

{exp:simple_cart:cart prefix="sc" fields_to_update="qty"}
    <table border="1">
        <thead>
            <tr>
                <th>Title</th>
                <th>Qty</th>
                <th>Raw Price</th>
                <th>Tax Price</th>
                <th>Tax included Price</th>
                <th>Subtotal raw Price</th>
                <th>Subtotal tax Price</th>
                <th>Subtotal tax included Price</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
    {entries}
        <tr>
            <td>{title}</td>
            <td><input name='qty[{sc:row_id}]' value="{sc:qty}"/></td>
            <td>{sc:price_raw}</td>
            <td>{sc:price_tax}</td>
            <td>{sc:price_include_tax}</td>
            <td>{sc:subtotal_raw}</td>
            <td>{sc:subtotal_tax}</td>
            <td>{sc:subtotal_include_tax}</td>
            <td><a href="{sc:delete}">Remove from cart</a></td>        
        </tr>
    {/entries}
        <tfoot>
            <tr>
                <td>&nbsp;</td>
                <td>{sc:qty_total}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>{sc:subtotal_raw}</td>
                <td>{sc:subtotal_tax}</td>
                <td>{sc:subtotal_include_tax}</td>
                <td>&nbsp;</td>
            </tr>
        </tfoot>
    </table>
        <p>{sc:submit}</p>
{/exp:simple_cart:cart}

<a href="{exp:simple_cart:empty_cart}">Empty cart</a>

Cart overview

{exp:simple_cart:cart prefix="sc"}
    <table border="1">
        <thead>
            <tr>
                <th>Title</th>
                <th>Qty</th>
                <th>Raw Price</th>
                <th>Tax Price</th>
                <th>Tax included Price</th>
                <th>Subtotal raw Price</th>
                <th>Subtotal tax Price</th>
                <th>Subtotal tax included Price</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
    {entries}
        <tr>
            <td>{title}</td>
            <td>{sc:qty}</td>
            <td>{sc:price_raw}</td>
            <td>{sc:price_tax}</td>
            <td>{sc:price_include_tax}</td>
            <td>{sc:subtotal_raw}</td>
            <td>{sc:subtotal_tax}</td>
            <td>{sc:subtotal_include_tax}</td>
            <td><a href="{sc:delete}">Remove from cart</a></td>        
        </tr>
    {/entries}
        <tfoot>
            <tr>
                <td>&nbsp;</td>
                <td>{sc:qty_total}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>{sc:subtotal_raw}</td>
                <td>{sc:subtotal_tax}</td>
                <td>{sc:subtotal_include_tax}</td>
                <td>&nbsp;</td>
            </tr>
        </tfoot>
    </table>
{/exp:simple_cart:cart}
<a href="{exp:simple_cart:empty_cart}">Empty cart</a>

PHP example

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($entry_id = 0, $price = 0, $qty = 1, $tax = 0, $time = 1200, $extra_param = array(), $increment = true);

//update_cart_entry
ee()->simple_cart_api->update_cart_entry($entry_id = 0, $price = 0, $qty = 1, $tax = 0, $time = 1200, $extra_param = array(), $increment = true);

//delete_cart_entry
ee()->simple_cart_api->delete_cart_entry($entry_id = 0);

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

Full Example

<h1>Producten</h1>
<ul>
    {exp:channel:entries channel="simple_cart"  dynamic="no"}
        <li>
            {title} - € {sc_price} -
            {exp:simple_cart:add_to_cart 
                entry_id="{entry_id}" 
                price="{sc_price}"
                tax="21"
                                return_url="http://reinos.nl/add-ons/simple-cart/examples/full-example"

                extra="{title} extra"
            }
                <input type="text" name="qty" size="1" />
                <input type="submit" value="Add to cart"/>
            {/exp:simple_cart:add_to_cart}
        </li>            
    {/exp:channel:entries}
</ul>

<h1>Cart</h1>
{exp:simple_cart:cart prefix="sc"  return_url="http://reinos.nl/add-ons/simple-cart/examples/full-example"}
    <table border="1">
        <thead>
            <tr>
                <th>Title</th>
                <th>Qty</th>
                <th>Raw Price</th>
                <th>Tax Price</th>
                <th>Tax included Price</th>
                <th>Subtotal raw Price</th>
                <th>Subtotal tax Price</th>
                <th>Subtotal tax included Price</th>
                <th>Current Timer</th>
                <th>extra</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
    {entries}
        <tr>
            <td>{title}</td>
            <td>{sc:qty:input}</td>
            <td>{sc:price_raw}</td>
            <td>{sc:price_tax}</td>
            <td>{sc:price_include_tax}</td>
            <td>{sc:subtotal_raw}</td>
            <td>{sc:subtotal_tax}</td>
            <td>{sc:subtotal_include_tax}</td>
            <td>{sc:current_timer:seconds} seconds</td>
            <td>{sc:extra}</td>
            <td><a href="{sc:delete}">Remove from cart</a></td>        
        </tr>
    {/entries}
        <tfoot>
            <tr>
                <td>&nbsp;</td>
                <td>{sc:qty_total}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>{sc:subtotal_raw}</td>
                <td>{sc:subtotal_tax}</td>
                <td>{sc:subtotal_include_tax}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </tfoot>
    </table>

    {sc:submit}
{/exp:simple_cart:cart}
<a href="{exp:simple_cart:empty_cart}">Leeg winkelwagen</a>

Edit Cart Item

Below example will edit directly an entry in the cart instead of producing an edit form. Use the {exp:simple_cart:cart} for updating the qty in an form.

{exp:simple_cart:edit_cart_item 
    entry_id="11" 
    price="15"
    tax="21"
    qty="25"
}