Ajax Basket Variation

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

Ajax Method Group: Ajax_Frontend_Basket_Variation

updateVariation

Overview

Permission Required: None

Method Call: /ajax/Ajax_Frontend_Basket_Variation/updateVariation

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

📘

The updateVariation method allows you to update a product that is currently in a users basket with a new variation, e.g. they have size 10 in their basket, yet they want the same item but in size 12.

Request Variables

VariableValuesRequiredDescription
basket_idIntegeryesThe ID of the basket item that you are updating i.e.

<br>123<br>
attributesStringyesA serialised representation of the selected product attribute i.e.

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

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

These values can be established using the basket data as follows:

{foreach from=$basket item="item"}
 <input type="hidden" value="{$item.id}" class="item_id_1"/>
 {foreach from=$item.product.attributes item="attribute"}
  <span>Select {$attribute.attribute_name}</span>
   <select name="attributes[{$attribute.id}]" class="prod_attributes_1">
    {foreach from=$attribute.values item="value"}
     <option value="{$value.id}">{$value.attribute_value}</option>
    {/foreach}
   </select>
 {/foreach}
 ...
 <script type="text/javascript>
 $.aurora.post(
  '/ajax/Ajax_Frontend_Basket_Variation/updateVariation',
  {
   basket_id: $('.item_id_1'),val(), 
   attributes: $('.prod_attributes_1').serialize()
  }, 
  function(response_data) {
   ...
  }, 
  'json'
 );
 <script>
{/foreach}

Response Variables

If the request has gone through, you will receive the following:

{"correct":"true"}

If you have requested for an item to be updated to one with less stock than the currently selected item, you will receive an error back:

{"error":{"available_stock":"12","desired_stock":"17","product":"Goodfellas"}}
VariableValuesDescription
available_stockIntegerHow much stock is available for the variation
desired_stockIntegerHow much stock you tried to add
productStringThe name of the product