Sha256: 43a3d2ca2bf6c3639e96274ed4bfa73ec1ace8ad5b24c8027c758fc3a4f9c0c6

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 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);

        // Add some tips
        $('.with-tip').powerTip({
            smartPlacement: true,
            fadeInTime: 50,
            fadeOutTime: 50,
            intentPollInterval: 300
        });

    });
});

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();
    });

}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_backend-2.4.10 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb
spree_backend-2.4.9 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb
spree_backend-2.4.8 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb
spree_backend-2.4.7 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb
spree_backend-2.4.6 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb
spree_backend-2.4.5 app/assets/javascripts/spree/backend/line_items_on_order_edit.js.erb