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
Variable | Values | Currency | Description |
---|---|---|---|
basket_items | Integer | The 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. | |
discount | String | Selected | The total discount currently applied to the Basket. |
total_cost | String | Selected | The total value of the Basket excluding Shipping Charges. |
shipping_cost | String | Selected | The total cost of the Shipping. |
payment_cost | String | Selected | The 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
Parameter | Values | Description | Required |
---|---|---|---|
json_basket | 1 | 0 | If 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_item | Integer | The 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_type | String | This 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_types | String | This 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_wishlist | Integer | The 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_quantity | Integer | The 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_quantity | Integer | The 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_item | Integer | The Basket ID of a line from the basket that you would like to remove completely. | No |
delete_coupon | 1 | 0 | If this parameter is provided, then any Coupons currently applied to the basket will be removed. | No |
apply_loyalty_points | Integer | This should be the number of Loyalty Points you would like to apply to the Basket. | No |
remove_loyalty_points | 1 | 0 | If this parameter is provided, then any Loyalty Points currently applied to the basket will be removed. | No |
delivery_option | Integer | This 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_options | 1 | 0 | If 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_storecredit | Float | The monetary value of the amount of Store Credit to be applied to the basket. | No |
remove_storecredit | 1 | 0 | If this parameter is provided, then any Store Credit currently applied to the basket will be removed. | No |
collect_in_store | 1 | 0 | If 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_delivery | 1 | 0 | No | |
store_id | Integer | The 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_id | Integer | The 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_name | String | The 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 Name | Values | Example | Description |
---|---|---|---|
success | Boolean | true | This 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. |
error | Array | FALSE | false | This will be FALSE if there are no errors to report, but will contain the error details if there are. |
error.message | String | This 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_items | Array or String | Dependant 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_items | Array | An array of removed items for use with tracking or any other custom process(es) you may wish to implement. | |
collect_plus_available | Boolean | true | Indicates whether Collect Plus is available for the current basket. |
delivery_options | Array | An array of available delivery options for the current basket. | |
delivery_options_html | String | The 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_time | Array | This contains various details regarding the currently selected delivery option. | |
delivery_time.name | String | This is the name of the currently selected delivery option. | |
delivery_time.time | String | 2 days | The time in days that the delivery option usually ships within (as configured in the Aurora Back-end). |
delivery_time.estimate | String | The shipping estimate generated by Aurora based on the current basket and selected delivery option. | |
delivery_time.totalCost | String | £29.99 | The total cost of the basket in the currently selected currency that was used for shipping calculations, with any appropriate currency formatting applied. |
delivery_time.shippingCost | Float | 2.99 | The total cost of the shipping in the currently selected currency, as a raw float value. |
delivery_time.discount | String | £5.99 | The total discount applied to the basket in the currently selected currency that was used for shipping calculations, with any appropriate currency formatting applied. |
delivery_cost | String | £2.99 | The total cost of the shipping in the currently selected currency, with any appropriate currency formatting applied. |
delivery_cost_float | Float | 2.99 | The total cost of the shipping in the currently selected currency, as an unmodified float value. |
order_subtotal | String | £28.00 | The subtotal of the basket in the currently selected currency, with any appropriate currency formatting applied. |
order_total | String | £24.00 | The total of the basket in the currently selected currency, with any appropriate currency formatting applied. |
order_total_float | Float | 24.00 | The total of the basket in the currently selected currency, as an unmodified float value. |
payment_cost | String | £24.00 | The 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_float | Float | 24.00 | The total payment due for the basket in the currently selected currency, as an unmodified float value. |
discount | String | £5.99 | The total discount applied to the basket in the currently selected currency, with any appropriate currency formatting applied. |
discount_value | Float | 5.99 | The total discount applied to the basket in the currently selected currency, as an unmodified float value. |
has_discount | Integer | 1 | Is there a discount applied to the basket? 1 for yes and 0 for no. |
loyalty_points | Integer | 123 | The number of loyalty point applied to the current basket. |
available_loyalty_points | Integer | 3000 | The number of loyalty point that the current user has available to them (requires the customer to be logged-in). |
applied_credit | String | £20.00 | The total amount of Store Credit applied to the basket in the currently selected currency, with any appropriate currency formatting applied. |
applied_credit_float | Float | 20.00 | The total amount of Store Credit applied to the basket in the currently selected currency, as an unmodified float value. |
available_credit | String | £100.00 | The 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_float | Float | 100.00 | The 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_spend | String | £30 | The 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_show | Integer | 1 | Is Free Shipping already available on the current basket? 1 for yes and 0 for no. |
cross_sells | String | The 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_enabled | Boolean | true | Is there a coupon currently applied to the basket? 1 for yes and 0 for no. |
total_cross_sells | Integer | 8 | A count of the number of cross sell products found for the current basket contents. |
shipping_country | Integer | 23 | Aurora's Internal ID for the currently selected shipping country. |
shipping_countries | Array | An array of the currently available shipping countries, as configured in the Aurora Back-end. | |
feedback | String | Provides 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_error | String | If 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_information | String | This will include any customs information configure in the Aurora Back-end for the currently selected shipping country. | |
paypal_credit_allowed | Boolean | true | Indicates 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
Parameter | Values | Description | Required |
---|---|---|---|
delete_basket_item | Integer | The 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 Name | Values | Description |
---|---|---|
0 | String HTML | The merged basket contents ready for display. This content is generated using the 'basket/dropdownbasket.tpl.html' Front-end Template. |
1 | Integer | The 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. |
2 | Float | The total value of the Basket excluding Shipping Charges. |
removed_basket_items | Array | An 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
Parameter | Values | Description | Required |
---|---|---|---|
product_id | Integer/Array | The 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_quantity | Integer/Array | The 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 |
attributes | String | A 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
Parameter | Values | Description | Required |
---|---|---|---|
product_id | Integer/Array | Deprecated - 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_fields | String | A 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_id | Integer/Array | The 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_id | Integer/Array | The 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_quantity | Integer/Array | The 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_id | Integer | The 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 Name | Values | Description |
---|---|---|
0 | String HTML | The basket contents ready for display. This content is generated using the 'basket/dropdownbasket.tpl.html' Front-end Template. |
1 | Integer | The 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. |
2 | String | Always: "Items" |
3 | Float | The total value of the basket. |
4 | Float | The subtotal of the basket excluding shipping and tax. |
5 | Float | The subtotal of the basket excluding shipping. |
6 | Array | An 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. |
7 | Array | An 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') });
Updated about 1 year ago