Cart

store.cart provides you the current cart. This variable is only available after the add to cart action. store.cart allow cart lines with product data, shipping address, delivery mode, Cart is stored and managed directly via odoo. To avoid performance problems, cart data are cached, each cart updating (add new product, set a shipping address…) refresh cached datas via an Odoo API call.

Each cart update recalculate grand total, subtotal, shipping cost and VAT amount automatically.

To validate a cart you need to have a logged user.

Attributes

Cart header

store.cart attributes
Name Type Desciption
amount Date Grand total and taxes, See Amout documentation
date Date The cart creation date
lines Array Cart lines See Cart lines documentation
id Integer Cart ID
invoicing Object Invoice address, see Invoicing doc
name String Cart reference
payment Object Payment method selected, see Select payment method doc
shipping Object Shipping address, see Shipping doc
state String Odoo sale order status
step String Cart Step list, see Checkout step process doc

Amout

Amout object provide cart Grand total and taxes amount

store.cart.amount
Name Type Desciption
tax Float VAT grand total (Item and shipping cost included)
total Float Grand total (included taxes)
untaxed Float Total amount without taxes

Shipping

Shipping object provide shipping customer address, selected carrier and shipping cost.

store.cart amount
Name Type Desciption
address Object Shipping address
amount.tax Float Shipping cost’s tax
amount.total Float Shipping cost taxes included
amount.untaxed Float Shipping cost without taxes
carrier Float Total amount included taxes
trackings Array Parcel tracking URLs, not available for cart.

Invoicing

Shipping object provide invoicing customer address.

store.cart amount
Name Type Desciption
address Object invoicing address

Actions

Some actions are available to manage cart content. Cart actions use html form. Each action need form submitting with specific parameters and action attribute value.

Usally, we use hidden input to specify these parameters values.

You have to use get or post for form method. All actions require invader_success_url and invader_error_url parameters to defined URL page use for redirection in case of success or error.

The action form attribute is use to specify a Shopinvader controller ( /invader/cart/update, /invader/cart/add_item…)

Note

POST or GET form method will have the same effect.

Checkout step process

Actually Shopinvader use muli-page checkout. To move from one step to the next you need to submit a HTML form with specific parameters to indicate the current and the next checkout step.

This process is necessary to ensure the cart data viability.

Usally we recommended these cart steps :

  • Cart summary
  • Customer login
  • Select shipping address
  • Select Shipping mode and payment
  • order summary

You have to set up your cart steps into odoo backend configuration.

HTML form input
Input name Type Desciption
invader_success_url String Shopinvader cart controller name
invader_error_url String Method on controller
current_step String current step ID
next_step String next step ID

form submitting on /invader/cart/update may be combined various actions like select shipping address, define shipping method in the same time.

HTML form to go to the next step
<form method="post" action="/invader/cart/update">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />
  <input type="hidden" name="current_step" value="cart_index">
  <input type="hidden" name="next_step" value="cart_login">
  <input type="submit" value="Update address"/>
</form>

Select Shipping and billing address

In your cart a customer can enter two addresses: billing address or shipping address.

shipping and billing address are an item of store.addresses. store.addresses collection (see store.addresses documentation).

Controller /invader/cart/update

HTML form input
Input name Type Desciption
invader_success_url String Shopinvader cart controller name
invader_error_url String Method on controller
partner_shipping integer Address ID, address list provided by store.addresses
partner_invoice integer Address ID, address list provided by store.addresses
HTML form to choose shipping
<form method="post" action="/invader/cart/update">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />
  <div>
    <h2>Select shipping address</h2>
    {% with_scope  address_type: "address" %}
      {% for address in store.addresses %}
        <div>
          <input type="radio" name="partner_shipping" value="{{address.id}}"/>
          {{address.display_name}}
        </div>
      {% endfor %}
    {% endwith_scope %}
  </div>
  <div>
    <h2>Select billing address</h2>
    {% with_scope  address_type: "address" %}
      {% for address in store.addresses %}
        <div>
          <input type="radio" name="partner_invoice" value="{{address.id}}"/>
          {{address.display_name}}
        </div>
      {% endfor %}
    {% endwith_scope %}
  </div>
  <input type="submit" value="Update"/>
</form>

Select shipping method

Controller /invader/cart/update

HTML form input
Input name Type Desciption
invader_success_url String Shopinvader cart controller name
invader_error_url String Method on controller
partner_shipping integer Address ID, address list provided by store.addresses
partner_invoice integer Address ID, address list provided by store.addresses

store.cart.available_carriers provide carrier list.

HTML form to go to the next step
<form method="post" action="/invader/cart/update">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />

  {%for carrier in store.cart.available_carriers%}
    <div>
      <input type="radio" name="carrier" value="{{carrier.id}}"/>
      <b>{{carrier.name}}</b>
    </div>
  {% endfor %}

  <input type="submit" value="Select carrier"/>
</form>

Select payment method

Controller /invader/cart/update

store.cart.available_payment_method provide carrier list.

HTML form to go to the next step
<form method="post" action="/invader/cart/update">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />

  {%for payment_method in store.cart.available_payment_method%}
    <div>
      <input type="radio" name="payment_method" value="{{payment_method.id}}"/>
      <b>{{payment_method.name}}</b>
    </div>
  {% endfor %}

  <input type="submit" value="Select payment method"/>
</form>

Cart lines

Attributes

A line represents a single line in the shopping cart. This object can be accessed in all Liquid templates via store.cart.lines.items. There is one cart line for each product variant added to the shopping cart.

Cart and cart lines are stored directly in odoo.

This object has the following attributes:

store.cart.order_line attributes
Name Type Desciption
count Integer Number of items in cart
amount Object subtotal of all products added to cart
items Object Collection of lines

Cart line json

{
  "order_line":[
    {
      "product":{
        "images":[
          {"small":"<URL image>" ,"large":"<URL image>","medium":"<URL image>","original":"<URL image>"},
          {"small":"<URL image>" ,"large":"<URL image>","medium":"<URL image>","original":"<URL image>"}
        ],
        "default_code":"SKUPRODUCT",
        "url_key":"my-product-url",
        "name":"Great product",
        "id": 208
      },
      "price_unit":60,
      "product_uom_qty":2.0,
      "price_subtotal":100,
      "discount":0,"price_subtotal_gross":120,
      "is_delivery":false,
      "id": 3008
    }
  ]
}

Display lines in template

<table>
{% for line in store.cart.lines %}
  <tr>
    <td>{{line.product.name}}</td>
    <td>{{line.product_uom_qty}}</td>
    <td>{{line.price_subtotal | money}}</td>
  </tr>
{% endfor %}
</table>

Actions

Add product to cart

Controller /invader/cart/add_item

HTML form input
Input name Value Desciption
invader_success_url string URL in case of success
invader_error_url string URL in case of error
product_id integer ObjectID of product added to cart
item_qty integer Product quantity added to cart
HTML form to add product in cart
<form method="POST" action="/invader/cart/add_item">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />
  <input type="hidden" name="product_id" value="<product.ObjectID>" />
  <input type="number" name="item_qty" value="1"  step="1" min="0" max="10"/>
  ...
  <input type="submit" value="Add product"/>
</form>

Update quantity

This action is usally used in cart item list.

Controller /invader/cart/update_item

HTML form input
Input name Value Desciption
invader_success_url string URL in case of success
invader_error_url string URL in case of error
item_id integer cart line ID
item_qty integer New product quantity
HTML form to change product quantity
<form method="POST" action="/invader/cart/update_item">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />
  <input type="hidden" name="item_id" value="<Cart line ID>" />
  <input type="number" name="item_qty" value="1"  step="1" min="0" max="10"/>
  ...
  <input type="submit" value="Change quantity"/>
</form>

Remove product to cart

HTML form input
Input name Value Desciption
invader_success_url string URL in case of success
invader_error_url string URL in case of error
item_id integer cart line ID
HTML form to remove cart line
<form method="POST" action="/invader/cart/delete_item">
  <input type="hidden" name="invader_success_url" value="<URL success page>" />
  <input type="hidden" name="invader_error_url" value="<URL error page>" />
  <input type="hidden" name="item_id" value="<Cart line ID>" />
  ...
  <input type="submit" value="Remove line"/>
</form>