Sha256: 2e09450c4e65a9db12f99864aceb2035e67c4f6dfa22ca4eeadfe1b35dac1424

Contents?: true

Size: 1.49 KB

Versions: 44

Compression:

Stored size: 1.49 KB

Contents

// This file contains the code for interacting with line items in the manual cart
$(document).ready(function () {
    'use strict';

    // handle variant selection, show stock level.
    $('#add_line_item_variant_id').change(function(){
        var variant_id = $(this).val();

        var variant = _.find(window.variants, function(variant){
            return variant.id == variant_id
        })
        $('#stock_details').html(variantLineItemTemplate({variant: variant}));
        $('#stock_details').show();

        $('button.add_variant').click(addVariant);
    });
});

addVariant = function() {
    $('#stock_details').hide();

    var variant_id = $('input.variant_autocomplete').val();
    var quantity = $("input.quantity[data-variant-id='" + variant_id + "']").val();

    adjustLineItems(order_number, variant_id, quantity);
    return 1
}

adjustLineItems = function(order_number, variant_id, quantity){
    var url = Spree.routes.orders_api + "/" + order_number + '/line_items';

    $.ajax({
        type: "POST",
        url: Spree.url(url),
        data: {
          line_item: {
            variant_id: variant_id,
            quantity: quantity
          },
          token: Spree.api_key
        }
    }).done(function( msg ) {
        window.Spree.advanceOrder();
        window.location.reload();
    }).fail(function(msg) {
      if (typeof msg.responseJSON.message != 'undefined') {
        alert(msg.responseJSON.message);
      } else {
        alert(msg.responseJSON.exception);
      }
    });
}

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
spree_backend-3.4.6 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.2.9 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.6 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.5 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.4 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.3 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.2 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.1 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.0 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.5.0 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.3.6 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.2.8 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.6.0.rc1 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.5.0.rc2 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.5.0.rc1 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.4.5 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.3.5 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.4.4 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.4.3 app/assets/javascripts/spree/backend/line_items_on_order_edit.js
spree_backend-3.3.4 app/assets/javascripts/spree/backend/line_items_on_order_edit.js