removeFromCart

This function must be called every time a product is removed from cart.

In the following paragraphs of the removeFromCart function, we will talk about "variations" of the products. Variation of a product is the product's properties group the user has to choose when he is willing to remove a product from cart: color, size, capacity, etc. For example, an online fashion store can set a system based on color and size variations: "Y - 32" (yellow color and size 32), "R - XS" (red color and size XS), "M" (size M) etc.

   _ra.removeFromCart(product_id, quantity, {
       "code": "color-size",
       "stock": stock,
       "details": {
           "var_code_option": {
               "category_name": "var_code_option_category_name",
               "category": "var_code_option_category_unique_token",
               "value": "var_code_option_value_name"
           },
           ...
       }
   }, callback_function);

executing scripts automatically when the page is loaded

    var _ra = _ra || {};

    _ra.removeFromCartInfo = {
        "product_id": product_id,
        "quantity": product_quantity,
        "variation": {
            "code": "color-size",
            "stock": stock,
            "details": {
                "var_code_option": {
                    "category_name": "var_code_option_category_name",
                    "category": "var_code_option_category_unique_token",
                    "value": "var_code_option_value_name"
                },
                ...
            }
        }
    };

    if (_ra.ready !== undefined) {
        _ra.removeFromCart(
            _ra.removeFromCartInfo.product_id,
            _ra.removeFromCartInfo.quantity,
            _ra.removeFromCartInfo.variation
        );
    }

removeFromCart function parameters

Field Type Required Description
id number or text True The product id
variation object / false True object with details about chosen variation details for the product added to cart. If the product does not have variation send false value. The object containing the details of the chosen variation has the following properties: code, details
variation.code text True unique combination of properties that form the variation of product, separated by simple line (-). It is mandatory to use a simple dash (-) to separate the options of variation
variation.stock bool True false - out of stock, true - in stock
variation.details object True The product name
variation.details.variation_code_option.category_name text True object that contains details about each variation option. Object details contains properties with the name of the property codes variation, and each property is an object containing the following properties: category_name, category, value
variation.details.variation_code_option.category text True Unique token or unique id of the category to which it belongs variation_code_option property code
variation.details.variation_code_option.value text True Full name of the variation_code_option property code
callback_function function False With this parameter you can define a function that runs itself after the action's parent function executes

removeFromCart function examples

send remove from cart event for a product without variation removing from cart is done in the product page

   _ra.removeFromCart(50, 1, false, function() {
       console.log("the information has been sent");
   });

executing scripts automatically when the page is loaded

   _ra.removeFromCartInfo = {
       "product_id": 133,
       "quantity": 1,
       "variation": {
           "code": "color-size",
           "stock": true,
           "details": {,
                "B": {
                   "category_name": "Color",
                   "category": "color",
                   "value": "Black"
                },
                "42": {
                   "category_name": "Size",
                   "category": "size",
                   "value": "42"
                }
           }
       }
   };

   if (_ra.ready !== undefined) {
       _ra.removeFromCart(
           _ra.removeFromCartInfo.product_id,
           _ra.removeFromCartInfo.quantity,
           _ra.removeFromCartInfo.variation
       );
   }