0

I have next problem:

$.ajax({
    url: 'index.php?route=checkout/cart/add',
    type: 'post',
    data: { product_id:product_id, quantity:quantity, "option[30]":product_option_id},
    dataType: 'json',

I have an ajax function that must return key option[value] and it's value product_option_id. My function takes three parameters:

function addTocartN(product_id, product_option_id, product_option) {

So i need to get data like this:

data: { product_id:product_id, quantity:quantity, "option[product_option]":product_option_id}

How i can do this?

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
Shevko
  • 51
  • 6

1 Answers1

0
function addToCartN(product_id, product_option_id, product_option) {

  var data = {};
  data.product_id = product_id;

  var optionKeyStr = "option[" + product_option + "]";
  data[optionKeyStr] = product_option_id;

  ...

  $.ajax({
    url: ...,
    type : ...,
    data : data,
    ...
  });

}
abl
  • 5,970
  • 4
  • 25
  • 44