var ishopModule = x3mModule.extend( { connector: null, preventJquery: false, constructor: function (preventJquery) { this.preventJquery = preventJquery; this.connector = new fConnector('ishop'); }, setPaySystem: function (paysystem) { this.connector.execute( { set_paysystem: { paysystem: paysystem } }); }, addToCart: function (id, count, ext, callback) { if (!id) return; obj = { id: id, count: count } if (ext) { obj['ext'] = ext; } this.connector.execute( {add_to_cart: obj}, callback); if (!callback) return this.connector.result.cart; }, getCartItems: function () { this.connector.execute( { get_cart: true }); return ishop.connector.result.cart_items; }, jqueryRun: function () { if (this.preventJquery) return; $.fn.ishopToBasket = function (options) { var defaults = { count: 1, idNum:null, idAttribute: 'id', onGoodAdded: null, extDataFunc: null, countSelector: '.countselector', countIdAttribute: 'lang', syncAddToBasket: true, basketContainer: '.basket-container', basketCountSelector: '.countselect', basketAllCountSelector: '.basket-count', basketSumSelector: '.basket-sum', isAuth:null, error:null, isCheckbox:null, basketElementTemplate: '
  • {details.props.Name}{count}{details.props.price}{priceSum}
  • ' }; var options = $.extend(defaults, options); $(this).live('click',function(e) { e.preventDefault(); if(options.isAuth) { var result = options.isAuth(); if(options.error && result == 0 || result == null) { options.error(); return; } } ext = {}; if (jQuery.isFunction(options.extDataFunc)) ext = options.extDataFunc(this); if($(options.countSelector).length>0) { options.count = $(options.countSelector+'['+options.countIdAttribute+'='+$(this).attr(options.idAttribute)+']').val(); if(options.count == 0) { alert('Выберите количество товаров'); return; } //$(options.countSelector+'['+countIdAttribute+'='+id+']').val(); } cart = ishop.addToCart($(this).attr(options.idAttribute), options.count, ext, options.onGoodAdded); if (!options.onGoodAdded) { $(options.basketCountSelector).html(cart.count); $(options.basketAllCountSelector).html(cart.allcount); if(cart.sum>10000) $(options.basketSumSelector).html(Math.round(cart.sum)) else $(options.basketSumSelector).html(Math.round(cart.sum*100)/100); if (options.syncAddToBasket) { items = ishop.getCartItems() var container = $(options.basketContainer); container.html(''); $.each(items, function (i, item) { container.append($.nano(options.basketElementTemplate, item)) }); } } if (options.after) { options.after(this.id); return false; } }); } } }); var ishop = new ishopModule(); x3m.addModule('ishop', ishop);