/**************************************************************** Copyright (c) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ function getFormElement(id, formName) { if(!formName) { formName = '0'; } if(document.forms[formName]) { return document.forms[formName][id]; } return null; } function cart( email ) { this.totalItems = 0; this.totalPrice = 0.00; this.items = new Array(); this.userEmail = email; // order of columns, you change the order here or by accessing the value in your html this.ItemColumns = ['Image','Name','Price','Options','Quantity','Total']; this.ItemColumnsNames = ['','Название','Цена','Модель','Кол-во','Сумма']; /* function to initialize the cart when the page is loaded */ this.initialize = function () { if( !readCookie("simpleCart") ) { this.totalItems = 0; this.totalPrice = 0.00; } else { data = readCookie("simpleCart").split("&"); this.totalItems = data[0]*1; this.totalPrice = data[1]*1; for(x=2;x < (data.length);x++) { newItem = new item(); itemData = data[x].split(","); i=0; for(i=0;i 0) { element.innerHTML = "Итого: " + this.returnTotalPrice(); } else { element.innerHTML = ''; } } x=0; elements = getElementsByClassName('simpleCart_quantity'); for( x=0;x 0) { element.innerHTML = String(this.totalItems); } else { element.innerHTML = ''; } } elements = getElementsByClassName('simpleCart_items'); for( x=0;x'; } } if( this.ItemColumns[i] == 'Name' ) { tempCell.innerHTML = tempItem.getValue('name'); } else if ( this.ItemColumns[i] == 'Price' ) { tempCell.innerHTML = this.returnFormattedPrice( tempItem.getValue('price')); } else if ( this.ItemColumns[i] == 'Options' && this.options() ) { tempCell.innerHTML = tempItem.optionList(); } else if ( this.ItemColumns[i] == 'Quantity' ) { tempCell.innerHTML = ''; } else if ( this.ItemColumns[i] == 'Total' ) { tempCell.innerHTML = this.returnFormattedPrice( tempItem.getValue('quantity')* tempItem.getValue('price') ); } newRow.appendChild(tempCell); } newRow.className = "itemContainer" cartTable.appendChild(newRow); } if(this.items.length == 0) { newRow = document.createElement('div'); newRow.innerHTML='
Ваша корзина пустая
'; newRow.className = "itemContainer" cartTable.appendChild(newRow); } // create totals row newRow = document.createElement('div'); tempCell = document.createElement('div'); tempCell.innerHTML = String(this.totalItems); tempCell.className = "totalItems"; newRow.appendChild(tempCell); tempCell = document.createElement('div'); tempCell.innerHTML = this.returnTotalPrice(); tempCell.className = "totalPrice"; newRow.appendChild(tempCell); newRow.className = "totalRow"; cartTable.appendChild(newRow); } elements = getElementsByClassName('simpleCart_sidebox_items'); for( x=0;x'; } } if( this.ItemColumns[i] == 'Name' ) { tempCell.innerHTML = tempItem.getValue('name') + " - " + tempItem.getValue('quantity') + " шт."; newRow.appendChild(tempCell); // } else if ( this.ItemColumns[i] == 'Price' ) { // tempCell.innerHTML = this.returnFormattedPrice( tempItem.getValue('price')); // newRow.appendChild(tempCell); // } else if ( this.ItemColumns[i] == 'Quantity' ) { // tempCell.innerHTML = " - " + tempItem.getValue('quantity') + " шт. "; // newRow.appendChild(tempCell); } else if ( this.ItemColumns[i] == 'Total' ) { tempCell.innerHTML = "Сумма: " + this.returnFormattedPrice( tempItem.getValue('quantity')* tempItem.getValue('price') ); newRow.appendChild(tempCell); } } newRow.className = "sideboxItemContainer" cartTable.appendChild(newRow); } if(this.items.length == 0) { newRow = document.createElement('div'); newRow.innerHTML='нет ничего'; newRow.className = "sideboxItemContainer center" cartTable.appendChild(newRow); } // create totals row newRow = document.createElement('div'); tempCell = document.createElement('div'); tempCell.innerHTML = String(this.totalItems); tempCell.className = "sideboxTotalItems"; newRow.appendChild(tempCell); tempCell = document.createElement('div'); tempCell.innerHTML = this.returnTotalPrice(); tempCell.className = "sideboxTotalPrice"; newRow.appendChild(tempCell); newRow.className = "sideboxTotalRow"; cartTable.appendChild(newRow); } var orderBody = getFormElement("orderBody"); if(orderBody && (orderBody != null)) { var content = ''; // create the header for( x=0;x 0) { if(content .length > 0) { content += ","; } content += this.ItemColumnsNames[x]; } } } content = "\n" + content + "\n"; // create a row for each item x=0; for( x=0;x