A Kilimanjaro question for the channel... When add...
# suitecommerce
m
A Kilimanjaro question for the channel... When adding an item to cart, is it possible to set a transaction line field at the same time? For background, I'm building a feature where a customer can purchase an extended warranty for a product that's registered to their account. The hope was that I could add the registered product's serial number on the line item for the extended warranty. I've tried the following, but it doesn't appear to set the field as I would hope.
Copy code
addTheAddOnItemToCart: function regProdModelAddToCart(itemIds) {
  var url = '/api/items?id=' + itemIds.join(',') + '&fieldset=details&currency=USD';
  var liveOrderModel = LiveOrderModel.getInstance();

  jQuery.ajax({
    type: 'get',
    url: url,
    data: '',
    contentType: 'application/json',
    dataType: 'jsonp',
    jsonpCallback: 'fnCallback',
    success: function (results) {
      var lines = [];

      results.items.forEach(function (item) {
        var item = new ItemModel(item);
        var product = new ProductModel({
          quantity: 1,
          item: item,
          _optionsDetails: [],
          options: []
        });

        product.setOption('custcol_serial_reference2', 'hi mom'); // Testing...

        lines.push(LiveOrderLineModel.createFromProduct(product));
      });

      var cart_promise = liveOrderModel.addLines(lines);
      CartConfirmationHelpers.showCartConfirmationMultiple(cart_promise, lines, SC._applications.MyAccount);

    },
    error: function (jqXHR, textStatus, errorThrown) {
      console.error('RegisteredProductsView: ' + textStatus + ' ... ' + errorThrown);
    },
    complete: function () {
      /* nothing for now */
    }
  });
},
Any ideas or suggestions?
e
m
Thanks for the suggestion. I'll give that a shot!
👌 1
k
Hey Mike, I think if want you leverage native item options, the options need to be defined in Netsuite and applied to the item record. Or you need to script the solution after a sales order is created. Scriptable cart can be useful, or a disaster for performance.
k
@Mike Herrera I am fairly certain you can use the transaction line field just like an item option field. You configure the field for the Store. Then on the client side you can set it in the lines option array in the LiveOrder.Model. I remember doing this a couple years back and my memory is foggy about the specifics.
m
Thank you @Keith Fetterman and @Kearobi. You guys are confirming my item option hunch that it's possible. I appreciate that a lot. I just need to get over my unknown obstacle...
e
If the scriptable cart is not the best option for you, Check the addLine method in the LiveOrder.Model suitescript file, you might need to set the value in the options there.
m
Thank you, everyone! I have a working solution using the LiveOrder.Model. It was a bit unexpected, so I'll write it up to share. Stand-by.
👍 2
In the end I added a custom transaction item option to hold my custom text value. I tried adding the custcol to the SCA config's different order items tables, but that didn't work for my use-case while in MyAccount. The breakthrough came when I found that I could manually intialize the product's options array so it would be capable of receiving my custom setOption calls. No other customizations or configurations were necessary. Thanks again for all the hints!
k
Nice!