1/* 2 * Add to Cart Button Change and Pop-up Notification 3 * OpenCart Version: 2.3-3.x 4 * Author: MagDevel ([email protected]) 5 * Homepage: https://magdevel.com/ 6 */ 7 8function abcUpdateMiniCart() { 9 $("#cart > ul").load("index.php?route=common/cart/info ul li"); 10} 11 12function abcNotify(text, type) { 13 if (window.abcData && window.abcData.show_notification === '1') { 14 var icon = ""; 15 16 if (type === "success") { 17 icon = "fa fa-check-circle"; 18 } else if (type === "info") { 19 icon = "fa fa-info-circle"; 20 } else if (type === "danger") { 21 icon = "fa fa-exclamation-circle"; 22 } 23 24 $('.alert').remove(); 25 26 $.notify({ 27 icon: icon, 28 message: text 29 }, { 30 type: type, 31 animate: { 32 enter: "animate__animated animate__bounceIn", 33 exit: "animate__animated animate__bounceOut" 34 }, 35 placement: { 36 from: "top", 37 align: "end" 38 }, 39 offset: 20, 40 spacing: 10, 41 delay: 3000 42 }); 43 } 44} 45 46function abcReplaceButton(product_id, quantity) { 47 if (window.abcData && 48 (window.abcData.replace_button_pp === '1') && 49 $("#button-cart").length && 50 ($("input[name='product_id']").val() == product_id) 51 ) { 52 var hasOptions = $("input, select, textarea").filter(function () { 53 return this.name.match(/option/); 54 }); 55 56 $("#button-cart, #atcp-button-cart").each(function () { 57 $(this).addClass("btn-in-cart " + product_id); 58 59 var btn_in_cart_value = abcData.btn_in_cart_pp.replace('{qty}', quantity); 60 61 if (!hasOptions.length) { 62 btn_in_cart_value = abcData.btn_in_cart_cp.replace('{qty}', quantity); 63 } 64 65 if ($(this).get(0).tagName == "INPUT") { 66 if (!$(this).attr("data-default-btn")) { 67 $(this).attr("data-default-btn", $(this).val()); 68 } 69 70 $(this).val(btn_in_cart_value); 71 } else { 72 if (!$(this).attr("data-default-btn")) { 73 $(this).attr("data-default-btn", $(this).html()); 74 } 75 76 $(this).html(btn_in_cart_value); 77 } 78 }); 79 } 80 81 if (window.abcData && window.abcData.replace_button_cp === '1') { 82 var btnCartSelector = '.button-group .add-to-cart-button'; 83 var btnCartFunction = 'addToCart'; 84 var btnInCartHtml = abcData.btn_in_cart_cp.replace('{qty}', quantity); 85 86 $(btnCartSelector).each(function () { 87 //console.log($(this)); 88 if ($(this).attr("onclick") && $(this).attr("onclick").indexOf(btnCartFunction) > -1) { 89 var dataProductId = $(this).data('product'); 90 91 //var cartFunctionArgs = $(this).attr("onclick").split(btnCartFunction)[1]; 92 93 //if (cartFunctionArgs.match(/([0-9]+)/g)[0] == product_id) { 94 if(dataProductId == product_id) { 95 if (!$(this).attr("data-default-btn")) { 96 $(this).attr("data-default-btn", $(this).html()); 97 } 98 99 $(this).addClass("btn-in-cart").html(btnInCartHtml); 100 } 101 } 102 }); 103 } 104} 105 106function abcReplaceButtons() { 107 if (window.abcData && window.abcData.products_in_cart) { 108 var product_id, quantity; 109 110 for (product_id in abcData.products_in_cart) { 111 quantity = abcData.products_in_cart[product_id]; 112 abcReplaceButton(product_id, quantity); 113 } 114 } 115} 116 117function abcResetButtons() { 118 $(".btn-in-cart").each(function () { 119 $(".btn-in-cart").removeClass("btn-in-cart").html($(this).attr("data-default-btn")); 120 }); 121} 122 123function abcUpdateButtons() { 124 $.ajax({ 125 url: 'index.php?route=extension/module/addtocart_button_change/getCartProducts', 126 type: 'post', 127 dataType: 'json', 128 success: function (json) { 129 abcResetButtons(); 130 if (json.cart_products) { 131 window.abcData.products_in_cart = JSON.parse(json.cart_products); 132 abcReplaceButtons(); 133 } 134 } 135 }); 136} 137 138function abcUpdateCartData() { 139 $.ajax({ 140 url: 'index.php?route=extension/module/addtocart_button_change/getCartProducts', 141 type: 'post', 142 dataType: 'json', 143 success: function (json) { 144 if (json.cart_products) { 145 window.abcData.products_in_cart = JSON.parse(json.cart_products); 146 } 147 } 148 }); 149} 150 151function abcAddToCart(product_id, quantity) { 152 quantity = quantity || 1; 153 154 if (window.abcData && 155 (window.abcData.btn_action_cp === '1') && 156 (product_id in window.abcData.products_in_cart) 157 ) { 158 return abcNotify(window.abcData.in_cart_notification, "info"); 159 } 160 161 $.ajax({ 162 url: 'index.php?route=checkout/cart/add', 163 type: 'post', 164 data: 'product_id=' + product_id + '&quantity=' + quantity, 165 dataType: 'json', 166 beforeSend: function () { 167 $('#cart > button').button('loading'); 168 }, 169 complete: function () { 170 $('#cart > button').button('reset'); 171 }, 172 success: function (json) { 173 $('.alert, .text-danger').remove(); 174 if (json.redirect) { 175 if (window.oip && oip.conf && oip.conf.use_on_category_page && typeof oip.OpenPopup === "function") { 176 return oip.OpenPopup(product_id); 177 } else { 178 location = json.redirect; 179 } 180 } 181 if (json.success) { 182 abcNotify(json.success, 'success'); 183 abcUpdateMiniCart(); 184 185 setTimeout(function () { 186 updateCartTotal(json['total']); 187 }, 100); 188 189 190 if (json.in_cart_qty) { 191 quantity = parseInt(json.in_cart_qty); 192 } 193 194 abcReplaceButton(product_id, quantity); 195 } 196 abcUpdateCartData(); 197 } 198 }); 199} 200 201function updateCartTotal(total) { 202 var url1 =$('base').attr('href') + 'image/catalog/CartIcon.png'; 203 $('#cart > button').html('<span id="cart-total"><img src="'+url1+'"></img>' + total + '</span>'); 204} 205 206function abcRemovefromCart(key) { 207 $.ajax({ 208 url: 'index.php?route=checkout/cart/remove', 209 type: 'post', 210 data: 'key=' + key, 211 dataType: 'json', 212 beforeSend: function () { 213 $('#cart > button').button('loading'); 214 }, 215 complete: function () { 216 $('#cart > button').button('reset'); 217 }, 218 success: function (json) { 219 $('.alert, .text-success').remove(); 220 abcUpdateMiniCart(); 221 setTimeout(function () { 222 updateCartTotal(json['total']); 223 }, 100); 224 225 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 226 location = 'index.php?route=checkout/cart'; 227 } 228 abcUpdateButtons(); 229 } 230 }); 231} 232 233$(document).ready(function () { 234 abcReplaceButtons(); 235 window.cart.add = function (product_id, quantity) { 236 return abcAddToCart(product_id, quantity); 237 } 238 window.cart.remove = function (key) { 239 return abcRemovefromCart(key); 240 } 241});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.