Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(App){
- window.App = App = App||{};
- var CheckoutWidget = App.CheckoutWidget = App.Widget.extend({
- defaults: function(){
- return {
- ajaxHandler: CheckoutWidget.ajaxHandler,
- isAuth: false,
- props: {},
- paySystems: {},
- deliveries: {},
- authForm: {},
- componentParams: '',
- block:{
- part_pay:'.part_pay'
- },
- selector:{
- count_pay_part:'div.count-pay-part select'
- }
- }
- },
- initialize: function(){
- this.__initForm();
- this.__initUserProps();
- this.__initPaySystems();
- this.__initDeliveries();
- this.__initAuthForm();
- this.__initCoupon();
- this.__events();
- },
- __events:function(){
- },
- __initForm: function(){
- this.$form = this.$el.find('form#checkout_main_form');
- this.$form.on('submit', $.proxy(this, 'submit'));
- },
- __initCoupon: function(){
- var $couponInput = $("#js_coupon_input");
- var $applyCouponButton = $("#js_apply_coupon");
- var $removeCouponButton = $("#js_remove_coupon");
- var _this = this;
- $applyCouponButton.on("click", function(event){
- event.preventDefault();
- _this.sendForm({
- func: 'processOrder',
- action: 'enterCoupon',
- coupon: $couponInput.val(),
- signedParamsString: _this.componentParams
- }, function(response){
- this.$el.replaceWith(response.data.html);
- });
- });
- $removeCouponButton.on("click", function(event){
- event.preventDefault();
- _this.sendForm({
- func: 'processOrder',
- action: 'removeCoupon',
- coupon: $couponInput.val(),
- signedParamsString: _this.componentParams
- }, function(response){
- this.$el.replaceWith(response.data.html);
- });
- });
- return false;
- },
- __initUserProps: function(){
- var _this = this;
- this.$el.find('.a-checkout-user-prop').each(function(){
- var prop = PropWidget.build($(this));
- _this.props[prop.code] = prop;
- });
- },
- __initPaySystems: function(){
- var _this = this;
- this.$el.find('.checkout_pay_system').each(function(){
- var paySystem = new PaySystemWidget($(this));
- $(paySystem).on(':change', function(e, paySystem, refresh){
- // if(refresh){
- // _this.refresh();
- // }
- });
- _this.paySystems[paySystem.id] = paySystem;
- $(_this.selector.count_pay_part).styler();
- });
- },
- __initDeliveries: function(){
- var _this = this;
- this.$el.find('.checkout_delivery').each(function(){
- var delivery = DeliveryWidget.build($(this));
- $(delivery).on(':change', function(e, delivery, refresh){
- //console.log(refresh);
- if(refresh){
- _this.refresh();
- $.removeCookie("divide_confirmed");
- }
- });
- _this.deliveries[delivery.id] = delivery;
- });
- },
- __initAuthForm: function(){
- var _this = this;
- this.authForm = new AuthFormWidget(this.$el.find('#checkout_auth'), {
- ajaxHandler: this.ajaxHandler
- });
- $(this.authForm).on(':submit', function(){
- _this.authorize();
- });
- _this.eventts();
- },
- eventts:function(){
- var _this = this;
- var $email = this.$el.find('form#checkout_main_form input[data-name="EMAIL"]');
- this.$errorEmail = $email.siblings('.err-text');
- dataTime = this.$el.find("select[name='ORDER_PROP_19']");
- dataTime.on('change', function(){
- if(dataTime.find("option:selected").data("express") != 1 || !($(this).data().no_refresh ? true : false)){ // getTimeData() local/modules/aniart.main/lib/services/novaposhtaservice.php
- _this.$el.find("select[name='DELIVERY_ID'] option:selected").val(3);/// 3 - доставка курьером
- _this.refresh();
- }
- });
- $(document).off('click').on('click', '.choose_another_delivery_type', function () {
- var delivery_types = App.Checkout.selector.deliveryType;
- var avaliable_delivery_variants = [];
- $(`${delivery_types} > option`).each(function (index, element) {
- avaliable_delivery_variants.push($(element).data('id'))
- });
- if(avaliable_delivery_variants.length > 1){
- $(`${delivery_types} > option:not(:selected)`).eq(0).prop('selected', true);
- $(delivery_types).trigger('refresh');
- _this.refresh();
- };
- })
- //проверка на уникальность емейла
- // $email.focusout(function () {
- //
- // $.post(App.CheckoutWidget.ajaxHandler, {
- // func: 'checkUniqueEmail',
- // email: $email.val(),
- //
- // }, function(response){
- // if(response.status==='success'){
- // _this.$errorEmail.empty();
- // _this.$errorEmail.hide();
- // }else{
- // _this.$errorEmail.html(response.message);
- // _this.$errorEmail.show();
- // }
- // }, 'json');
- // });
- },
- authorize: function(){
- var _this = this;
- this.sendForm({
- func: 'authorize',
- do_authorize: 'Y',
- action: 'showAuthForm',
- save: 'Y',
- template:this.template,
- signedParamsString: this.componentParams
- }, function(response){
- var isError = !!response.data.order['ERROR'];
- if(response.status=='ok'&&!isError){
- window.location.reload();
- }
- if(isError){
- _this.authForm.showErrors(response.data.order['ERROR']['AUTH'].join('<br />'));
- }
- return false;
- }, this.authForm.$form);
- },
- refresh: function(){
- this.sendForm({
- func: 'processOrder',
- action: 'processOrder',
- template:this.template,
- signedParamsString: this.componentParams
- }, function(response){
- this.$el.replaceWith(response.data.html);
- App.getStyler({object: $('select')});
- App.getStyler({object: $('input')});
- $('select').css({'visibility': 'visible'});
- $('input').css({'visibility': 'visible'});
- });
- },
- checkErrFields:function () {
- var err = false;
- $('#sale_order input').each(function (i,e) {
- if($(e).hasClass('inp-error-pink')){
- var top = $(this).offset().top;
- $('html, body').animate({ scrollTop: top }, 500);
- err = true;
- return;
- }
- });
- if(err){return true;}
- },
- submit: function(e){
- if(e){
- e.preventDefault();
- }
- if(!App.checkFormFields(this.$form)) {
- return false;
- }
- var _this = this;
- var city,city_, policy;
- policy = this.$el.find('input[name="ORDER_POLICY"]');
- if(!policy.is(':checked')){
- policy.addClass('inp-error-pink');
- policy.trigger('refresh');
- return;
- }
- city = this.$el.find('input[name="ORDER_PROP_4"]');
- city_ = this.$el.find('select[name="ORDER_PROP_4"]');
- if(!city.val() && !city_.val()){
- city.addClass('inp-error-pink');
- city.trigger('refresh');
- return;
- }
- var data = {
- func: 'processOrder',
- action: 'processOrder',
- json: 'Y',
- template:this.template,
- signedParamsString: this.componentParams,
- confirmorder: 'Y'
- };
- this.sendForm(data, function(response){
- if(response.data.html['redirectUrl']){
- var url = response.data.html['redirectUrl'];
- window.location.href = url;
- }
- if(response.data.html['redirect'] && !response.data.html['redirectUrl']){
- var url = response.data.html['redirect'].split('?');
- window.location = '/checkout/?'+url[1];
- return;
- }
- this.$el.replaceWith(response.data.html);
- App.getStyler({object: $('input')});
- $('input').css({'visibility': 'visible'});
- });
- },
- sendForm: function(data, callback, $form){
- var _this = this;
- if(CheckoutWidget.sendFormTimeout){
- clearTimeout(CheckoutWidget.sendFormTimeout);
- }
- CheckoutWidget.sendFormTimeout = setTimeout(function(){
- _this.__sendForm(data, function(response){
- if(response.status=='ok'){
- if(response.data.html.liqpayForm != undefined){
- $("body").append(response.data.html.liqpayForm);
- $("#liqpay-form").submit();
- }else{
- callback.apply(_this, [response]);
- _this.checkErrFields();
- }
- }else{
- alert(response.message);
- }
- }, $form);
- }, 500);
- },
- __sendForm: function(data, callback, $form){
- data = data||{};
- callback = callback||$.noop;
- $form = $form||this.$form;
- var request = $form.serialize();
- for(var paramName in data){
- var paramValue = data[paramName];
- request += '&'+paramName+'='+paramValue;
- }
- return $.post(this.ajaxHandler, request, callback, 'json');
- }
- }, {
- lang: 'ru',
- ajaxHandler: App.AJAX_DIR+'?handler=order',
- sendFormTimeout: false
- });
- var BaseRadioWidget = App.Widget.extend({
- defaults: function(){
- return {
- $radio: null
- }
- },
- initialize: function(){
- var _this = this;
- this.$radio = this.$el.is('[type="radio"]')?this.$el:this.$el.find('input[type="radio"]');
- this.$radio.on('change', function(){
- //_this.__initAdditional($(this));
- $(_this).trigger(':change', [_this]);
- });
- this.$radio.styler();
- _this.__initAdditional(this.$radio);
- },
- __initAdditional: function($radio){
- if($radio.is(':checked')){
- $radio.closest('.order-form-choose').find('.order-radio').removeClass('checked');
- $radio.closest('.order-radio').addClass('checked');
- }else{
- $radio.closest('.order-radio').removeClass('checked');
- }
- }
- });
- var BaseSelectWidget = App.Widget.extend({
- defaults: function(){
- return {
- $select: null
- };
- },
- initialize: function(){
- var _this = this;
- this.$select = this.$el.find('select');
- this.$select.styler();
- this.$select.on('change', function(e){
- //global change block for select
- var $option = _this.$select.find('option:selected');
- var $refresh = ($(this).data().no_refresh ? false : true);
- $(_this).trigger(':change', [$option, $refresh]);
- });
- }
- });
- var PaySystemWidget = BaseSelectWidget.extend({
- defaults: function(){
- return {
- id: 0
- }
- },
- initialize: function(){
- PaySystemWidget.__super__.initialize.apply(this, arguments);
- var options = arguments[1] || {};
- this.id = options.id || this.$el.data('id');
- }
- });
- var DeliveryWidget = BaseSelectWidget.extend({
- defaults: function(){
- return {
- id: 0
- }
- },
- initialize: function(){
- DeliveryWidget.__super__.initialize.apply(this, arguments);
- var options = arguments[1]||{};
- this.id = options.id||this.$el.data('id');
- }
- }, {
- build: function($el){
- if($el.find('#checkout_np_city').length){
- return new NewPostDeliveryWidget($el);
- }else if($el.find('#checkout_streets').length){
- return new NewPostDeliveryWidget($el);
- }
- return new DeliveryWidget($el);
- }
- });
- var NewPostDeliveryWidget = DeliveryWidget.extend({
- defaults: function(){
- return {
- cities: null,
- departments: null,
- $cityId: null,
- $dep: null,
- $address: null,
- $schedule: null,
- $streets: null,
- $depId: null,
- $deliveryId:null,
- $depref:null,
- $oldstreets:null
- }
- },
- initialize: function(){
- NewPostDeliveryWidget.__super__.initialize.apply(this, arguments);
- this.loader = new App.LoaderWidget(this.$el);
- this.$deliveryId = this.$el.find('option:selected').val();
- this.$streetsVal = this.$el.find('#checkout_np_streets input[type="text"]');
- this.$houseVal = this.$el.find('#checkout_np_house input[type="text"]');
- this.$roomsVal = this.$el.find('#checkout_np_rooms input[type="text"]');
- this.__initCity();
- this.__initStreets();
- this.__initDepartments();
- this.$streetsId = this.$el.find('#checkout_np_streets input[type="hidden"]');
- this.$cityId = this.$el.find('#checkout_np_city input[type="hidden"]');
- this.$depId = this.$el.find('#checkout_np_departments input[type="hidden"]');
- this.$dep = this.$el.find('.post-tit');
- this.$address = this.$el.find('.post-adr');
- this.$schedule = this.$el.find('.post-time');
- },
- __initCity: function(){
- // console.log(this.$deliveryId);
- var _this = this;
- this.cities = new NewPostDeliveryWidget.CitiesWidget(this.$el.find('#checkout_np_city'), {
- loader: this.loader
- });
- /// для доставки у відділення
- var DepartmentDelivery = BX.message('DepartmentDelivery');
- if(this.$deliveryId == DepartmentDelivery){
- $(this.cities).on(":select", function (e, suggestion) {
- _this.departments.showForCity(suggestion.data, _this.$depref);
- _this.$cityId.val(suggestion.data);
- });
- }else {
- $(this.cities).on(":selectForStreets", function (e, suggestion) {
- _this.streets.__initInput(suggestion.data, _this.$oldstreets);
- _this.$cityId.val(suggestion.data);
- });
- }
- $(this.cities).on(':empty', function(e){
- _this.$houseVal.val("");
- _this.$roomsVal.val("");
- _this.$streetsVal.val("");
- _this.$streetsId.val("");
- _this.$cityId.val("");
- _this.departments.$select.empty();
- _this.departments.hide();
- _this.$cityId.empty();
- _this.$streetsId.empty();
- _this.$dep.empty();
- _this.$depId.empty();
- _this.$address.empty();
- _this.$address.hide();
- _this.$schedule.empty();
- });
- },
- __initStreets: function(){
- var _this = this;
- this.streets = new NewPostDeliveryWidget.StreetsWidget(this.$el.find('#checkout_np_streets'), {
- loader: this.loader
- });
- $(this.streets).on(':selectStreets', function(e, streets){
- _this.$oldstreets = streets;
- _this.$streetsId.val(streets.data);
- _this.$streetsVal.val(streets.value);
- });
- $(this.streets).on(':empty', function(e){
- _this.$cityId.empty();
- _this.$cityId.val("");
- _this.$streetsVal.val("");
- });
- },
- __initDepartments: function(){
- var _this = this;
- this.departments = new NewPostDeliveryWidget.DepartmentsWidget(this.$el.find('#checkout_np_departments'), {
- loader: this.loader
- });
- this.departments.hide(this.departments);
- $(this.departments).on(':selectDepartment', function(e, department){
- _this.$depref = department;
- var dep, addr, schedule;
- [dep, addr] = department.NAME.split(':');
- //schedule = department.SCHEDULE['Monday']||'';
- //schedule += '<br />'+department.PHONE;
- _this.$dep.html(dep);
- _this.$depId.val(department.REF);
- _this.$address.html(addr);
- //_this.$schedule.html(schedule);
- });
- }
- }, {
- DepartmentsWidget: App.Widget.extend({
- defaults: function(){
- return {
- $select: null,
- $error: null,
- loader: null,
- departments: {}
- };
- },
- initialize: function(){
- this.__initSelect();
- },
- __initSelect: function(){
- var _this = this;
- this.$select = this.$el.find('select');
- this.$select.styler();
- this.$select.on('change', function(){
- var $option = _this.$select.find('option:selected');
- var department = _this.departments[$option.data('id')];
- // console.log(department);
- if(department){
- $(_this).trigger(':selectDepartment', [department]);
- }
- });
- this.$error = this.$el.find('.err-text');
- },
- showForCity: function(cityRef, oldDepRef){
- var _this = this;
- if(!cityRef){
- return;
- }
- oldDepRef = oldDepRef?oldDepRef:"";
- if(cityRef == oldDepRef.CITY_REF){
- _this.show();
- return;
- }
- this.clearError();
- this.loader.show();
- $.post(App.CheckoutWidget.ajaxHandler, {
- func: 'getNewPostDepartmentsByCityRef',
- cityRef: cityRef,
- lang: App.CheckoutWidget.lang
- }, function(response){
- //console.log(response);
- _this.clearError();
- _this.loader.hide();
- if(response.status==='success'){
- _this.$select.empty();
- var defaultDepartment = _this.$select.data('dep')||response.data[0]['NAME'];
- response.data.map(function(departmentData){
- //console.log(departmentData);
- var $option = $('<option>', {
- text: departmentData.NAME,
- value: departmentData.NAME
- });
- if(departmentData.NAME===defaultDepartment){
- $option.attr('selected', 'selected');
- }
- $option.data('id', departmentData['REF']);
- _this.$select.append($option);
- _this.departments[departmentData['REF']] = departmentData;
- });
- _this.$select.trigger('change');
- _this.$select.trigger('refresh');
- _this.show();
- _this.loader.reset();
- }else{
- _this.showError(response.message);
- }
- }, 'json');
- },
- hide: function(){
- this.$el.hide();
- },
- show: function(){
- this.$el.show();
- },
- clearError: function(){
- this.$el.removeClass('error-inp');
- this.$error.empty();
- },
- showError: function(message){
- this.$el.addClass('error-inp');
- this.$error.html(message);
- }
- }),
- CitiesWidget: App.Widget.extend({
- defaults: function(){
- return {
- $input: null,
- $error: null,
- loader: null,
- $streetsVall:null
- }
- },
- initialize: function(){
- this.$error = this.$el.find('.err-text');
- this.__initInput();
- },
- __initInput: function(){
- var _this = this;
- this.$input = this.$el.find('input[type="text"]');
- this.$inputHidden = this.$el.find('input[type="hidden"]');
- $(this.$el).on('input', _this.$input, function(e){
- if(_this.$input.val()<2){
- $(_this).trigger(':empty');
- }
- });
- setTimeout(function(){
- _this.$input.autocomplete({
- serviceUrl: CheckoutWidget.ajaxHandler,
- type: 'POST',
- params: {
- lang: App.CheckoutWidget.lang,
- func: 'getNewPostCities'
- },
- deferRequestBy: 350,
- minChars: 2,
- onSearchStart: function(){
- // _this.loader.show();
- // _this.clearError();
- },
- transformResult: function(response){
- // _this.loader.hide();
- response = JSON.parse(response);
- var suggestions = [];
- if(response.status == 'error'){
- // _this.$input.val('');
- _this.$inputHidden.val("");
- $(_this).trigger(':empty');
- _this.showError(response.message);
- return {suggestions: suggestions};
- }
- _this.clearError();
- suggestions = response.data.map(function(cityData){
- return {value: cityData.NAME, data: cityData.REF};
- });
- if(!suggestions.length){
- _this.showError(response.message);
- _this.$inputHidden.val("");
- // _this.$input.val('');
- $(_this).trigger(':empty');
- }
- return {suggestions: suggestions};
- },
- onSelect: function(suggestion){
- $(_this).trigger(':select', [suggestion]);
- $(_this).trigger(':selectForStreets', [suggestion]);
- }
- });
- var value = _this.$input.val();
- if(value){
- _this.$input.focus();
- }
- }, 1000);
- },
- clearError: function(){
- this.$el.removeClass('error-inp');
- this.$error.empty();
- },
- showError: function(message){
- this.$el.addClass('error-inp');
- this.$error.html(message);
- }
- }),
- StreetsWidget: App.Widget.extend({
- defaults: function(){
- return {
- $input: null,
- $error: null,
- loader: null
- }
- },
- initialize: function(){
- this.$error = this.$el.find('.err-text');
- this.__initInput();
- },
- __initInput: function(cityRef, oldstreets){
- var _this = this;
- var $oldstreets = oldstreets;
- this.$input = this.$el.find('input[type="text"]');
- this.$inputHidden = this.$el.find('input[type="hidden"]');
- if(!cityRef){
- cityRef = $('#checkout_np_city input[type="hidden"]').eq(1).val();
- }if(!cityRef){
- cityRef = $('#checkout_np_city input[type="hidden"]').eq(0).val();
- }
- setTimeout(function(){
- _this.$input.autocomplete({
- serviceUrl: CheckoutWidget.ajaxHandler,
- type: 'POST',
- params: {
- func: 'getNewPostStreets',
- cityRef: cityRef
- },
- deferRequestBy: 350,
- minChars: 2,
- onSearchStart: function(){
- // _this.loader.show();
- _this.clearError();
- },
- transformResult: function(response, e){
- response = JSON.parse(response);
- var suggestions = [];
- if(response.status == 'error'){
- _this.showError(response.message);
- _this.$inputHidden.val('');
- $(_this).trigger(':empty');
- return {suggestions: suggestions};
- }
- suggestions = response.data.map(function(streetData){
- return {value: streetData.Description + " (" + streetData.StreetsType+")", data: streetData.Ref};
- });
- if(!suggestions.length){
- _this.showError(response.message);
- _this.$inputHidden.val('');
- $(_this).trigger(':empty');
- }
- return {suggestions: suggestions};
- },
- onSelect: function(suggestion){
- $(_this).trigger(':selectStreets', [suggestion]);
- }
- });
- var value = _this.$input.val();
- if(value){
- _this.$input.focus();
- }
- }, 1000);
- },
- clearError: function(){
- this.$el.removeClass('error-inp');
- this.$error.empty();
- },
- showError: function(message){
- this.$el.addClass('error-inp');
- this.$error.html(message);
- },
- isSelected: function(){
- return this.$el.is(':selected');
- }
- }),
- });
- var PropWidget = App.Widget.extend({
- defaults: function(){
- return {
- id: 0,
- code: '',
- $input: null
- }
- },
- initialize: function(){
- this.$input = this.$el.find('input');
- },
- getValue: function(){
- return this.$input.val();
- }
- }, {
- build: function($el){
- var params = {id: $el.data('id'), code: $el.data('code')};
- if(!params.code){
- throw new Error('PropWidget: Invalid property code');
- }
- var propWidget;
- if(params.code=='PHONE'){
- propWidget = new PhonePropWidget($el, params);
- }else{
- propWidget = new PropWidget($el, params);
- }
- return propWidget;
- }
- });
- var PhonePropWidget = PropWidget.extend({
- initialize: function(){
- PhonePropWidget.__super__.initialize.apply(this, arguments);
- // App.phoneField(this.$input);
- }
- });
- var AuthFormWidget = App.Widget.extend({
- defaults: function(){
- return {
- $form: null,
- $emailInput: null,
- $passwordInput: null,
- $forgotLink: null,
- $forgotModal: null,
- $errors: null
- }
- },
- initialize: function(){
- this.__initForm();
- this.__initForgotLink();
- this.$emailInput = this.$form.find('input[name="USER_LOGIN"]');
- this.$passwordInput = this.$form.find('input[name="USER_PASSWORD"]');
- this.$errors = this.$form.find('#checkout_auth_error');
- },
- __initForm: function(){
- var _this = this;
- this.$form = this.$el.find('form');
- this.$form.on('submit', function(e){
- e.preventDefault();
- _this.clearErrors();
- $(_this).trigger(':submit');
- });
- },
- __initForgotLink: function(){
- this.$forgotLink = this.$form.find('#checkout_auth_forgot');
- this.$forgotModal = $('#myModal');
- var _this = this;
- this.$forgotLink.on('click', function(){
- _this.$forgotModal.one('show.bs.modal', function(){
- _this.$forgotModal.find('div.one-log-forg a').click();
- });
- _this.$forgotModal.modal();
- });
- },
- clearErrors: function(){
- this.$errors.empty().hide();
- },
- showErrors: function(err){
- this.$errors.html(err).show();
- }
- });
- })(window.App);
- var Checkout = App.Checkout = (function(App){
- window.App = App = App || {};
- return {
- storesDetached: false,
- selector: {
- idDeliv: '#checkout_np_timeInterval select',
- idDelivSelected: '#checkout_np_timeInterval .selected',
- deliveryType: '.checkout_delivery select[name="DELIVERY_ID"]',
- inputHide: '#checkout_np_timeInterval input[type="hidden"]',
- userDataProps: '.user-data-props input',
- buyButton: '.one-click-bt span',
- quantity: '.cart_item_quantity select',
- checkout: '#cart_main_checkout',
- selectedStore: ".all-hide-radio .selected",
- selectStores: "select#checkout_stores_select",
- selectCity: "select#checkout_cities_stores",
- basketItemDelete: ".checkout_cart_item_delete a",
- paySystemType: ".checkout_pay_system select[name='PAY_SYSTEM_ID']",
- groupsModal: "#basket_groups",
- paySystemPayParts: 9,
- paySystemPayCashInShop: 8,
- paySystemPayLiqpay: 7,
- paySystemPayCash: 6,
- deliveryTypeExpress: 5,
- deliveryTypePickup: 6,
- },
- events: function () {
- var _app = App,
- _this = this;
- if($(this.selector.deliveryType).val() == _this.selector.deliveryTypeExpress) {
- _this.changeValue();
- }
- $(document).on('click', this.selector.buyButton, function (){
- setTimeout(function(){
- $('#myModal2').modal('show');
- },3000);
- });
- $(document).ready(setTimeout(function (){
- $('#myModal2').modal('show');
- },3000));
- $(document).on("input", this.selector.userDataProps ,function () {
- var pattern = $(this).data("pattern");
- var value = $(this).val();
- if(pattern != "undefined" && pattern != undefined){
- pattern = pattern.split("/");
- reg = new RegExp(pattern[1]);
- if(reg.test(value.trim()) || value.trim() == ""){
- if ($(this).hasClass("inp-error-pink")) {
- $(this).removeClass("inp-error-pink");
- $(this).siblings(".err-text").hide();
- }
- }
- else
- {
- if (value.trim() != ""){
- $(this).siblings(".err-text").show();
- $(this).addClass("inp-error-pink");
- }
- }
- }
- });
- $(document).on("click",".confirm_devide",function () {
- var groupsArr = [];
- var groupObj = {};
- $(document).find('.devide-group').each(function(i,e){
- var store_id = $(e).find('#select_store option').data('id');
- groupObj[store_id] = [];
- $(e).find('.one-prod-basket').each(function(i,e){
- groupObj[store_id].push($(e).data('id'))
- })
- });
- var devideData = JSON.stringify(groupObj);
- $("input[name='ORDER_PROP_37']").val(devideData);
- $.cookie('divide_confirmed', 'true');
- });
- // $(document).on('change', _this.selector.deliveryType, function(e){
- //
- // if($(this).val() == _this.selector.deliveryTypeExpress) {
- // setTimeout(function(e){
- // _this.changeValue(e);
- // }, 1000);
- // }
- //
- // });
- $(document).on('change', _this.selector.paySystemType, function(e){
- var delivery = $('.checkout_delivery.one-del .deliver .selected').text();
- var paysyst = $('.checkout_pay_system .selected').text();
- _this.getMsgForPaySystemAndDelivery(paysyst, delivery);
- $(".part_pay").hide();
- $(".hidden_part").hide();
- if($(this).val() == _this.selector.paySystemPayParts){
- $('.part_pay').show();
- $('.for_pp').show();
- }
- });
- $(document).on("click", "span.show_check_limit", function () {
- $(".hidden_part").show();
- });
- $(document).on("click", "a#limit", function () {
- var number = $(".part_pay .hidden_part input.phone").val();
- _this.sendToCheckLimit(number);
- });
- $(document).on('change',this.selector.idDeliv, function (e) {
- _this.changeValue(e);
- });
- $(document).on('click', _this.selector.basketItemDelete, function(params){
- var productId = $(this).data("id");
- var deliveryId = $(document).find(_this.selector.deliveryType).val();
- var paySystemId = $(document).find(_this.selector.paySystemType).val();
- var storeSityId = $(document).find("#checkout_stores .sel").data("id");
- params.id = productId || 0;
- params.deliveryId = deliveryId || 0;
- params.paySystemId = paySystemId || 0;
- params.storeSityId = storeSityId || 1;
- if(params.id <= 0){
- return false;
- }
- _this.delete(params);
- });
- $(document).on('change', _this.selector.quantity, function(){
- var deliveryId = $(document).find(_this.selector.deliveryType).val();
- var paySystemId = $(document).find(_this.selector.paySystemType).val();
- var storeSityId = $(document).find("#checkout_stores .sel").data("id");
- _this.getCalculate({
- id:$(this).data().id,
- quantity:$(this).find('option:selected').val(),
- deliveryId: deliveryId,
- paySystemId:paySystemId,
- storeSityId:storeSityId
- });
- });
- $(document).on('change', "#checkout_stores #checkout_np_city select ", function(){
- var cityValue = $(this).val();
- var cityId = $('#checkout_cities_stores option[value="'+cityValue+'"]').data().id;
- //$('.all-hide-radio').hide();
- $(_this.selector.selectStores).remove();
- $("span.address").text("");
- $("#checkout_stores_select-styler").remove();
- _this.getStoreByCityId(cityId);
- });
- $(document).on("change",_this.selector.selectStores, function(){
- _this.setAdressAndShopId();
- });
- $(document).on('show.bs.modal', _this.selector.groupsModal, function () {
- _this.attachStoresToModal();
- $(document).find('#myModal1').addClass('modal_hidden');
- });
- $(document).on('hide.bs.modal', _this.selector.groupsModal, function () {
- _this.attachStoresToPage();
- $(document).find('#myModal1').removeClass('modal_hidden');
- $(document).find('#myModal1').modal('hide');
- });
- App.getPhoneMask({
- object:$(document).find(".part_pay .hidden_part input.phone")
- });
- },
- init: function () {
- this.setAdressAndShopId();
- this.events();
- },
- attachStoresToModal: function(){
- var _this = this;
- try{
- if(! _this.storesDetached && $('#checkout-stores-attachable > #checkout_stores').length > 0){
- $(document).find('#checkout-stores-attachable > #checkout_stores')
- .detach()
- .appendTo('#modal-stores-attacheble');
- _this.storesDetached = true;
- }
- } catch (e) {
- console.log('err attachStoresToModal', e)
- }
- },
- attachStoresToPage: function(){
- var _this = this;
- try{
- if( _this.storesDetached && $('#modal-stores-attacheble > #checkout_stores').length > 0 ){
- $(document).find('#modal-stores-attacheble > #checkout_stores')
- .detach()
- .appendTo('#checkout-stores-attachable');
- _this.storesDetached = false;
- }
- } catch (e) {
- console.log('err attachStoresToPage', e)
- }
- },
- setAdressAndShopId: function(){
- var _this =this;
- var address = $(document).find(_this.selector.selectedStore).data("address");
- var store_id = $(document).find(_this.selector.selectedStore).data("id");
- $(document).find("span.address").text(address);
- $(document).find(".radio-hide input[type='hidden']").val(store_id);
- },
- changeValue:function (e) {
- _this = this;
- var date = $(this.selector.idDelivSelected).data('code');
- var date_exp = $(this.selector.idDelivSelected).data('express');
- var data_id = $(this.selector.idDelivSelected).val();
- $(_this.selector.inputHide).val(date);
- },
- getCalculate:function(params){
- params.id = params.id || 0;
- params.quantity = params.quantity || 0;
- params.basket = params.basket || {};
- params.deliveryId = params.deliveryId || 0;
- params.paySystemId = params.paySystemId || 0;
- params.storeSityId = params.storeSityId || 1;
- if(params.id <= 0 || params.quantity <= 0){
- return false;
- }
- var _this = this;
- return _this.update({
- id:params.id,
- quantity:params.quantity,
- deliveryId: params.deliveryId,
- paySystemId: params.paySystemId,
- storeSityId: params.storeSityId
- }, function(data){
- });
- },
- update:function(params, callback){
- var _app = App,
- _this = this;
- _app.post({
- data:{
- handler:'basket',
- func:'update',
- id:params.id,
- quantity:params.quantity,
- checkout: "checkout",
- getbasketHtml: true,
- deliveryId: params.deliveryId,
- storeSityId: params.storeSityId,
- paySystemId: params.paySystemId
- }
- }, function(response){
- if(response.status != 'success'){
- return $(_this.selector.popupError).modal('show');
- }else {
- if(response.data.basketHtml.length){
- $(_this.selector.checkout).html(response.data.basketHtml);
- }
- if(response.data.textForPayPart !== null) {
- $(".one-del.part_pay span.bold").text(response.data.basketCalcPayPart);
- }
- if (response.data.basketAmount < PAYPARTS_MIN_SUM){
- $(".one-del.part_pay span.bold").addClass("err")
- } else {
- $(".one-del.part_pay span.bold").removeClass("err")
- }
- _this.devideBasket(response.data, params.storeSityId);
- }
- });
- },
- devideBasket: function (data, id) {
- var _this = this;
- if(data.pickUp == false) {
- $(document).find('.checkout_delivery option[data-id="6"]').attr('disabled', true).trigger('refresh');
- if(data.changeDelivery == true){
- // alert("Тип доставки буде змінено");
- window.location.reload();
- }
- }else {
- $(document).find('.checkout_delivery option[data-id="6"]').attr('disabled', false).trigger('refresh');
- $(_this.selector.selectStores).remove();
- $("span.address").text("");
- $("#checkout_stores_select-styler").remove();
- if(data.showPopup == true) {
- _this.getStoreByCityId(id);
- }
- $(document).find('#checkout_stores_select select').trigger('refresh');
- }
- },
- delete:function(params, callback){
- var _app = App,
- _this = this;
- _app.post({
- data:{
- handler:'basket',
- func:'delete',
- id:params.id,
- template: "checkout",
- getbasketHtml: true,
- deliveryId: params.deliveryId,
- storeSityId: params.storeSityId,
- paySystemId: params.paySystemId
- }
- }, function(response){
- if(response.status != 'success'){
- return $(_this.selector.popupError).modal('show');
- }else {
- if(response.data.basketHtml.length){
- $(_this.selector.checkout).html(response.data.basketHtml);
- }
- if(response.data.textForPayPart !== null) {
- $(".one-del.part_pay span.bold").text(response.data.basketCalcPayPart);
- }
- if (response.data.basketAmount < PAYPARTS_MIN_SUM){
- $(".one-del.part_pay span.bold").addClass("err")
- } else {
- $(".one-del.part_pay span.bold").removeClass("err")
- }
- _this.devideBasket(response.data, params.storeSityId);
- }
- });
- },
- getStoreByCityId:function (cityId) {
- var _app = App,
- _this = this;
- $.post(App.CheckoutWidget.ajaxHandler, {
- func: 'getStoreByCityId',
- cityId: cityId,
- lang: App.CheckoutWidget.lang
- }, function(response){
- response = JSON.parse(response);
- if(response.status != 'success'){
- $("#order_store_id").val("");
- $(_this.selector.selectStores).val("");
- var cityName = $(_this.selector.selectCity).val();
- $('.radio-hide-select .err-text .store').html(cityName);
- $('.radio-hide-select .err-text').show();
- $('.modal-basket-cont-html').html(`<div class="error-msg">${response.message}</div>`);
- } else {
- $('.radio-hide-select .err-text').hide();
- if(response.data.needDivide == true){
- // $(".divide-popup div").remove();
- _this.attachStoresToPage();
- $("#checkout_stores_select").remove();
- $(".divide-popup").html(response.data.divideHtml);
- $(document).find('#basket_groups select').styler();
- $(_this.selector.groupsModal).modal('show');
- }else {
- $('.radio-hide-select')
- .append(`<select
- data-no_refresh="true"
- id="checkout_stores_select"
- name="ORDER_PROP_5"
- style="visibility:visible;"
- ></select>`
- );
- $select = $("select#checkout_stores_select");
- response.data.map(function (stores) {
- var $option = $('<option>', {
- text: stores.Title,
- value: stores.Title
- });
- $option.data("address", stores.Address);
- $option.data("id", stores.xml_id);
- $select.append($option);
- });
- $(document).find("select#checkout_stores_select").styler();
- _this.setAdressAndShopId();
- $('.all-hide-radio').show();
- }
- }
- });
- },
- getMsgForPaySystemAndDelivery:function (paySystem,delivery) {
- var _app = App,
- _this = this;
- $.post(App.CheckoutWidget.ajaxHandler, {
- func: 'getMsgForPaySystemAndDelivery',
- paySystem: paySystem,
- delivery: delivery,
- lang: App.CheckoutWidget.lang
- }, function(response) {
- response = JSON.parse(response);
- if(response.status != 'success') {
- }
- else{
- $(".message_info").text(response.data);
- }
- });
- },
- sendToCheckLimit:function (number) {
- var _app = App,
- _this = this;
- $.post(App.CheckoutWidget.ajaxHandler, {
- func: 'sendToCheckLimit',
- tel: number,
- lang: App.CheckoutWidget.lang
- }, function(response) {
- response = JSON.parse(response);
- if(response.status != 'success') {
- }
- else{
- $(".show_check_limit").hide();
- $(".hidden_part").html("<span>Повідомлення надіслано</span>");
- }
- });
- },
- }
- })(window.App);
- $(document).ready(function () {
- Checkout.init();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement