Tuesday, November 4, 2014

Using Javascript for Eval | AjaxAddOrderItem | Adding multiple parts to Cart

I ran into this problem in the past and realized, it's hard to remember the eval function and without that you could end up spending a lot of time, trying to figure out passing multiple params with dynamic values. (partNumber_1, quanitty_1...partNumber_2, quantity_2).

eval() evaluates the expression in the argument. If the argument is one or more JavaScript statements, eval() executes the statements.
E.g. service code.

    var renderCtx = wc.render.getContextById("AjaxAddToCartContext");
     //setting context properties  
    renderCtx.properties['partNumber'] = partNumber;
    renderCtx.properties['quantity'] = quantity;

     eval("params.partNumber_" + counter + "='"+partNumber+ "';");
     eval("params.quantity_" + counter + "="+quantity+ ";");
    //invoke the AJAX service for orderitem add (Cart Service)
     wc.service.getServiceById("AjaxAddOrderItem").formId = orderFormId;
     wc.service.invoke("AjaxAddOrderItem", params);

5 comments:

  1. Many individuals require the chance to acquire a little measure of money that would be accessible in their next paycheck and a few organizations will go after that.Check Cashing

    ReplyDelete
  2. Thanks for sharing this such an informative and useful blog and beneficial. If anyone wants to become front end developer join the good IT company -
    best Node JS development company
    iPhone application development company

    ReplyDelete
  3. Enhorabuena por el artículo, muy buena redacción, se nota claramente que le pones esfuerzo y ganas.

    ReplyDelete
  4. Muy buen post, gracias por compartir esta información, sin duda seguiré esperando a que subas más contenido.

    ReplyDelete
  5. Services included keyword research, buy curated links, data pulls, and monthly link building.

    ReplyDelete