| 1 |
|
$(document).ready(function() { |
| 2 |
|
|
| 3 |
|
$(".magento-add-to-cart").click(function() { |
| 4 |
|
var prod_id = $(this).attr("product_id"); |
| 5 |
|
var title = $(this).attr("product_title"); |
| 6 |
|
var path = Drupal.settings.magento.add_url[0]; |
| 7 |
|
var img = Drupal.settings.magento.trobber_image[0]; |
| 8 |
|
if (prod_id && title && path && img) { |
| 9 |
|
add_item(prod_id, title, path, img); |
| 10 |
|
} |
| 11 |
|
}); |
| 12 |
|
|
| 13 |
|
$(".magento-clear-cart").click(function() { |
| 14 |
|
var path = Drupal.settings.magento.clear_url[0]; |
| 15 |
|
if (path) { |
| 16 |
|
clear_cart(path); |
| 17 |
|
} |
| 18 |
|
}); |
| 19 |
|
|
| 20 |
|
$("div#block-magento_orders-user .cart_block").each(function() { |
| 21 |
|
if ($(this).hasClass("empty")) { |
| 22 |
|
$("div#block-magento_orders-user").addClass("hidden"); // attr("display", "none"); |
| 23 |
|
} |
| 24 |
|
}); |
| 25 |
|
|
| 26 |
|
magento_cart_make_jq_comboboxes(); |
| 27 |
|
}); |
| 28 |
|
|
| 29 |
|
/*-------------------------*/ |
| 30 |
|
|
| 31 |
|
function delete_item($product_id, $product_title, $path) { |
| 32 |
|
$.post($path, { id: $product_id, title: $product_title}, function(data){ |
| 33 |
|
// reload cart block |
| 34 |
|
$("div#block-magento_orders-user div.in").html(data); |
| 35 |
|
}); |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
function clear_cart($path) { |
| 39 |
|
$.post($path, {}, function(data){ |
| 40 |
|
// reload cart block |
| 41 |
|
$("div#block-magento_orders-user div.in").html(data); |
| 42 |
|
}); |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
function add_item($product_id, $product_title, $path, $image) { |
| 46 |
|
// Set qty value |
| 47 |
|
$qty = 1; |
| 48 |
|
// Start throbber |
| 49 |
|
$("span#throbber_"+$product_id).html('<img src="'+$image+'"/></img>'); |
| 50 |
|
|
| 51 |
|
$.post($path, { id: $product_id , title: $product_title, qty: $qty }, function(data){ |
| 52 |
|
// check if error was returned or new html for cart block |
| 53 |
|
var text = /^\s*<[a-z]/i.test(data); |
| 54 |
|
// reload cart block or show error message |
| 55 |
|
if (text) { |
| 56 |
|
$("div#block-magento_orders-user div.in").html(data); |
| 57 |
|
$("div#block-magento_orders-user").removeClass("hidden"); |
| 58 |
|
} else { |
| 59 |
|
alert(data); |
| 60 |
|
} |
| 61 |
|
// Set qty value in form to 0 |
| 62 |
|
// $("#edit-product-count-"+$product_id).val(0); |
| 63 |
|
// Stop throbber |
| 64 |
|
$("span#throbber_"+$product_id).html(''); |
| 65 |
|
}); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
function magento_cart_make_jq_comboboxes() { |
| 69 |
|
if ($("#magento-orders-view-cart-form #edit-country-id").length) { |
| 70 |
|
var elementJQ = $("#magento-orders-view-cart-form #edit-country-id").combobox( |
| 71 |
|
{ |
| 72 |
|
comboboxContainerClass: "comboboxContainer", |
| 73 |
|
comboboxValueContainerClass: "comboboxValueContainer", |
| 74 |
|
comboboxValueContentClass: "comboboxValueContent", |
| 75 |
|
comboboxDropDownClass: "comboboxDropDownContainer", |
| 76 |
|
comboboxDropDownButtonClass: "comboboxDropDownButton", |
| 77 |
|
comboboxDropDownItemClass: "comboboxItem", |
| 78 |
|
comboboxDropDownItemHoverClass: "comboboxItemHover", |
| 79 |
|
comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", |
| 80 |
|
comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", |
| 81 |
|
width: "280px", |
| 82 |
|
onChange: function(){$("#edit-get-quote").trigger('click');} |
| 83 |
|
}); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|