Which was intended only to show an abstract example of the implementation of a shopping cart, I did not think that it would generate so many questions and requests that poured in on the blog itself, and in my email, etc. Actually, that’s why I decided to write this plugin “jqCart”, but I want to immediately emphasize a few points:
So, for the plugin to work, the jQuery library >= 1.8 is required, which must be connected before connecting the plugin itself. It should work in all modern browsers and, in theory, even in IE8. The problem for old "donkeys" may only lie in the applied CSS properties and the version of jQuery ( Let me remind you that jQuery 2.x does not support Internet Explorer 6, 7, and 8). Data is transferred to the server using Ajax and therefore, I highly recommend using UTF-8 file encoding without BOM!
Connection:
Usage:
$(function() ( "use strict"; // initializing the plugin $.jqCart(( buttons: ".add_item", // button selector, ala "Add to cart" handler: "/php/handler.php", / / path to the handler visibleLabel: false, // show/hide the label when the cart is empty (default: false) openByAdding: false, // automatically open the cart when adding a product (default: false) currency: "€", // currency : string value, mnemonics (default "$") cartLabel: ".label-place" /* selector of the element where the label will be placed, also known as the "button" for opening the cart */ )); // additional methods $. jqCart("openCart"); // open cart $.jqCart("clearCart"); // clear cart ));
In the buttons ( "Add to Basket"), the following data attributes must be specified:
All values of the above data attributes take part in the formation of the cart window. You can add additional data attributes, the values of which will be sent with the rest of the data to the handler. The keys in the resulting array on the server will correspond to the attribute name after “data-”, i.e. the value of the attribute "data-somevalue" will be in the array under the key "somevalue" The tag for the button and its location on the page do not matter.
Add to Basket
In the archive you will find an example of a handler (handler.php) with preparing and sending a letter by email. At the end of the handler, there must be a response to the client in JSON format.