Ajax Basket

This section describes the methods available within the "Basket" family of Ajax methods. Using these methods you can access and manipulate the Aurora Basket's contents.

Ajax Method Group: Ajax_Basket

getBasketInfo

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/getBasketInfo

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • templates/example.com/_js/productdetails.js

📘

The getBasketInfo method allows you to fetch a summary of the Basket's values (cost, item count, etc).

Method Description

Request Parameters

None 

Response Variables

VariableValuesCurrencyDescription
basket_itemsIntegerThe number of items in the customer's basket.

This is the total number of items/products in the basket and not the number of lines in the basket; e.g. if there is one Line in the Basket, but this line has a quantity of 3, then this value will be returned as 3 and not 1.
discountStringSelectedThe total discount currently applied to the Basket.
total_costStringSelectedThe total value of the Basket excluding Shipping Charges.
shipping_costStringSelectedThe total cost of the Shipping.
payment_costStringSelectedThe total payment that would be due for the Basket if it were to be ordered as it is.

getBasketDetails

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/getBasketDetails

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • templates/example.com/_js/basket.js

Related Aurora Demo Templates:

  • templates/example.com/basket/basket.tpl.html

📘

The getBasketDetails method allow you to:

  • Remove an item from the basket.
  • Fetch the current basket contents using a dedicated Front-end template for it's presentation (basket/basket.tpl.html).
  • Get the list of currently available shipping options/methods.
  • Update the visitor's shipping settings.

Setting the Shipping Methods

Getting the Available Shipping Methods

Before you can chose a shipping method, you must first find all of the available ones to present to the customer. These methods can be found using this endpoint and looking to the contents of the "delivery_options" return variable.

This variable will contain an array of all available shipping options based on the user's current basket and settings. This accounts for all of the supported matrix, such as total order value, weight, dimensions and more.

👍

If this variable contains only a single shipping option, then it is suggested that you simply auto-select this for the customer and avoid even presenting them with a choice as there is none to make.

This kind of flow is often used for services like Collect+ and Click & Collect, where there are no options for the customer to consider (other than the desire to use said service in the first place).

🚧

If you omit the delivery_option parameter completely, Aurora will attempt to default this for you, but this may not always result in the desired behaviour, if (for example) there are multiple possible options to be selected from (in this case Aurora will simply select the first). Due to this, it is suggested you provide this value.

Home Delivery

To tell Aurora that the customer wishes to use a home delivery service, call this endpoint as demonstrated below.

/ajax/Ajax_Basket/getBasketDetails?shipping_country=1&delivery_option=33&delivery_type=home

🚧

The delivery_option of 33 is an example and should be a shipping rule ID, as configured for "Home Delivery" under Aurora's Shipping Rules.

Collect in Store (also called 'Click and Collect' or 'Pay and Collect') Delivery

To tell Aurora that the customer wishes to use a Click and Collect delivery service, call this endpoint as demonstrated below.

/ajax/Ajax_Basket/getBasketDetails?shipping_country=1&delivery_option=66&delivery_type=store&delivery_store_type=physical&collect_in_store=1&store_id=71&delivery_store_id=71

🚧

The delivery_option of 66 is an example and should be a shipping rule ID, as configured for "Pay and Collect" under Aurora's Shipping Rules.

The store_id must be a valid Store ID from the Aurora Back-end, as configured under Orders > Shipping > Stores.

Reserve and Collect Delivery

To tell Aurora that the customer wishes to use a Reserve and Collect delivery service, call this endpoint as demonstrated below.

/ajax/Ajax_Basket/getBasketDetails?shipping_country=1&delivery_option=77&delivery_type=reserve_and_collect&delivery_store_type=physical&store_id=71&delivery_store_id=71

🚧

The delivery_option of 77 is an example and should be a shipping rule ID, as configured for "Reserve and Collect" under Aurora's Shipping Rules.

The store_id must be a valid Store ID from the Aurora Back-end, as configured under Orders > Shipping > Stores.

Collect+ (Collect Plus) Delivery

To tell Aurora that the customer wishes to use a Collect+ delivery service, call this endpoint as demonstrated below.

/ajax/Ajax_Basket/getBasketDetails?shipping_country=1&delivery_option=55&delivery_type=collect_plus&collect_plus_delivery=1

🚧

The delivery_option of 55 is an example and should be a shipping rule ID, as configured for "Collect Plus" under Aurora's Shipping Rules.

Method Description

Request Parameters

ParameterValuesDescriptionRequired
json_basket1 | 0If this parameter is provided, the basket will be returned as a JSON array, otherwise it will be returned as fully generated HTML.

The HTML (if requested) is generated using the following template from your Front-end Templates by default:

basket/basket.tpl.html 

This template can be changed using the template_name parameter detailed further along in this section.
No
delete_basket_itemIntegerThe Internal ID Aurora uses to identify a Basket Item/Line.

This is often used to provide seamless support for the 'delete line' button or 'cross' in the Basket, allowing you to request an item be removed and retrieve the resulting basket contents in a single call.
No
payment_typeStringThis should be the string payment type, as set via the Checkout form, and is most commonly used from the checkout to query the basket contents and promotions based on a selected payment type.

Some example payment types include:

card
paypal
* store_card
No
additional_payment_typesStringThis should be a comma separated string of payment types, as set via the Checkout form, and is most commonly used from the checkout to query the basket contents and promotions based on a selected payment type.

Some example payment types include:

* gif_card
No
move_basket_item_to_wishlistIntegerThe Basket ID of a line from the basket that you would like to remove from he basket and add to the current visitor's wish list.No
update_basket_item_quantityIntegerThe Basket ID of a line from the basket that you would like to change the quantity of.Conditional

Required if basket_item_quantity is provided.
basket_item_quantityIntegerThe new quantity you would like to set for the line specified by the update_basket_item_quantity parameter.

If you provide a clue of 0 (Zero) here, then the line will be removed completely from he basket.
Conditional

Required if update_basket_item_quantity is provided.
delete_basket_itemIntegerThe Basket ID of a line from the basket that you would like to remove completely.No
delete_coupon1 | 0If this parameter is provided, then any Coupons currently applied to the basket will be removed.No
apply_loyalty_pointsIntegerThis should be the number of Loyalty Points you would like to apply to the Basket.No
remove_loyalty_points1 | 0If this parameter is provided, then any Loyalty Points currently applied to the basket will be removed.No
delivery_optionIntegerThis should be the Internal Aurora ID of the Delivery/Shipping Option selected by the customer (or that you wish to have applied to the basket).No
update_shipping_options1 | 0If this this parameter is provided, then it will force Aurora to refresh the shipping options applied to the basket and re-apply any default(s) configured in Aurora (affected by the content of the basket).No
apply_storecreditFloatThe monetary value of the amount of Store Credit to be applied to the basket.No
remove_storecredit1 | 0If this parameter is provided, then any Store Credit currently applied to the basket will be removed.No
collect_in_store1 | 0If this parameter is provided and set to 1, then the shipping is set to be a Click/Pay and Collect option (if possible, i.e. all the required fields have also been provided, including Store ID and a valid C&C delivery option).No
reserve_collect_delivery1 | 0No
store_idIntegerThe Unique Aurora Store ID for the store from which the order will be collected.

Deprecated in favour of delivery_store_id.
Conditional: If collect_in_store or reserve_collect_delivery is provided.
delivery_store_idIntegerThe Unique Aurora Store ID for the store from which the order will be collected.Conditional: If collect_in_store or reserve_collect_delivery is provided.
template_nameStringThe name of the template you would like used for generating the new basket contents.

Defaults to "basket.tpl.html".

This may only be a filename and must exist within your Front-end Templates under "/templates/yourdomain/basket/".

If the template does not exist, then the default "/templates/yourdoman/basket/basket.tpl.html" template will be used instead.

This perimeter is ignored unless the json_basket parameter is set to 0, indicating that HTML should be returned instead of JSON data.
No

Response Variables

The data returned by the getDropdownBasket method is contained within an indexed array. The table below details what is held in each of the array elements by their index value.

Variable NameValuesExampleDescription
successBooleantrueThis will return TRUE or FALSE based on whether the action(s) attempted were successful.

Even when an action fails, the return fields will often still include all described fields in the rest of this table.
errorArray | FALSEfalseThis will be FALSE if there are no errors to report, but will contain the error details if there are.
error.messageStringThis will be a short description of the error that occurred during the call to the endpoint. It is intended for developmental reference only and so is not translatable or intended for display to the end user.

This error message should be used by developers to diagnose errors in the use of this Ajax endpoint and how to resolve them.
basket_itemsArray or StringDependant on the value passed for the json_basket parameter, this will either be:

json_basket is 0 or not set at all: HTML
json_basket is 1: JSON
removed_basket_itemsArrayAn array of removed items for use with tracking or any other custom process(es) you may wish to implement.
collect_plus_availableBooleantrueIndicates whether Collect Plus is available for the current basket.
delivery_optionsArrayAn array of available delivery options for the current basket.
delivery_options_htmlStringThe fully generated HTML representing the delivery options available to the current basket.

The HTML (if requested) is generated using the following template from your Front-end Templates:

checkout/delivery-options.tpl.html

If this template is not found by Aurora, then this field will be blank.
delivery_timeArrayThis contains various details regarding the currently selected delivery option.
delivery_time.nameStringThis is the name of the currently selected delivery option.
delivery_time.timeString2 daysThe time in days that the delivery option usually ships within (as configured in the Aurora Back-end).
delivery_time.estimateStringThe shipping estimate generated by Aurora based on the current basket and selected delivery option.
delivery_time.totalCostString£29.99The total cost of the basket in the currently selected currency that was used for shipping calculations, with any appropriate currency formatting applied.
delivery_time.shippingCostFloat2.99The total cost of the shipping in the currently selected currency, as a raw float value.
delivery_time.discountString£5.99The total discount applied to the basket in the currently selected currency that was used for shipping calculations, with any appropriate currency formatting applied.
delivery_costString£2.99The total cost of the shipping in the currently selected currency, with any appropriate currency formatting applied.
delivery_cost_floatFloat2.99The total cost of the shipping in the currently selected currency, as an unmodified float value.
order_subtotalString£28.00The subtotal of the basket in the currently selected currency, with any appropriate currency formatting applied.
order_totalString£24.00The total of the basket in the currently selected currency, with any appropriate currency formatting applied.
order_total_floatFloat24.00The total of the basket in the currently selected currency, as an unmodified float value.
payment_costString£24.00The total payment due for the basket in the currently selected currency, with any appropriate currency formatting applied.

This can differ from the order total when things like Store Credit are applied, e.g. if £20 of store credit were applied, there might only be £5 remaining to be paid.
payment_cost_floatFloat24.00The total payment due for the basket in the currently selected currency, as an unmodified float value.
discountString£5.99The total discount applied to the basket in the currently selected currency, with any appropriate currency formatting applied.
discount_valueFloat5.99The total discount applied to the basket in the currently selected currency, as an unmodified float value.
has_discountInteger1Is there a discount applied to the basket?

1 for yes and 0 for no.
loyalty_pointsInteger123The number of loyalty point applied to the current basket.
available_loyalty_pointsInteger3000The number of loyalty point that the current user has available to them (requires the customer to be logged-in).
applied_creditString£20.00The total amount of Store Credit applied to the basket in the currently selected currency, with any appropriate currency formatting applied.
applied_credit_floatFloat20.00The total amount of Store Credit applied to the basket in the currently selected currency, as an unmodified float value.
available_creditString£100.00The total amount of Store Credit available to the current user in the currently selected currency, with any appropriate currency formatting applied (requires the customer to be logged-in).
available_credit_floatFloat100.00The total amount of Store Credit available to the current user in the currently selected currency, as an unmodified float value (requires the customer to be logged-in).
free_shipping_spendString£30The additional amount that the customer would need to spend to qualify for Free Shipping (based on the current basket) in the currently selected currency, with any appropriate currency formatting applied.

The is dependant on Free Shipping Options having been configured in the Aurora Back-end.

If the customer already qualifies (i.e. there is already free shipping available to them) then this value will be 0/Zero).
free_shipping_spend_showInteger1Is Free Shipping already available on the current basket?

1 for yes and 0 for no.
cross_sellsStringThe fully generated HTML representing the list of Cross Sells for the current basket contents (based on the Front-end Templates).

The HTML is generated using the following template from your Front-end Templates:

basket/cross-sells.tpl.html

If this template is not found by Aurora, then this field will be blank.
coupon_enabledBooleantrueIs there a coupon currently applied to the basket?

1 for yes and 0 for no.
total_cross_sellsInteger8A count of the number of cross sell products found for the current basket contents.
shipping_countryInteger23Aurora's Internal ID for the currently selected shipping country.
shipping_countriesArrayAn array of the currently available shipping countries, as configured in the Aurora Back-end.
feedbackStringProvides feedback from the 'Move Basket Item to Wishlist" operation in the form of a generated HTML block (based on your Front-end Templates).

The HTML (if requested) is generated using the following template from your Front-end Templates:

basket/ajax-wishlist-feedback.tpl.html

This HTML is only generated when the "move_basket_item_to_wishlist" parameter is used.
basket_errorStringIf an error occurs on the basket, e.g. a coupon could not be applied, then this string will include an appropriate error message to this effect.

If no error has occurred, then this fields will be blank.
customer_customs_informationStringThis will include any customs information configure in the Aurora Back-end for the currently selected shipping country.
paypal_credit_allowedBooleantrueIndicates whether the current basket is eligible for payment using PayPal Credit.

getDropdownBasket

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/getDropdownBasket

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • templates/example.com/_js/generic.js

Related Aurora Demo Templates:

  • templates/example.com/basket/dropdownbasket.tpl.html

📘

The getDropdownBasket method allow you to:

- remove an item from the basket.
- fetch the current basket contents using a dedicated Front-end template for it's presentation (basket/dropdownbasket.tpl.html).

Method Description

Request Parameters

ParameterValuesDescriptionRequired
delete_basket_itemIntegerThe Internal ID Aurora uses to identify a Basket Item/Line.

This is often used to provide seamless support for the 'delete line' button or 'cross' in the Mini/Dropdown Basket, allowing you to request an item be removed and retrieve the resulting basket contents in a single call.
No

Response Variables

The data returned by the getDropdownBasket method is contained within an indexed array. The table below details what is held in each of the array elements by their index value.

Variable NameValuesDescription
0String HTMLThe merged basket contents ready for display.

This content is generated using the 'basket/dropdownbasket.tpl.html' Front-end Template.
1IntegerThe number of items in the customer's basket.

This is the total number of items/products in the basket and not the number of lines in the basket, e.g. if there is one Line in the Basket, but this line has a quantity of 3, then this value will be returned as 3 and not 1.
2FloatThe total value of the Basket excluding Shipping Charges.
removed_basket_itemsArrayAn array of removed items for use with tracking or any other custom process(es) you may wish to implement.

showLoyaltyPoints

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/showLoyaltyPoints

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • templates/example.com/_js/basket.js

Related Aurora Demo Templates:

  • templates/example.com/basket/ajax-loyalty-points.tpl.html

📘

The showLoyaltyPoints method allow you to fetch the Loyalty Points information for the current User using a dedicated Front-end template for it's presentation (basket/ajax-loyalty-points.tpl.html).

Method Description

Request Parameters

None

Response Variables

The data returned by the showLoyaltyPoints method is plain HTML content and is not JSON Encoded in any way. The return data can simply be used directly in a page for presentation of the current User's Loyalty Point information, as described by the 'basket/ajax-loyalty-points.tpl.html' Front-end Template.

addToBasket

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/addToBasket

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • None

 Related Aurora Demo Templates:

  • None

📘

The addToBasket method allow you to:

- Add an item to the basket
- Update item quantity if the item is already in the basket

Method Description

Request Parameters

ParameterValuesDescriptionRequired
product_idInteger/ArrayThe product id of the item that needs to be added to the basket. This also can be an array of product ids that need to be added to the basket.No
product_quantityInteger/ArrayThe product quantity that needs to be added of the provided product_id. This can also be a associative array with quantities for the provided product_id's. If this is not provided, a default quantity of 1 will be used.

Example of product quantity array

<br>$product_quantity = array(<br> 321 => 1,<br> 322 => 5,<br> ...<br>);<br>
No
attributesStringA serialised representation of the selected product attribute i.e.

<br>attributes[{$attribute.id}]={$value_id}<br>

Which can be established as follows:

<br>{foreach from=$product.attributes item="attribute"}<br> <span>Select {$attribute.attribute_name}</span><br> <select name="attributes[{$attribute.id}]" class="prodattr"><br> {foreach from=$attribute.values item="value"}<br> <option value="{$value.id}">{$value.attribute_value}</option><br> {/foreach}<br> </select><br>{/foreach}<br>...<br><script type="text/javascript><br>$.aurora.post(<br> '/ajax/Ajax_Basket/addToBasket',<br> {<br> product_id: $('.prodid'),val(), <br> product_quantity: $('.prodqty'),val(), <br> attributes: $('.prodattr').serialize()<br> }, <br> function(response_data) {<br> ...<br> }, <br> 'json'<br>);<br><script><br>

You may need to explicitly URL encoded this value dependent on your template scripting library.
No

Response Variables

The data returned by the addToBasket method is always 1

addToBasketDropdown

Overview

Permission Required: None

Method Call: /ajax/Ajax_Basket/addToBasketDropdown

Aurora Demo Example URL: https://demo.auroracommerce.com/

Aurora Demo Example JavaScript:

  • None

 Related Aurora Demo Templates:

  • None

📘

The addToBasketDropdown method allows you to:

  • Add an item/items to the basket
  • Add variations of an item to the basket
  • Add bundles to the basket
  • Retrieve the rendered basket dropdown template contents

Method Description

Request Parameters

ParameterValuesDescriptionRequired
product_idInteger/ArrayDeprecated - See product_id under all_fields

The product ID of the item that needs to be added to the basket. This is not used and should not be provided.
No
all_fieldsStringA serialised representation of the products and variations to be added to the basket. Values are separated by an ampersand character.

Example:
product_id=123&variation_id=456&product_quantity=1

Where providing data as an array e.g. product_ids you may use the following syntax:

product_id[]=123&product_id[]=124

Please see the example requests section further down for more information on usage of this field.

You may need to explicitly URL encode this value depending on your template scripting library.
No
all_fields - product_idInteger/ArrayThe product ID or an array of product IDs that you wish to add to the basket.

Please Note that this should only be used for products without variations (use variation_id instead - this point is reiterated in the variation_id description below)

Please Note that a non-array product_id will be ignored if any variation_id parameters are defined.
No
all_fields - variation_idInteger/ArrayThe variation ID or an array of variation IDs that you wish to add to the basket.

This can be used in conjunction with product_id but product_id should be provided as an array, even if there is only a single product. e.g. product_id[]=123&variation_id[]=9987

If providing a variation_id you should not provide the parent products id as a product_id parameter as well. This a reiteration of a note made in the product_id parameter description in the above row.
No
all_fields - product_quantityInteger/ArrayThe product quantity that needs to be added of the provided product_id. This can also be a associative array with quantities for the provided product_id's. If this is not provided, a default quantity of 1 will be used.

Example of product quantity array

$product_quantity = array(321 => 1, 322 => 5);
No
all_fields - bundle_idIntegerThe bundle ID that you wish to add to the basket.

This cannot be used in conjunction with adding multiple products or variations. Please see the example requests section further down for more information on usage of this field.
No

Response Variables

The data returned by the addToBasketDropdown method is contained within an indexed array. The table below details what is held in each of the array elements by their index value.

Variable NameValuesDescription
0String HTMLThe basket contents ready for display.

This content is generated using the 'basket/dropdownbasket.tpl.html' Front-end Template.
1IntegerThe number of items in the customer's basket.

This is the total number of items/products in the basket and not the number of lines in the basket, e.g. if there is one Line in the Basket, but this line has a quantity of 3, then this value will be returned as 3 and not 1.
2StringAlways: "Items"
3FloatThe total value of the basket.
4FloatThe subtotal of the basket excluding shipping and tax.
5FloatThe subtotal of the basket excluding shipping.
6ArrayAn array of products that have been added to the basket for use with tracking or any other custom process(es) that you may wish to implement.
7ArrayAn array of bundle data that has been added to the basket where a bundle ID has been provided.

Example Usage

The following requests can be performed on https://demo.auroracommerce.com with the products set up in that environment.

Add single product

📘

Please note that you can also use the array syntax under Add multiple products/Add multiple variations to add a single product/variation.

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'product_id=32602&'   // Silver And Navy Stud Earrings
 // + 'product_quantity=2&' // Optionally provide quantity
}).then(() => { window.location.replace('/basket') });

Add multiple products

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'product_id[]=32602&'        // Silver And Navy Stud Earrings
    + 'product_id[]=32603&'        // Silver And Navy Jewel Necklace
 // + 'product_quantity[32602]=2&' // Optional quantity for earrings
 // + 'product_quantity[32603]=2&' // Optional quantity for necklace
}).then(() => { window.location.replace('/basket') });

Add single variation

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'variation_id=5379&'  // Black Cord Button Pinafore Dress - Size 6
 // + 'product_quantity=2&' // Optionally provide quantity
}).then(() => { window.location.replace('/basket') });

Add multiple variations

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'variation_id[5379]=3&' // Black Cord Button Pinafore Dress - Size 6 - Qty 3
    + 'variation_id[5368]=1&' // Bottle Green Bodycon Dress - Size 8 - Qty 1
}).then(() => { window.location.replace('/basket') });

Add multiple products and variations

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'product_id[]=32602&'        // Silver And Navy Stud Earrings
    + 'product_id[]=32603&'        // Silver And Navy Jewel Necklace
    + 'product_quantity[32603]=2&' // Qty 2 of Necklace
    + 'variation_id[5379]=3&'      // Black Cord Button Pinafore Dress - Size 6 - Qty 3
    + 'variation_id[5368]=1&'      // Bottle Green Bodycon Dress - Size 8 - Qty 1
}).then(() => { window.location.replace('/basket') });

Add a bundle

📘

Note that you cannot add multiple products or variations when adding a bundle. These must take place across two requests.

$.post('/ajax/Ajax_Basket/addToBasketDropdown', {
  'all_fields': ''
    + 'product_id=32602&'           // The main bundle product ID
    + 'bundle_id=51&'               // The bundle ID
    + 'bundle_product_ids[]=32602&' // List the bundle products
    + 'bundle_product_ids[]=32603&' // ...
}).then(() => { window.location.replace('/basket') });