├── .travis.yml ├── .gitignore ├── .github └── FUNDING.yml ├── .npmignore ├── composer.json ├── bower.json ├── LICENSE ├── test ├── test.js └── test-template.html ├── package.json ├── examples ├── results.php ├── index.html └── paypal.html ├── CONTRIBUTING.md ├── karma.conf.js ├── dist ├── css │ ├── smart_cart.min.css │ └── smart_cart.css └── js │ ├── jquery.smartCart.min.js │ └── jquery.smartCart.js ├── gulpfile.js ├── src ├── css │ └── smart_cart.css └── js │ └── jquery.smartCart.js └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /mpp-sc.txt 2 | /bower_components 3 | /node_modules/ 4 | /vendor/ 5 | coverage 6 | .DS_Store 7 | 8 | # IDE Files 9 | #------------------------- 10 | /nbproject/ 11 | /nbproject/private/ 12 | .idea/* 13 | .vscode/* 14 | .tmp 15 | ## Sublime Text cache files 16 | *.tmlanguage.cache 17 | *.tmPreferences.cache 18 | *.stTheme.cache 19 | *.sublime-workspace 20 | *.sublime-project 21 | /examples/test-page.html -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: [https://www.paypal.me/dipuraj] 13 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Automatically ignored per: 2 | # https://www.npmjs.org/doc/developers.html#Keeping-files-out-of-your-package 3 | # 4 | # .*.swp 5 | # ._* 6 | # .DS_Store 7 | # .git 8 | # .hg 9 | # .lock-wscript 10 | # .svn 11 | # .wafpickle-* 12 | # CVS 13 | # npm-debug.log 14 | # node_modules 15 | 16 | *.seed 17 | *.log 18 | *.csv 19 | *.dat 20 | *.out 21 | *.pid 22 | *.gz 23 | *.orig 24 | *.jql.js 25 | 26 | work 27 | build 28 | src 29 | test 30 | spec 31 | pids 32 | logs 33 | results 34 | coverage 35 | lib-cov 36 | html-report 37 | xunit.xml 38 | 39 | .project 40 | .idea 41 | .settings 42 | .iml 43 | *.sublime-workspace 44 | *.sublime-project 45 | 46 | ehthumbs.db 47 | Icon? 48 | Thumbs.db 49 | .AppleDouble 50 | .LSOverride 51 | .Spotlight-V100 52 | .Trashes -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "techlab/jquery-smartcart", 3 | "description": "The smart interactive jQuery Shopping Cart plugin with PayPal payment support", 4 | "homepage": "http://techlaboratory.net/smartcart", 5 | "license": "MIT", 6 | "support": { 7 | "source": "https://github.com/techlab/SmartCart", 8 | "issues": "https://github.com/techlab/SmartCart/issues", 9 | "docs": "http://techlaboratory.net/smartcart/documentation" 10 | }, 11 | "keywords": [ 12 | "jquery", 13 | "cart", 14 | "paypal", 15 | "shopping", 16 | "bootstrap", 17 | "ui", 18 | "jquery-plugin" 19 | ], 20 | "authors": [ 21 | { 22 | "name": "Dipu Raj", 23 | "email": "hello@techlaboratory.net", 24 | "homepage": "http://dipuraj.me" 25 | } 26 | ], 27 | "require": { 28 | "components/jquery": ">=1.9", 29 | "components/bootstrap": ">=3.0.0" 30 | } 31 | } -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-smartcart", 3 | "version": "v3.0.1", 4 | "homepage": "http://techlaboratory.net/smartcart", 5 | "authors": [ 6 | "Dipu Raj " 7 | ], 8 | "description": "The smart interactive jQuery Shopping Cart plugin with PayPal payment support", 9 | "main": [ 10 | "./dist/css/smart_cart.css", 11 | "./dist/js/jquery.smartCart.js" 12 | ], 13 | "keywords": [ 14 | "jquery", 15 | "cart", 16 | "paypal", 17 | "shopping", 18 | "bootstrap", 19 | "ui", 20 | "jquery-plugin" 21 | ], 22 | "dependencies": { 23 | "jquery": ">= 1.9.0", 24 | "bootstrap": ">= 3.0.0" 25 | }, 26 | "license": "MIT", 27 | "ignore": [ 28 | "**/.*", 29 | "node_modules", 30 | "composer.json", 31 | "examples", 32 | "bower_components", 33 | ".git*", 34 | ".travis*", 35 | "*bower.json", 36 | "*jquery.json", 37 | "test" 38 | ] 39 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Dipu Raj 4 | http://www.techlaboratory.net 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | describe('SmartCart Default Options', function() { 2 | var el, plugin; 3 | 4 | beforeEach(function(){ 5 | jasmine.getFixtures().fixturesPath = 'base/test'; 6 | loadFixtures('test-template.html'); 7 | 8 | el = $('#smartcart'); 9 | plugin = el.smartCart(); 10 | }); 11 | 12 | afterEach(function(){ 13 | el.remove(); 14 | el = null; 15 | }); 16 | 17 | it('should add default theme to the main element', function() { 18 | expect(el).toHaveClass("sc-theme-default"); 19 | }); 20 | 21 | it('should add cart hidden element', function() { 22 | expect(el.children('#cart_list')).toExist(); 23 | }); 24 | 25 | it('should add cart list elements', function() { 26 | expect(el.children('.sc-cart-heading')).toExist(); 27 | expect(el.children('.sc-cart-item-list')).toExist(); 28 | }); 29 | 30 | it('should add cart toolbar elements', function() { 31 | var toolbar = el.children('.sc-toolbar'); 32 | expect(toolbar).toExist(); 33 | expect(toolbar.children('.sc-cart-toolbar')).toExist(); 34 | expect(toolbar.children('.sc-cart-summary')).toExist(); 35 | 36 | var toolbarBtn = toolbar.children('.sc-cart-toolbar'); 37 | expect(toolbarBtn.children('.sc-cart-checkout')).toExist(); 38 | expect(toolbarBtn.children('.sc-cart-clear')).toExist(); 39 | }); 40 | 41 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-smartcart", 3 | "version": "v3.0.1", 4 | "description": "The smart interactive jQuery Shopping Cart plugin with PayPal payment support", 5 | "homepage": "http://techlaboratory.net/smartcart", 6 | "license": "MIT", 7 | "author": "Dipu Raj ", 8 | "contributors": [ 9 | { 10 | "name": "Dipu Raj", 11 | "email": "hello@techlaboratory.net" 12 | } 13 | ], 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://techlab@github.com/techlab/SmartCart.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/techlab/SmartCart/issues" 20 | }, 21 | "keywords": [ 22 | "jquery", 23 | "cart", 24 | "paypal", 25 | "shopping", 26 | "bootstrap", 27 | "ui", 28 | "jquery-plugin" 29 | ], 30 | "main": "", 31 | "scripts": { 32 | "start": "", 33 | "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS", 34 | "build": "gulp", 35 | "clean": "gulp clean", 36 | "lint": "gulp lint" 37 | }, 38 | "dependencies": { 39 | "jquery": ">=1.9.0", 40 | "bootstrap": ">=3.0.0" 41 | }, 42 | "devDependencies": { 43 | "autoprefixer": "^6.7.7", 44 | "del": "^2.2.2", 45 | "gulp": "^3.9.1", 46 | "gulp-babel": "^6.1.2", 47 | "gulp-clean-css": "^3.0.4", 48 | "gulp-cssbeautify": "^0.1.3", 49 | "gulp-jasmine": "^2.4.2", 50 | "gulp-jshint": "^2.0.4", 51 | "gulp-karma": "0.0.5", 52 | "gulp-postcss": "^6.4.0", 53 | "gulp-rename": "^1.2.2", 54 | "gulp-uglify": "^2.1.1", 55 | "jasmine-core": "^2.5.2", 56 | "jasmine-jquery": "^2.1.1", 57 | "jshint": "^2.9.4", 58 | "karma": "^1.5.0", 59 | "karma-chrome-launcher": "^2.0.0", 60 | "karma-cli": "^1.0.1", 61 | "karma-jasmine": "^1.1.0", 62 | "karma-jasmine-html-reporter": "^0.2.2", 63 | "karma-jasmine-jquery": "^0.1.1", 64 | "karma-phantomjs-launcher": "^1.0.4", 65 | "karma-spec-reporter": "0.0.31" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/results.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Smart Cart - jQuery Shopping Cart Plugin 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | $value) { 24 | //var_dump($key, $value); 25 | $result_html .= $key.": ".$value."
"; 26 | } 27 | $result_html .= '------------------------------------------
'; 28 | } 29 | } else { 30 | $result_html .= "Cart is Empty"; 31 | } 32 | ?> 33 | 34 |
35 |
36 |
37 |
38 |
39 |
40 | Cart Products 41 |
42 |
43 | Full JSON Result
44 | 45 | 46 | 47 |

48 | Product List
49 | 50 |
51 |
52 |
53 |
54 |
55 | 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## What can I contribute? 4 | - Fix a bug you found or already reported on the [GitHub Issues Tracker](https://github.com/techlab/SmartCart/issues/). 5 | - Add new features to the project. 6 | - Add new test cases. 7 | - Add documentation 8 | - Add a demo page 9 | - [Donate](https://www.paypal.me/dipuraj) money for the project on [Paypal](https://www.paypal.me/dipuraj) 10 | 11 | ## How to contribute code 12 | Here are the basic steps to get started contributing: 13 | 14 | 1. Fork the [repo](https://github.com/techlab/SmartCart/) and get development running on your computer. 15 | 2. Replicate the issue you're trying to fix or spec out the feature you're trying to add. 16 | 3. Change the code to fix the bug or add the feature. All changes should happen in the relevant `src/js/*.js` and `src/css/*.css` files. 17 | 4. Build the code by running `npm run build` or `gulp build` 18 | 5. Run the test cases by running `npm test` or `gulp test`, you can also add more test cases based on your new change. 19 | 6. Verify that your fix or feature works. 20 | 7. Commit your changes with an informative description 21 | 8. Open a pull request to the [repo](https://github.com/techlab/SmartCart/) with your new commit and a descriptive message about what the PR does. 22 | 23 | ## Reporting bugs 24 | ### Make sure it is a bug related to this project 25 | Before reporting the bug, please make sure that the bug is in the project and not from your own code or any other library used. 26 | 27 | ### Try the latest version 28 | Bugs in the older versions of the project may have already been fixed. 29 | In order to avoid reporting known issues, make sure you are always testing against the latest release. 30 | Also make sure the problem hasn't already been reported on the [GitHub Issues Tracker](https://github.com/techlab/SmartCart/issues/). 31 | If not, create a new issue there and include your test case. 32 | 33 | ### Notes for pull request 34 | - Follow the same code style as the library. 35 | - Run the test suites in the `test` directory first by running `npm test` or `gulp test`. 36 | - Don't modify any files in the `dist` directory. -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | 3 | module.exports = function(config) { 4 | config.set({ 5 | 6 | // base path that will be used to resolve all patterns (eg. files, exclude) 7 | basePath: '', 8 | 9 | 10 | // frameworks to use 11 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 12 | frameworks: ['jasmine-jquery','jasmine'], 13 | 14 | 15 | // list of files / patterns to load in the browser 16 | files: [ 17 | 'test/*.js', 18 | 'node_modules/jquery/dist/jquery.min.js', 19 | 'src/js/*.js', 20 | { 21 | pattern: 'test/*.html', 22 | watched: true, 23 | served: true, 24 | included: false 25 | } 26 | ], 27 | 28 | 29 | // list of files to exclude 30 | exclude: [ 31 | ], 32 | 33 | 34 | // preprocess matching files before serving them to the browser 35 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 36 | preprocessors: { 37 | }, 38 | 39 | 40 | // test results reporter to use 41 | // possible values: 'dots', 'progress' 42 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 43 | reporters: ['spec'], 44 | 45 | 46 | // web server port 47 | port: 9876, 48 | 49 | 50 | // enable / disable colors in the output (reporters and logs) 51 | colors: true, 52 | 53 | 54 | // level of logging 55 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 56 | logLevel: config.LOG_INFO, 57 | 58 | 59 | // enable / disable watching file and executing tests whenever any file changes 60 | autoWatch: false, 61 | 62 | 63 | // start these browsers 64 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 65 | browsers: ['PhantomJS'], 66 | 67 | 68 | // Continuous Integration mode 69 | // if true, Karma captures browsers, runs the tests and exits 70 | singleRun: true, 71 | 72 | // Concurrency level 73 | // how many browser should be started simultaneous 74 | concurrency: Infinity 75 | }) 76 | } 77 | -------------------------------------------------------------------------------- /dist/css/smart_cart.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.x 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */.sc-cart-item-list{min-height:50px}.sc-cart-remove{background:0 0;border:none;font-size:20px;position:absolute;top:0;right:0}.sc-cart-remove:hover{color:red}.sc-cart-empty-msg{color:#999;margin:0;padding:10px;text-align:center}.sc-cart-item-qty{width:55px;border-radius:3px;font-size:12px;padding:4px 0 3px 6px;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.075) inset;box-shadow:0 1px 1px rgba(0,0,0,.075) inset;-webkit-transition:border-color .15s ease-in-out 0s,-webkit-box-shadow .15s ease-in-out 0s;transition:border-color .15s ease-in-out 0s,-webkit-box-shadow .15s ease-in-out 0s;transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s;transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s,-webkit-box-shadow .15s ease-in-out 0s}.sc-cart-item-summary{text-align:right;margin-top:5px;padding-top:5px}.sc-cart-summary{text-align:right;font-size:1.5em}.sc-cart-toolbar{margin-top:10px;text-align:right}.sc-cart-toolbar button{margin-left:5px}.sc-cart-toolbar button.disabled img{opacity:.5}.sc-cart-item img{margin-right:10px;width:60px}.sc-highlight{-webkit-animation:highlight 1s;animation:highlight 1s}@keyframes highlight{from{background:#faebcc}to{background:0 0}}@-webkit-keyframes highlight{from{background:#faebcc}to{background:0 0}}.sc-product-item{position:relative}.sc-product-item:after,.sc-product-item:before{-webkit-transition:all .2s ease-in-out 0s;transition:all .2s ease-in-out 0s}.sc-added-item{border-color:#5cb85c}.sc-added-item:after{content:"\2713 ";display:inline-block;position:absolute;top:0;right:4px;z-index:99;color:#fff;font-size:18px;font-weight:700;white-space:nowrap}.sc-added-item:before{content:"";display:inline-block;position:absolute;z-index:98;top:0;right:0;border-style:solid;border-width:0 40px 40px 0;-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);border-color:rgba(255,255,255,0) #5cb85c rgba(255,255,255,0) rgba(255,255,255,0)}.sc-button-checkout-paypal{border:0;cursor:pointer;padding:0;width:170px;height:32px} -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | jshint = require('gulp-jshint'), 3 | rename = require('gulp-rename'), 4 | uglify = require('gulp-uglify'), 5 | babel = require("gulp-babel"), 6 | postcss = require('gulp-postcss'), 7 | cleanCSS = require('gulp-clean-css'), 8 | cssbeautify = require('gulp-cssbeautify'), 9 | autoprefixer = require('autoprefixer'), 10 | karma = require('karma'), 11 | del = require('del'); 12 | 13 | // Source files 14 | var SRC_JS = 'src/js/*.js'; 15 | var SRC_CSS = 'src/css/*.css'; 16 | 17 | // Destination folders 18 | var DEST_JS = 'dist/js'; 19 | var DEST_CSS = 'dist/css'; 20 | 21 | // JS TASKS 22 | // Lint JS 23 | gulp.task('lint', function() { 24 | return gulp.src(SRC_JS) 25 | .pipe(jshint()) 26 | .pipe(jshint.reporter('default')) 27 | .pipe(jshint.reporter('fail')); 28 | }); 29 | 30 | // Build JS 31 | gulp.task('build:js', ['clean:js', 'lint'], function() { 32 | return gulp.src(SRC_JS) 33 | .pipe(babel()) 34 | .pipe(gulp.dest(DEST_JS)) 35 | .pipe(uglify({preserveComments:'license'})) 36 | .pipe(rename({suffix: '.min'})) 37 | .pipe(gulp.dest(DEST_JS)); 38 | }); 39 | 40 | // CSS TASKS 41 | gulp.task('build:css', ['clean:css'], function () { 42 | return gulp.src(SRC_CSS) 43 | .pipe(postcss( [autoprefixer({browsers: ['last 10 versions']})] )) 44 | .pipe(cssbeautify({ autosemicolon: true })) 45 | .pipe(gulp.dest(DEST_CSS)) 46 | .pipe(cleanCSS({compatibility: 'ie8'})) 47 | .pipe(rename({suffix: '.min'})) 48 | .pipe(gulp.dest(DEST_CSS)); 49 | }); 50 | 51 | // CLEAN files 52 | gulp.task('clean', function () { 53 | gulp.start( 'clean:js', 'clean:css'); 54 | }); 55 | 56 | gulp.task('clean:js', function () { 57 | return del([DEST_JS]); 58 | }); 59 | 60 | gulp.task('clean:css', function () { 61 | return del([DEST_CSS]); 62 | }); 63 | 64 | // WATCH for file changes and rerun the task 65 | gulp.task('watch', function() { 66 | gulp.watch('./src/js/*.js', ['build:js']); 67 | gulp.watch('./src/css/*.css', ['build:css']); 68 | }); 69 | 70 | // TEST 71 | gulp.task('test', function (done) { 72 | new karma.Server({ 73 | configFile: __dirname + '/karma.conf.js', 74 | singleRun: true 75 | }, function() { 76 | done(); 77 | }).start(); 78 | }); 79 | 80 | // DEFAULT task 81 | gulp.task('default', function() { 82 | gulp.start( 'build:js', 'build:css' ); 83 | }); -------------------------------------------------------------------------------- /src/css/smart_cart.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.x 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */ 12 | 13 | .sc-cart-item-list{ 14 | min-height: 50px; 15 | } 16 | 17 | .sc-cart-remove { 18 | background: transparent; 19 | border: none; 20 | font-size: 20px; 21 | position: absolute; 22 | top: 0; 23 | right: 0; 24 | } 25 | 26 | .sc-cart-remove:hover { 27 | color: red; 28 | } 29 | 30 | .sc-cart-empty-msg{ 31 | color: #999; 32 | margin: 0; 33 | padding: 10px; 34 | text-align: center; 35 | } 36 | 37 | .sc-cart-item-qty{ 38 | width: 55px; 39 | border-radius: 3px; 40 | font-size: 12px; 41 | padding: 4px 0 3px 6px; 42 | color: #555; 43 | background-color: #fff; 44 | background-image: none; 45 | border: 1px solid #ccc; 46 | box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; 47 | transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s; 48 | } 49 | 50 | .sc-cart-item-summary{ 51 | text-align: right; 52 | margin-top: 5px; 53 | padding-top: 5px; 54 | } 55 | 56 | .sc-cart-summary{ 57 | text-align: right; 58 | font-size: 1.5em; 59 | } 60 | 61 | .sc-cart-subtotal{ 62 | 63 | } 64 | 65 | .sc-cart-toolbar{ 66 | margin-top: 10px; 67 | text-align: right; 68 | } 69 | 70 | .sc-cart-toolbar button { 71 | margin-left: 5px; 72 | } 73 | 74 | .sc-cart-toolbar button.disabled img { 75 | opacity: .5; 76 | } 77 | 78 | .sc-cart-item img{ 79 | margin-right: 10px; 80 | width: 60px; 81 | } 82 | 83 | .sc-highlight { 84 | animation: highlight 1s; 85 | } 86 | 87 | @keyframes highlight { 88 | from { 89 | background: #faebcc 90 | } 91 | 92 | to { 93 | background: none; 94 | } 95 | } 96 | 97 | @-webkit-keyframes highlight { 98 | from { 99 | background: #faebcc 100 | } 101 | 102 | to { 103 | background: none; 104 | } 105 | } 106 | 107 | .sc-product-item { 108 | position: relative; 109 | } 110 | 111 | .sc-product-item:after, .sc-product-item:before { 112 | transition: all 0.2s ease-in-out 0s; 113 | } 114 | 115 | .sc-added-item { 116 | border-color: #5cb85c; 117 | } 118 | 119 | .sc-added-item:after { 120 | content: "\2713 "; 121 | display: inline-block; 122 | position: absolute; 123 | top: 0; 124 | right: 4px; 125 | z-index: 99; 126 | color:#fff; 127 | font-size:18px; 128 | font-weight:bold; 129 | white-space: nowrap; 130 | } 131 | 132 | .sc-added-item:before { 133 | content: ""; 134 | display: inline-block; 135 | position: absolute; 136 | z-index: 98; 137 | top: 0; 138 | right: 0; 139 | border-style: solid; 140 | border-width: 0 40px 40px 0; 141 | -webkit-transform: rotate(360deg); 142 | -moz-transform: rotate(360deg); 143 | -o-transform: rotate(360deg); 144 | transform: rotate(360deg); 145 | border-color: rgba(255,255,255,0) #5cb85c rgba(255,255,255,0) rgba(255,255,255,0); 146 | } 147 | 148 | .sc-button-checkout-default { 149 | 150 | } 151 | 152 | .sc-button-checkout-paypal { 153 | border: 0; 154 | cursor: pointer; 155 | padding: 0; 156 | width: 170px; 157 | height: 32px; 158 | } -------------------------------------------------------------------------------- /dist/css/smart_cart.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.x 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */ 12 | 13 | .sc-cart-item-list { 14 | min-height: 50px; 15 | } 16 | 17 | .sc-cart-remove { 18 | background: transparent; 19 | border: none; 20 | font-size: 20px; 21 | position: absolute; 22 | top: 0; 23 | right: 0; 24 | } 25 | 26 | .sc-cart-remove:hover { 27 | color: red; 28 | } 29 | 30 | .sc-cart-empty-msg { 31 | color: #999; 32 | margin: 0; 33 | padding: 10px; 34 | text-align: center; 35 | } 36 | 37 | .sc-cart-item-qty { 38 | width: 55px; 39 | border-radius: 3px; 40 | font-size: 12px; 41 | padding: 4px 0 3px 6px; 42 | color: #555; 43 | background-color: #fff; 44 | background-image: none; 45 | border: 1px solid #ccc; 46 | -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; 47 | box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; 48 | -webkit-transition: border-color 0.15s ease-in-out 0s, -webkit-box-shadow 0.15s ease-in-out 0s; 49 | transition: border-color 0.15s ease-in-out 0s, -webkit-box-shadow 0.15s ease-in-out 0s; 50 | transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s; 51 | transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s, -webkit-box-shadow 0.15s ease-in-out 0s; 52 | } 53 | 54 | .sc-cart-item-summary { 55 | text-align: right; 56 | margin-top: 5px; 57 | padding-top: 5px; 58 | } 59 | 60 | .sc-cart-summary { 61 | text-align: right; 62 | font-size: 1.5em; 63 | } 64 | 65 | .sc-cart-subtotal { 66 | } 67 | 68 | .sc-cart-toolbar { 69 | margin-top: 10px; 70 | text-align: right; 71 | } 72 | 73 | .sc-cart-toolbar button { 74 | margin-left: 5px; 75 | } 76 | 77 | .sc-cart-toolbar button.disabled img { 78 | opacity: .5; 79 | } 80 | 81 | .sc-cart-item img { 82 | margin-right: 10px; 83 | width: 60px; 84 | } 85 | 86 | .sc-highlight { 87 | -webkit-animation: highlight 1s; 88 | animation: highlight 1s; 89 | } 90 | 91 | @keyframes highlight { 92 | from { 93 | background: #faebcc; 94 | } 95 | 96 | to { 97 | background: none; 98 | } 99 | } 100 | 101 | @-webkit-keyframes highlight { 102 | from { 103 | background: #faebcc; 104 | } 105 | 106 | to { 107 | background: none; 108 | } 109 | } 110 | 111 | .sc-product-item { 112 | position: relative; 113 | } 114 | 115 | .sc-product-item:after, .sc-product-item:before { 116 | -webkit-transition: all 0.2s ease-in-out 0s; 117 | transition: all 0.2s ease-in-out 0s; 118 | } 119 | 120 | .sc-added-item { 121 | border-color: #5cb85c; 122 | } 123 | 124 | .sc-added-item:after { 125 | content: "\2713 "; 126 | display: inline-block; 127 | position: absolute; 128 | top: 0; 129 | right: 4px; 130 | z-index: 99; 131 | color: #fff; 132 | font-size: 18px; 133 | font-weight: bold; 134 | white-space: nowrap; 135 | } 136 | 137 | .sc-added-item:before { 138 | content: ""; 139 | display: inline-block; 140 | position: absolute; 141 | z-index: 98; 142 | top: 0; 143 | right: 0; 144 | border-style: solid; 145 | border-width: 0 40px 40px 0; 146 | -webkit-transform: rotate(360deg); 147 | -ms-transform: rotate(360deg); 148 | transform: rotate(360deg); 149 | border-color: rgba(255,255,255,0) #5cb85c rgba(255,255,255,0) rgba(255,255,255,0); 150 | } 151 | 152 | .sc-button-checkout-default { 153 | } 154 | 155 | .sc-button-checkout-paypal { 156 | border: 0; 157 | cursor: pointer; 158 | padding: 0; 159 | width: 170px; 160 | height: 32px; 161 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jQuery Smart Cart 3 2 | ### The smart interactive jQuery Shopping Cart plugin with PayPal payment support. 3 | 4 | [![Build Status](https://travis-ci.org/techlab/jquery-smartcart.svg?branch=master)](https://travis-ci.org/techlab/jquery-smartcart) 5 | [![npm version](https://badge.fury.io/js/jquery-smartcart.svg)](https://badge.fury.io/js/jquery-smartcart) 6 | [![Bower version](https://badge.fury.io/bo/jquery-smartcart.svg)](https://badge.fury.io/bo/jquery-smartcart) 7 | [![Latest Stable Version](https://poser.pugx.org/techlab/jquery-smartcart/v/stable)](https://packagist.org/packages/techlab/jquery-smartcart) 8 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/techlab/jquery-smartcart/blob/master/LICENSE) 9 | 10 | 11 | jQuery Smart Cart is the smart interactive **jQuery Shopping Cart plugin** with **PayPal** payment support. It can create an interactive and user friendly shopping cart with minimal code. It has built-in support for **Form** submit, **Ajax** submit and **PayPal** submit of the cart items. A lot of customization options and custom events makes it easy to implement your requirements. It can integrate with your existing shopping list very easily and you can use your own css or use the default **Bootstrap**. 12 | 13 | The new version **jQuery Smart Cart 3** is completely rewritten from scratch and adopted the modern patterns. It is more powerful, robust, scalable and customizable. A lot of features is added like Bootstrap support, theme support, customizable toolbars, customization options, public methods, event support and a lot more. 14 | See the list of [features](http://techlaboratory.net/smartcart#features), [demos](http://techlaboratory.net/smartcart#demo) and [documentation](http://techlaboratory.net/smartcart#documentation) for more details. 15 | 16 | + [Homepage](http://techlaboratory.net/smartcart) 17 | + [Documentation](http://techlaboratory.net/smartcart#documentation) 18 | + [Demos](http://techlaboratory.net/smartcart#demo) 19 | 20 | Demos 21 | ----- 22 | + [Basic Example](http://techlaboratory.net/projects/demo/jquery-smart-cart/v3/basic) 23 | + [PayPal Cart Example](http://techlaboratory.net/projects/demo/jquery-smart-cart/v3/paypal) 24 | 25 | Screenshots 26 | ----- 27 | ![Smart Cart Screenshot1](http://techlaboratory.net/assets/media/SmartCart3-Normal.png?v=2) 28 | ![Smart Cart Screenshot2](http://techlaboratory.net/assets/media/SmartCart3-PayPal.png?v=2) 29 | 30 | Requirements 31 | ----- 32 | + [Bootstrap 3+](http://getbootstrap.com/getting-started/#download) 33 | + [jQuery](http://jquery.com/) (supports jQuery 1.9+, jQuery 2+, jQuery 3+) 34 | 35 | Installation and usage 36 | ----- 37 | 38 | ### [NPM](https://www.npmjs.com/package/jquery-smartcart) 39 | npm install jquery-smartcart 40 | 41 | ### Bower 42 | bower install jquery-smartcart 43 | 44 | ### [Composer](https://packagist.org/packages/techlab/jquery-smartcart) 45 | composer require techlab/jquery-smartcart 46 | 47 | ### Download 48 | #### [Download from GitHub](https://github.com/techlab/jquery-smartcart/archive/master.zip) 49 | ### 50 | Please see the [documentation](http://techlaboratory.net/smartcart#documentation) for more deatils on implementation and usage. 51 | 52 | Features 53 | ----- 54 | + In-built PayPal, Ajax and form submit methods 55 | + Bootstrap support 56 | + Heavily customizable toolbar, option to add extra buttons 57 | + Theme support 58 | + Customizable css styles 59 | + Public methods for external function call 60 | + Enhanced event support 61 | + Compatible with latest jQuery versions (jQuery 1.9+, jQuery 2+, jQuery 3+) 62 | + Easy to implement, Minimal HTML required 63 | + Clean and compact design 64 | + Automatically calculates subtotal 65 | + Quantity is editable from the cart list 66 | + Product Image display 67 | + Customizable cart templates 68 | + Customizable currency formatting option 69 | + Pre-populate products on cart on load 70 | + and a lot more... 71 | 72 | Version 73 | ----- 74 | **SmartCart v3.0.1** 75 | 76 | License 77 | ---- 78 | [MIT License](https://github.com/techlab/jquery-smartcart/blob/master/LICENSE) 79 | -------------------------------------------------------------------------------- /test/test-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Smart Cart - jQuery Shopping Cart Plugin 5 | 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 | Products 16 |
17 |
18 |
19 | 20 |
21 |
22 | ... 23 |
24 |

Product 1

25 |

Product details

26 |
27 | 28 |
29 |
30 | 31 | 36 |
37 |
38 |
39 | 42 | 45 | 48 |
49 |
50 | 51 |
52 | $29,90.50 53 | 54 | 55 | 56 | 57 |
58 |
59 |
60 |
61 |
62 |
63 | 64 | ... 65 |
66 |

Product 2

67 |

Product details

68 | 69 |
70 |
71 |
72 | 73 | 78 |
79 |
80 |
81 | 84 | 87 | 90 |
91 |
92 | 95 |
96 | $54,35.50 97 | 98 | 99 | 100 | 101 |
102 |
103 |
104 |
105 |
106 | 107 |
108 | 109 | ... 110 |

Product Tittle

111 | 112 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

113 |
114 |
115 |
116 |

$29,90

117 |
118 |
119 | 120 |
121 | 122 |
123 |
124 |
125 | 126 |
127 |
128 |
129 |
130 | 131 | 144 |
145 |
146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /dist/js/jquery.smartCart.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.0.1 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */ 12 | !function(t,e,a,i){"use strict";function s(e,a){this.options=t.extend(!0,{},r,a),this.cart=[],this.cart_element=t(e),this.init()}var r={cart:[],resultName:"cart_list",theme:"default",combineProducts:!0,highlightEffect:!0,cartItemTemplate:'

{product_name}

{product_desc}

',cartItemQtyTemplate:"{display_price} × {display_quantity} = {display_amount}",productContainerSelector:".sc-product-item",productElementSelector:"*",addCartSelector:".sc-add-to-cart",paramSettings:{productPrice:"product_price",productQuantity:"product_quantity",productName:"product_name",productId:"product_id"},lang:{cartTitle:"Shopping Cart",checkout:"Checkout",clear:"Clear",subtotal:"Subtotal:",cartRemove:"×",cartEmpty:"Cart is Empty!
Choose your products"},submitSettings:{submitType:"form",ajaxURL:"",ajaxSettings:{}},currencySettings:{locales:"en-US",currencyOptions:{style:"currency",currency:"USD",currencyDisplay:"symbol"}},toolbarSettings:{showToolbar:!0,showCheckoutButton:!0,showClearButton:!0,showCartSummary:!0,checkoutButtonStyle:"default",checkoutButtonImage:"",toolbarExtraButtons:[]},debug:!1};t.extend(s.prototype,{init:function(){this._setElements(),this._setToolbar(),this._setEvents();var e=this;t(this.options.cart).each(function(t,a){a=e._addToCart(a)}),this._hasCartChange()},_setElements:function(){var e=t('');this.cart_element.append(e),this.cart_element.addClass("panel panel-default sc-cart sc-theme-"+this.options.theme),this.cart_element.append('
'+this.options.lang.cartTitle+' 0
'),this.cart_element.append('
')},_setToolbar:function(){if(this.options.toolbarSettings.showToolbar!==!0)return!1;var e=t("
").addClass("panel-footer sc-toolbar"),a=t('
'),i=t('
');if(this.options.toolbarSettings.showCheckoutButton){var s="";switch(this.options.toolbarSettings.checkoutButtonStyle){case"paypal":s='';break;case"image":s='';break;default:s=' "}a.append(s)}if(this.options.toolbarSettings.showClearButton){var r=t('"),s.attr("data-unique-key",e.unique_key),s.append(this._formatTemplate(this.options.cartItemTemplate,e));var r='
'+this._getMoneyFormatted(e[this.options.paramSettings.productPrice])+"";r+=' × ',r+=' = '+this._getMoneyFormatted(a)+"
",s.append(r),i.append(s)}this.options.highlightEffect===!0&&(s.addClass("sc-highlight"),setTimeout(function(){s.removeClass("sc-highlight")},500)),this._hasCartChange()},_hasCartChange:function(){t(".sc-cart-count",this.cart_element).text(this.cart.length),t(".sc-cart-subtotal",this.element).text(this._getCartSubtotal()),0===this.cart.length?(t(".sc-cart-item-list",this.cart_element).empty().append(t('
'+this.options.lang.cartEmpty+"
")),t(this.options.productContainerSelector).removeClass("sc-added-item"),t(".sc-cart-checkout, .sc-cart-clear").addClass("disabled"),this._triggerEvent("cartEmpty")):(t(".sc-cart-item-list > .sc-cart-empty-msg",this.cart_element).remove(),t(".sc-cart-checkout, .sc-cart-clear").removeClass("disabled")),t("#"+this.options.resultName,this.cart_element).val(JSON.stringify(this.cart))},_getCartSubtotal:function(){var e=this,a=0;return t.each(this.cart,function(t,i){e._getValidateNumber(i[e.options.paramSettings.productPrice])&&(a+=(i[e.options.paramSettings.productPrice]-0)*(i[e.options.paramSettings.productQuantity]-0))}),this._getMoneyFormatted(a)},_submitCart:function(){var e=this,a=this.cart_element.parents("form");if(!a)return this._logError("Form not found to submit"),!1;switch(this.options.submitSettings.submitType){case"ajax":var i=this.options.submitSettings.ajaxURL&&this.options.submitSettings.ajaxURL.length>0?this.options.submitSettings.ajaxURL:a.attr("action"),s=t.extend(!0,{},{url:i,type:"POST",data:a.serialize(),beforeSend:function(){e.cart_element.addClass("loading")},error:function(t,a,i){e.cart_element.removeClass("loading"),e._logError(i)},success:function(t){e.cart_element.removeClass("loading"),e._triggerEvent("cartSubmitted",[e.cart]),e._clearCart()}},this.options.submitSettings.ajaxSettings);t.ajax(s);break;case"paypal":a.children(".sc-paypal-input").remove(),t.each(this.cart,function(t,i){var s=t+1;a.append('').append('').append('').append('')}),a.submit(),this._triggerEvent("cartSubmitted",[this.cart]);break;default:a.submit(),this._triggerEvent("cartSubmitted",[this.cart])}return!0},_getContent:function(t){return t.is(":checkbox, :radio")?t.is(":checked")?t.val():"":t.is("[value], select")?t.val():t.is("img")?t.attr("src"):t.text()},_isObjectsEqual:function(t,e){if(Object.getOwnPropertyNames(t).length!==Object.getOwnPropertyNames(e).length)return!1;for(var a in t)if("unique_key"!==a&&a!==this.options.paramSettings.productQuantity&&(void 0!==t[a]||void 0!==e[a])&&t[a]!==e[a])return!1;return!0},_getMoneyFormatted:function(t){return t-=0,Number(t.toFixed(2)).toLocaleString(this.options.currencySettings.locales,this.options.currencySettings.currencyOptions)},_getValueOrEmpty:function(t){return t&&void 0!==t?t:""},_getValidateNumber:function(t){return!!((t-=0)&&t>0)},_formatTemplate:function(t,e){for(var a=t.split("{"),i="",s=0;s0?a[s].replace(r+"}",this._getValueOrEmpty(e[r])):a[s]}return i},_triggerEvent:function(e,a){var i=t.Event(e);return this.cart_element.trigger(i,a),!i.isDefaultPrevented()&&i.result},_getUniqueKey:function(){return(new Date).getTime()},_logMessage:function(t){if(this.options.debug!==!0)return!1;console.log(t)},_logError:function(e){if(this.options.debug!==!0)return!1;t.error(e)},submit:function(){this._submitCart()},clear:function(){this._clearCart()}}),t.fn.smartCart=function(e){var a,i=arguments;return void 0===e||"object"==typeof e?this.each(function(){t.data(this,"smartCart")||t.data(this,"smartCart",new s(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?(a=t.data(this[0],"smartCart"),"destroy"===e&&t.data(this,"smartCart",null),a instanceof s&&"function"==typeof a[e]?a[e].apply(a,Array.prototype.slice.call(i,1)):this):void 0}}(jQuery,window,document); -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery Smart Cart - The smart interactive jQuery Shopping Cart plugin with PayPal payment support 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |
18 |
19 |
20 |
21 | Products 22 |
23 |
24 |
25 | 26 |
27 |
28 | ... 29 |
30 |

Product 1

31 |

Product details

32 |
33 | 34 |
35 |
36 | 37 | 42 |
43 |
44 |
45 | 48 | 51 | 54 |
55 |
56 | 57 |
58 | $2,990.50 59 | 60 | 61 | 62 | 63 |
64 |
65 |
66 |
67 |
68 |
69 | 70 | ... 71 |
72 |

Product 2

73 |

Product details

74 | 75 |
76 |
77 |
78 | 79 | 84 |
85 |
86 |
87 | 90 | 93 | 96 |
97 |
98 | 101 |
102 | $5,435.50 103 | 104 | 105 | 106 | 107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | ... 115 |
116 |

Product 3

117 |

Product details

118 | 119 |
120 | 121 |
122 |
123 | 124 | 129 |
130 |
131 |
132 | 135 | 138 | 141 |
142 |
143 | 146 |
147 | $5,435.50 148 | 149 | 150 | 151 | 152 |
153 |
154 |
155 |
156 |
157 | 158 |
159 | 160 | ... 161 |
162 |

Product 4

163 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

164 | 165 |
166 |
167 |
168 | 169 | 174 |
175 |
176 |
177 | 180 | 183 | 186 |
187 |
188 | 191 |
192 | $435.50 193 | 194 | 195 | 196 | 197 |
198 |
199 |
200 |
201 |
202 | 203 |
204 | 205 | ... 206 |
207 |

Product 5

208 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

209 | 210 |
211 |
212 |
213 | 214 | 219 |
220 |
221 |
222 | 225 | 228 | 231 |
232 |
233 | 236 |
237 | $3,410.00 238 | 239 | 240 | 241 | 242 |
243 |
244 |
245 |
246 |
247 | 248 |
249 | 250 | ... 251 |
252 |

Product 6

253 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

254 | 255 |
256 |
257 |
258 | 259 | 264 |
265 |
266 |
267 | 270 | 273 | 276 |
277 |
278 | 281 |
282 | $5,435.50 283 | 284 | 285 | 286 | 287 |
288 |
289 |
290 |
291 |
292 | 293 |
294 |
295 |
296 | 297 |
298 | 299 | 308 |
309 |
310 | 311 | 312 | 313 | 314 | 315 | 316 | 322 | 323 | -------------------------------------------------------------------------------- /examples/paypal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery Smart Cart - The smart interactive jQuery Shopping Cart plugin with PayPal payment support 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |
18 |
19 |
20 |
21 | Products 22 |
23 |
24 |
25 | 26 |
27 |
28 | ... 29 |
30 |

Product 1

31 |

Product details

32 |
33 | 34 |
35 |
36 | 37 | 42 |
43 |
44 |
45 | 48 | 51 | 54 |
55 |
56 | 57 |
58 | $2,990.50 59 | 60 | 61 | 62 | 63 |
64 |
65 |
66 |
67 |
68 |
69 | 70 | ... 71 |
72 |

Product 2

73 |

Product details

74 | 75 |
76 |
77 |
78 | 79 | 84 |
85 |
86 |
87 | 90 | 93 | 96 |
97 |
98 | 101 |
102 | $5,435.50 103 | 104 | 105 | 106 | 107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | ... 115 |
116 |

Product 3

117 |

Product details

118 | 119 |
120 | 121 |
122 |
123 | 124 | 129 |
130 |
131 |
132 | 135 | 138 | 141 |
142 |
143 | 146 |
147 | $5,435.50 148 | 149 | 150 | 151 | 152 |
153 |
154 |
155 |
156 |
157 | 158 |
159 | 160 | ... 161 |
162 |

Product 4

163 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

164 | 165 |
166 |
167 |
168 | 169 | 174 |
175 |
176 |
177 | 180 | 183 | 186 |
187 |
188 | 191 |
192 | $435.50 193 | 194 | 195 | 196 | 197 |
198 |
199 |
200 |
201 |
202 | 203 |
204 | 205 | ... 206 |
207 |

Product 5

208 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

209 | 210 |
211 |
212 |
213 | 214 | 219 |
220 |
221 |
222 | 225 | 228 | 231 |
232 |
233 | 236 |
237 | $3,410.00 238 | 239 | 240 | 241 | 242 |
243 |
244 |
245 |
246 |
247 | 248 |
249 | 250 | ... 251 |
252 |

Product 6

253 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

254 | 255 |
256 |
257 |
258 | 259 | 264 |
265 |
266 |
267 | 270 | 273 | 276 |
277 |
278 | 281 |
282 | $5,435.50 283 | 284 | 285 | 286 | 287 |
288 |
289 |
290 |
291 |
292 | 293 |
294 |
295 |
296 | 297 |
298 | 299 | 318 | 319 |
320 |
321 | 322 | 323 | 324 | 325 | 326 | 327 | 340 | 341 | 342 | -------------------------------------------------------------------------------- /dist/js/jquery.smartCart.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.0.1 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */ 12 | 13 | ;(function ($, window, document, undefined) { 14 | "use strict"; 15 | // Default options 16 | 17 | var defaults = { 18 | cart: [], // initial products on cart 19 | resultName: 'cart_list', // Submit name of the cart parameter 20 | theme: 'default', // theme for the cart, related css need to include for other than default theme 21 | combineProducts: true, // combine similar products on cart 22 | highlightEffect: true, // highlight effect on adding/updating product in cart 23 | cartItemTemplate: '

{product_name}

{product_desc}

', 24 | cartItemQtyTemplate: '{display_price} × {display_quantity} = {display_amount}', 25 | productContainerSelector: '.sc-product-item', 26 | productElementSelector: '*', // input, textarea, select, div, p 27 | addCartSelector: '.sc-add-to-cart', 28 | paramSettings: { // Map the paramters 29 | productPrice: 'product_price', 30 | productQuantity: 'product_quantity', 31 | productName: 'product_name', 32 | productId: 'product_id' 33 | }, 34 | lang: { // Language variables 35 | cartTitle: "Shopping Cart", 36 | checkout: 'Checkout', 37 | clear: 'Clear', 38 | subtotal: 'Subtotal:', 39 | cartRemove: '×', 40 | cartEmpty: 'Cart is Empty!
Choose your products' 41 | }, 42 | submitSettings: { 43 | submitType: 'form', // form, paypal, ajax 44 | ajaxURL: '', // Ajax submit URL 45 | ajaxSettings: {} // Ajax extra settings for submit call 46 | }, 47 | currencySettings: { 48 | locales: 'en-US', // A string with a BCP 47 language tag, or an array of such strings 49 | currencyOptions: { 50 | style: 'currency', 51 | currency: 'USD', 52 | currencyDisplay: 'symbol' 53 | } // extra settings for the currency formatter. Refer: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString 54 | }, 55 | toolbarSettings: { 56 | showToolbar: true, 57 | showCheckoutButton: true, 58 | showClearButton: true, 59 | showCartSummary: true, 60 | checkoutButtonStyle: 'default', // default, paypal, image 61 | checkoutButtonImage: '', // image for the checkout button 62 | toolbarExtraButtons: [] // Extra buttons to show on toolbar, array of jQuery input/buttons elements 63 | }, 64 | debug: false 65 | }; 66 | 67 | // The plugin constructor 68 | function SmartCart(element, options) { 69 | // Merge user settings with default, recursively 70 | this.options = $.extend(true, {}, defaults, options); 71 | // Cart array 72 | this.cart = []; 73 | // Cart element 74 | this.cart_element = $(element); 75 | // Call initial method 76 | this.init(); 77 | } 78 | 79 | $.extend(SmartCart.prototype, { 80 | 81 | init: function () { 82 | // Set the elements 83 | this._setElements(); 84 | 85 | // Add toolbar 86 | this._setToolbar(); 87 | 88 | // Assign plugin events 89 | this._setEvents(); 90 | 91 | // Set initial products 92 | var mi = this; 93 | $(this.options.cart).each(function (i, p) { 94 | p = mi._addToCart(p); 95 | }); 96 | 97 | // Call UI sync 98 | this._hasCartChange(); 99 | }, 100 | 101 | // PRIVATE FUNCTIONS 102 | /* 103 | * Set basic elements for the cart 104 | */ 105 | _setElements: function () { 106 | // The element store all cart data and submit with form 107 | var cartListElement = $(''); 108 | this.cart_element.append(cartListElement); 109 | // Set the cart main element 110 | this.cart_element.addClass('panel panel-default sc-cart sc-theme-' + this.options.theme); 111 | this.cart_element.append('
' + this.options.lang.cartTitle + ' 0
'); 112 | this.cart_element.append('
'); 113 | }, 114 | /* 115 | * Set the toolbar for the cart 116 | */ 117 | _setToolbar: function () { 118 | if (this.options.toolbarSettings.showToolbar !== true) { 119 | return false; 120 | } 121 | 122 | var toolbar = $('
').addClass('panel-footer sc-toolbar'); 123 | var toolbarButtonPanel = $('
'); 124 | var toolbarSummaryPanel = $('
'); 125 | 126 | // Checkout Button 127 | if (this.options.toolbarSettings.showCheckoutButton) { 128 | var btnCheckout = ''; 129 | switch (this.options.toolbarSettings.checkoutButtonStyle) { 130 | case 'paypal': 131 | btnCheckout = ''; 132 | break; 133 | case 'image': 134 | btnCheckout = ''; 135 | break; 136 | default: 137 | btnCheckout = ' '; 138 | break; 139 | } 140 | toolbarButtonPanel.append(btnCheckout); 141 | } 142 | 143 | // Clear Button 144 | if (this.options.toolbarSettings.showClearButton) { 145 | var btnClear = $(''); 336 | elmMain.attr('data-unique-key', p.unique_key); 337 | 338 | elmMain.append(this._formatTemplate(this.options.cartItemTemplate, p)); 339 | 340 | var itemSummary = '
' + this._getMoneyFormatted(p[this.options.paramSettings.productPrice]) + ''; 341 | itemSummary += ' × '; 342 | itemSummary += ' = ' + this._getMoneyFormatted(productAmount) + '
'; 343 | 344 | elmMain.append(itemSummary); 345 | cartList.append(elmMain); 346 | } 347 | 348 | // Apply the highlight effect 349 | if (this.options.highlightEffect === true) { 350 | elmMain.addClass('sc-highlight'); 351 | setTimeout(function () { 352 | elmMain.removeClass('sc-highlight'); 353 | }, 500); 354 | } 355 | 356 | this._hasCartChange(); 357 | }, 358 | /* 359 | * Handles the changes in the cart 360 | */ 361 | _hasCartChange: function () { 362 | $('.sc-cart-count', this.cart_element).text(this.cart.length); 363 | $('.sc-cart-subtotal', this.element).text(this._getCartSubtotal()); 364 | 365 | if (this.cart.length === 0) { 366 | $('.sc-cart-item-list', this.cart_element).empty().append($('
' + this.options.lang.cartEmpty + '
')); 367 | $(this.options.productContainerSelector).removeClass('sc-added-item'); 368 | $('.sc-cart-checkout, .sc-cart-clear').addClass('disabled'); 369 | 370 | // Trigger "cartEmpty" event 371 | this._triggerEvent("cartEmpty"); 372 | } else { 373 | $('.sc-cart-item-list > .sc-cart-empty-msg', this.cart_element).remove(); 374 | $('.sc-cart-checkout, .sc-cart-clear').removeClass('disabled'); 375 | } 376 | 377 | // Update cart value to the cart hidden element 378 | $('#' + this.options.resultName, this.cart_element).val(JSON.stringify(this.cart)); 379 | }, 380 | /* 381 | * Calculates the cart subtotal 382 | */ 383 | _getCartSubtotal: function () { 384 | var mi = this; 385 | var subtotal = 0; 386 | $.each(this.cart, function (i, p) { 387 | if (mi._getValidateNumber(p[mi.options.paramSettings.productPrice])) { 388 | subtotal += (p[mi.options.paramSettings.productPrice] - 0) * (p[mi.options.paramSettings.productQuantity] - 0); 389 | } 390 | }); 391 | return this._getMoneyFormatted(subtotal); 392 | }, 393 | /* 394 | * Cart submit functionalities 395 | */ 396 | _submitCart: function () { 397 | var mi = this; 398 | var formElm = this.cart_element.parents('form'); 399 | if (!formElm) { 400 | this._logError('Form not found to submit'); 401 | return false; 402 | } 403 | 404 | switch (this.options.submitSettings.submitType) { 405 | case 'ajax': 406 | var ajaxURL = this.options.submitSettings.ajaxURL && this.options.submitSettings.ajaxURL.length > 0 ? this.options.submitSettings.ajaxURL : formElm.attr('action'); 407 | 408 | var ajaxSettings = $.extend(true, {}, { 409 | url: ajaxURL, 410 | type: "POST", 411 | data: formElm.serialize(), 412 | beforeSend: function () { 413 | mi.cart_element.addClass('loading'); 414 | }, 415 | error: function (jqXHR, status, message) { 416 | mi.cart_element.removeClass('loading'); 417 | mi._logError(message); 418 | }, 419 | success: function (res) { 420 | mi.cart_element.removeClass('loading'); 421 | mi._triggerEvent("cartSubmitted", [mi.cart]); 422 | mi._clearCart(); 423 | } 424 | }, this.options.submitSettings.ajaxSettings); 425 | 426 | $.ajax(ajaxSettings); 427 | 428 | break; 429 | case 'paypal': 430 | formElm.children('.sc-paypal-input').remove(); 431 | // Add paypal specific fields for cart products 432 | $.each(this.cart, function (i, p) { 433 | var itemNumber = i + 1; 434 | formElm.append('').append('').append('').append(''); 435 | }); 436 | 437 | formElm.submit(); 438 | this._triggerEvent("cartSubmitted", [this.cart]); 439 | 440 | break; 441 | default: 442 | formElm.submit(); 443 | this._triggerEvent("cartSubmitted", [this.cart]); 444 | 445 | break; 446 | } 447 | 448 | return true; 449 | }, 450 | 451 | // HELPER FUNCTIONS 452 | /* 453 | * Get the content of an HTML element irrespective of its type 454 | */ 455 | _getContent: function (elm) { 456 | if (elm.is(":checkbox, :radio")) { 457 | return elm.is(":checked") ? elm.val() : ''; 458 | } else if (elm.is("[value], select")) { 459 | return elm.val(); 460 | } else if (elm.is("img")) { 461 | return elm.attr('src'); 462 | } else { 463 | return elm.text(); 464 | } 465 | return ''; 466 | }, 467 | /* 468 | * Compare equality of two product objects 469 | */ 470 | _isObjectsEqual: function (o1, o2) { 471 | if (Object.getOwnPropertyNames(o1).length !== Object.getOwnPropertyNames(o2).length) { 472 | return false; 473 | } 474 | for (var p in o1) { 475 | if (p === 'unique_key' || p === this.options.paramSettings.productQuantity) { 476 | continue; 477 | } 478 | if (typeof o1[p] === typeof undefined && typeof o2[p] === typeof undefined) { 479 | continue; 480 | } 481 | if (o1[p] !== o2[p]) { 482 | return false; 483 | } 484 | } 485 | return true; 486 | }, 487 | /* 488 | * Format money 489 | */ 490 | _getMoneyFormatted: function (n) { 491 | n = n - 0; 492 | return Number(n.toFixed(2)).toLocaleString(this.options.currencySettings.locales, this.options.currencySettings.currencyOptions); 493 | }, 494 | /* 495 | * Get the value of an element and empty value if the element not exists 496 | */ 497 | _getValueOrEmpty: function (v) { 498 | return v && typeof v !== typeof undefined ? v : ''; 499 | }, 500 | /* 501 | * Validate Number 502 | */ 503 | _getValidateNumber: function (n) { 504 | n = n - 0; 505 | if (n && n > 0) { 506 | return true; 507 | } 508 | return false; 509 | }, 510 | /* 511 | * Small templating function 512 | */ 513 | _formatTemplate: function (t, o) { 514 | var r = t.split("{"), 515 | fs = ''; 516 | for (var i = 0; i < r.length; i++) { 517 | var vr = r[i].substring(0, r[i].indexOf("}")); 518 | if (vr.length > 0) { 519 | fs += r[i].replace(vr + '}', this._getValueOrEmpty(o[vr])); 520 | } else { 521 | fs += r[i]; 522 | } 523 | } 524 | return fs; 525 | }, 526 | /* 527 | * Event raiser 528 | */ 529 | _triggerEvent: function (name, params) { 530 | // Trigger an event 531 | var e = $.Event(name); 532 | this.cart_element.trigger(e, params); 533 | if (e.isDefaultPrevented()) { 534 | return false; 535 | } 536 | return e.result; 537 | }, 538 | /* 539 | * Get unique key 540 | */ 541 | _getUniqueKey: function () { 542 | var d = new Date(); 543 | return d.getTime(); 544 | }, 545 | /* 546 | * Log message to console 547 | */ 548 | _logMessage: function (msg) { 549 | if (this.options.debug !== true) { 550 | return false; 551 | } 552 | // Log message 553 | console.log(msg); 554 | }, 555 | /* 556 | * Log error to console and terminate execution 557 | */ 558 | _logError: function (msg) { 559 | if (this.options.debug !== true) { 560 | return false; 561 | } 562 | // Log error 563 | $.error(msg); 564 | }, 565 | 566 | // PUBLIC FUNCTIONS 567 | /* 568 | * Public function to sumbit the cart 569 | */ 570 | submit: function () { 571 | this._submitCart(); 572 | }, 573 | /* 574 | * Public function to clear the cart 575 | */ 576 | clear: function () { 577 | this._clearCart(); 578 | } 579 | }); 580 | 581 | // Wrapper for the plugin 582 | $.fn.smartCart = function (options) { 583 | var args = arguments; 584 | var instance; 585 | 586 | if (options === undefined || typeof options === 'object') { 587 | return this.each(function () { 588 | if (!$.data(this, "smartCart")) { 589 | $.data(this, "smartCart", new SmartCart(this, options)); 590 | } 591 | }); 592 | } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { 593 | instance = $.data(this[0], 'smartCart'); 594 | 595 | if (options === 'destroy') { 596 | $.data(this, 'smartCart', null); 597 | } 598 | 599 | if (instance instanceof SmartCart && typeof instance[options] === 'function') { 600 | return instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 601 | } else { 602 | return this; 603 | } 604 | } 605 | }; 606 | })(jQuery, window, document); -------------------------------------------------------------------------------- /src/js/jquery.smartCart.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery Smart Cart v3.0.1 3 | * The smart interactive jQuery Shopping Cart plugin with PayPal payment support 4 | * http://www.techlaboratory.net/smartcart 5 | * 6 | * Created by Dipu Raj 7 | * http://dipuraj.me 8 | * 9 | * Licensed under the terms of the MIT License 10 | * https://github.com/techlab/SmartCart/blob/master/LICENSE 11 | */ 12 | 13 | ;(function ($, window, document, undefined) { 14 | "use strict"; 15 | // Default options 16 | var defaults = { 17 | cart: [], // initial products on cart 18 | resultName: 'cart_list', // Submit name of the cart parameter 19 | theme: 'default', // theme for the cart, related css need to include for other than default theme 20 | combineProducts: true, // combine similar products on cart 21 | highlightEffect: true, // highlight effect on adding/updating product in cart 22 | cartItemTemplate: '

{product_name}

{product_desc}

', 23 | cartItemQtyTemplate: '{display_price} × {display_quantity} = {display_amount}', 24 | productContainerSelector: '.sc-product-item', 25 | productElementSelector: '*', // input, textarea, select, div, p 26 | addCartSelector: '.sc-add-to-cart', 27 | paramSettings : { // Map the paramters 28 | productPrice: 'product_price', 29 | productQuantity: 'product_quantity', 30 | productName: 'product_name', 31 | productId: 'product_id', 32 | }, 33 | lang: { // Language variables 34 | cartTitle: "Shopping Cart", 35 | checkout: 'Checkout', 36 | clear: 'Clear', 37 | subtotal: 'Subtotal:', 38 | cartRemove:'×', 39 | cartEmpty: 'Cart is Empty!
Choose your products' 40 | }, 41 | submitSettings: { 42 | submitType: 'form', // form, paypal, ajax 43 | ajaxURL: '', // Ajax submit URL 44 | ajaxSettings: {} // Ajax extra settings for submit call 45 | }, 46 | currencySettings: { 47 | locales: 'en-US', // A string with a BCP 47 language tag, or an array of such strings 48 | currencyOptions: { 49 | style: 'currency', 50 | currency: 'USD', 51 | currencyDisplay: 'symbol' 52 | } // extra settings for the currency formatter. Refer: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString 53 | }, 54 | toolbarSettings: { 55 | showToolbar: true, 56 | showCheckoutButton: true, 57 | showClearButton: true, 58 | showCartSummary:true, 59 | checkoutButtonStyle: 'default', // default, paypal, image 60 | checkoutButtonImage: '', // image for the checkout button 61 | toolbarExtraButtons: [] // Extra buttons to show on toolbar, array of jQuery input/buttons elements 62 | }, 63 | debug: false 64 | }; 65 | 66 | // The plugin constructor 67 | function SmartCart(element, options) { 68 | // Merge user settings with default, recursively 69 | this.options = $.extend(true, {}, defaults, options); 70 | // Cart array 71 | this.cart = []; 72 | // Cart element 73 | this.cart_element = $(element); 74 | // Call initial method 75 | this.init(); 76 | } 77 | 78 | $.extend(SmartCart.prototype, { 79 | 80 | init: function () { 81 | // Set the elements 82 | this._setElements(); 83 | 84 | // Add toolbar 85 | this._setToolbar(); 86 | 87 | // Assign plugin events 88 | this._setEvents(); 89 | 90 | // Set initial products 91 | var mi = this; 92 | $(this.options.cart).each(function(i, p) { 93 | p = mi._addToCart(p); 94 | }); 95 | 96 | // Call UI sync 97 | this._hasCartChange(); 98 | }, 99 | 100 | // PRIVATE FUNCTIONS 101 | /* 102 | * Set basic elements for the cart 103 | */ 104 | _setElements: function () { 105 | // The element store all cart data and submit with form 106 | var cartListElement = $(''); 107 | this.cart_element.append(cartListElement); 108 | // Set the cart main element 109 | this.cart_element.addClass('panel panel-default sc-cart sc-theme-' + this.options.theme); 110 | this.cart_element.append('
' + this.options.lang.cartTitle + ' 0
'); 111 | this.cart_element.append('
'); 112 | }, 113 | /* 114 | * Set the toolbar for the cart 115 | */ 116 | _setToolbar: function () { 117 | if(this.options.toolbarSettings.showToolbar !== true) { return false; } 118 | 119 | var toolbar = $('
').addClass('panel-footer sc-toolbar'); 120 | var toolbarButtonPanel = $('
'); 121 | var toolbarSummaryPanel = $('
'); 122 | 123 | // Checkout Button 124 | if(this.options.toolbarSettings.showCheckoutButton){ 125 | var btnCheckout = ''; 126 | switch(this.options.toolbarSettings.checkoutButtonStyle){ 127 | case 'paypal': 128 | btnCheckout = ''; 129 | break; 130 | case 'image': 131 | btnCheckout = ''; 132 | break; 133 | default: 134 | btnCheckout = ' '; 135 | break; 136 | } 137 | toolbarButtonPanel.append(btnCheckout); 138 | } 139 | 140 | // Clear Button 141 | if(this.options.toolbarSettings.showClearButton){ 142 | var btnClear = $(''); 331 | elmMain.attr('data-unique-key', p.unique_key); 332 | 333 | elmMain.append(this._formatTemplate(this.options.cartItemTemplate, p)); 334 | 335 | var itemSummary = '
' + this._getMoneyFormatted(p[this.options.paramSettings.productPrice]) + ''; 336 | itemSummary += ' × '; 337 | itemSummary += ' = ' + this._getMoneyFormatted(productAmount) + '
'; 338 | 339 | elmMain.append(itemSummary); 340 | cartList.append(elmMain); 341 | } 342 | 343 | // Apply the highlight effect 344 | if(this.options.highlightEffect === true){ 345 | elmMain.addClass('sc-highlight'); 346 | setTimeout(function() { 347 | elmMain.removeClass('sc-highlight'); 348 | },500); 349 | } 350 | 351 | this._hasCartChange(); 352 | }, 353 | /* 354 | * Handles the changes in the cart 355 | */ 356 | _hasCartChange: function () { 357 | $('.sc-cart-count',this.cart_element).text(this.cart.length); 358 | $('.sc-cart-subtotal',this.element).text(this._getCartSubtotal()); 359 | 360 | if(this.cart.length === 0){ 361 | $('.sc-cart-item-list',this.cart_element).empty().append($('
' + this.options.lang.cartEmpty + '
')); 362 | $(this.options.productContainerSelector).removeClass('sc-added-item'); 363 | $('.sc-cart-checkout, .sc-cart-clear').addClass('disabled'); 364 | 365 | // Trigger "cartEmpty" event 366 | this._triggerEvent("cartEmpty"); 367 | }else{ 368 | $('.sc-cart-item-list > .sc-cart-empty-msg',this.cart_element).remove(); 369 | $('.sc-cart-checkout, .sc-cart-clear').removeClass('disabled'); 370 | } 371 | 372 | // Update cart value to the cart hidden element 373 | $('#' + this.options.resultName, this.cart_element).val(JSON.stringify(this.cart)); 374 | }, 375 | /* 376 | * Calculates the cart subtotal 377 | */ 378 | _getCartSubtotal: function () { 379 | var mi = this; 380 | var subtotal = 0; 381 | $.each(this.cart, function( i, p ) { 382 | if(mi._getValidateNumber(p[mi.options.paramSettings.productPrice])){ 383 | subtotal += (p[mi.options.paramSettings.productPrice] - 0) * (p[mi.options.paramSettings.productQuantity] - 0); 384 | } 385 | }); 386 | return this._getMoneyFormatted(subtotal); 387 | }, 388 | /* 389 | * Cart submit functionalities 390 | */ 391 | _submitCart: function () { 392 | var mi = this; 393 | var formElm = this.cart_element.parents('form'); 394 | if(!formElm){ 395 | this._logError( 'Form not found to submit' ); 396 | return false; 397 | } 398 | 399 | switch(this.options.submitSettings.submitType){ 400 | case 'ajax': 401 | var ajaxURL = (this.options.submitSettings.ajaxURL && this.options.submitSettings.ajaxURL.length > 0) ? this.options.submitSettings.ajaxURL : formElm.attr( 'action' ); 402 | 403 | var ajaxSettings = $.extend(true, {}, { 404 | url: ajaxURL, 405 | type: "POST", 406 | data: formElm.serialize(), 407 | beforeSend: function(){ 408 | mi.cart_element.addClass('loading'); 409 | }, 410 | error: function(jqXHR, status, message){ 411 | mi.cart_element.removeClass('loading'); 412 | mi._logError(message); 413 | }, 414 | success: function(res){ 415 | mi.cart_element.removeClass('loading'); 416 | mi._triggerEvent("cartSubmitted", [mi.cart]); 417 | mi._clearCart(); 418 | } 419 | }, this.options.submitSettings.ajaxSettings); 420 | 421 | $.ajax(ajaxSettings); 422 | 423 | break; 424 | case 'paypal': 425 | formElm.children('.sc-paypal-input').remove(); 426 | // Add paypal specific fields for cart products 427 | $.each(this.cart, function( i, p ) { 428 | var itemNumber = i + 1; 429 | formElm.append('') 430 | .append('') 431 | .append('') 432 | .append(''); 433 | }); 434 | 435 | formElm.submit(); 436 | this._triggerEvent("cartSubmitted", [this.cart]); 437 | 438 | break; 439 | default: 440 | formElm.submit(); 441 | this._triggerEvent("cartSubmitted", [this.cart]); 442 | 443 | break; 444 | } 445 | 446 | return true; 447 | }, 448 | 449 | // HELPER FUNCTIONS 450 | /* 451 | * Get the content of an HTML element irrespective of its type 452 | */ 453 | _getContent: function (elm) { 454 | if(elm.is(":checkbox, :radio")){ 455 | return elm.is(":checked") ? elm.val() : ''; 456 | } else if (elm.is("[value], select")){ 457 | return elm.val(); 458 | } else if (elm.is("img")){ 459 | return elm.attr('src'); 460 | } else { 461 | return elm.text(); 462 | } 463 | return ''; 464 | }, 465 | /* 466 | * Compare equality of two product objects 467 | */ 468 | _isObjectsEqual: function (o1, o2) { 469 | if (Object.getOwnPropertyNames(o1).length !== Object.getOwnPropertyNames(o2).length) { 470 | return false; 471 | } 472 | for (var p in o1) { 473 | if(p === 'unique_key' || p === this.options.paramSettings.productQuantity) { 474 | continue; 475 | } 476 | if (typeof o1[p] === typeof undefined && typeof o2[p] === typeof undefined) { 477 | continue; 478 | } 479 | if (o1[p] !== o2[p]){ 480 | return false; 481 | } 482 | } 483 | return true; 484 | }, 485 | /* 486 | * Format money 487 | */ 488 | _getMoneyFormatted: function (n) { 489 | n = n - 0; 490 | return Number(n.toFixed(2)).toLocaleString(this.options.currencySettings.locales, this.options.currencySettings.currencyOptions); 491 | }, 492 | /* 493 | * Get the value of an element and empty value if the element not exists 494 | */ 495 | _getValueOrEmpty: function (v) { 496 | return (v && typeof v !== typeof undefined) ? v : ''; 497 | }, 498 | /* 499 | * Validate Number 500 | */ 501 | _getValidateNumber: function (n) { 502 | n = n - 0; 503 | if(n && n > 0){ 504 | return true; 505 | } 506 | return false; 507 | }, 508 | /* 509 | * Small templating function 510 | */ 511 | _formatTemplate: function (t, o){ 512 | var r = t.split("{"), fs = ''; 513 | for(var i=0; i < r.length; i++){ 514 | var vr = r[i].substring(0, r[i].indexOf("}")); 515 | if(vr.length > 0){ 516 | fs += r[i].replace(vr + '}', this._getValueOrEmpty(o[vr])); 517 | }else{ 518 | fs += r[i]; 519 | } 520 | } 521 | return fs; 522 | }, 523 | /* 524 | * Event raiser 525 | */ 526 | _triggerEvent: function (name, params) { 527 | // Trigger an event 528 | var e = $.Event(name); 529 | this.cart_element.trigger(e, params); 530 | if (e.isDefaultPrevented()) { return false; } 531 | return e.result; 532 | }, 533 | /* 534 | * Get unique key 535 | */ 536 | _getUniqueKey: function () { 537 | var d = new Date(); 538 | return d.getTime(); 539 | }, 540 | /* 541 | * Log message to console 542 | */ 543 | _logMessage: function (msg) { 544 | if(this.options.debug !== true) { return false; } 545 | // Log message 546 | console.log(msg); 547 | }, 548 | /* 549 | * Log error to console and terminate execution 550 | */ 551 | _logError: function (msg) { 552 | if(this.options.debug !== true) { return false; } 553 | // Log error 554 | $.error(msg); 555 | }, 556 | 557 | // PUBLIC FUNCTIONS 558 | /* 559 | * Public function to sumbit the cart 560 | */ 561 | submit: function () { 562 | this._submitCart(); 563 | }, 564 | /* 565 | * Public function to clear the cart 566 | */ 567 | clear: function () { 568 | this._clearCart(); 569 | } 570 | }); 571 | 572 | // Wrapper for the plugin 573 | $.fn.smartCart = function(options) { 574 | var args = arguments; 575 | var instance; 576 | 577 | if (options === undefined || typeof options === 'object') { 578 | return this.each( function() { 579 | if ( !$.data( this, "smartCart") ) { 580 | $.data( this, "smartCart", new SmartCart( this, options ) ); 581 | } 582 | }); 583 | } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { 584 | instance = $.data(this[0], 'smartCart'); 585 | 586 | if (options === 'destroy') { 587 | $.data(this, 'smartCart', null); 588 | } 589 | 590 | if (instance instanceof SmartCart && typeof instance[options] === 'function') { 591 | return instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) ); 592 | } else { 593 | return this; 594 | } 595 | } 596 | }; 597 | 598 | })(jQuery, window, document); --------------------------------------------------------------------------------