2

I Have Installed Codazon Fastest Theme on my Manto2 site.i am facing an issue with js loading.

here is my system configuration below. magento version : 2.4.5 PHP: 8.0 theme: Codazon Fastest Theme

after installing the theme third-party extension js stopped working. I tried to include js using require js but the result was the same. here I have mentioned js files that cause errors.

 var config = {
 config: {
 mixins: {
 'Magento_Catalog/js/catalog-add-to-cart': {
 'Codazon_AjaxCartPro/js/catalog-add-to-cart': true
 }
 }
 },
 map: {
 '*': {
 'codazonSidebar': 'Codazon_AjaxCartPro/js/sidebar',
 'catalogAddToCart': 'Codazon_AjaxCartPro/js/catalog-add-to-cart',
 'Magento_Catalog/js/catalog-add-to-cart': 'Codazon_AjaxCartPro/js/catalog-add-to-cart',
 'mage/dataPost': 'Codazon_AjaxCartPro/js/ajax-post',
 'defaultMageDataPost': 'mage/dataPost' 
 }
 },
 deps: [
 'Codazon_AjaxCartPro/js/ajax-post'
 ]
};

path : /app/code/Codazon/AjaxCartPro/view/frontend/web/js/ajax-post.js

define([
 'jquery',
 'mage/template',
 'Magento_Ui/js/modal/confirm',
 'Magento_Customer/js/customer-data',
 'jquery-ui-modules/widget',
 'defaultMageDataPost'
 ], function(,ドル mageTemplate, uiConfirm, customerData) {
 if (typeof window.cdzBuilAjaxPost == 'undefined') {
 window.cdzBuilAjaxPost = true;
 var dataPost = $(document).data('mageDataPost');
 if (typeof dataPost != 'undefined') {
 
 var isCompareIndexPage = function() {
 return $('body').hasClass('catalog-product_compare-index');
 }
 
 var $loginPopup = $('<div class="ajax-lgfm-popup md-dialog-container account-popup" id="ajax-lgfm-popup" data-cdzpopup>').appendTo('body');
 $('body').trigger('cdzBuildPopup');
 $loginPopup.parents('.popup-ajax-lgfm-popup').first().addClass('popup-account-popup');
 dataPost.ajaxActions = {};
 dataPost.$msgContainer = $('<div class="cdz-msg-container fixed">').appendTo('body');
 dataPost.isAjaxAction = function(action) {
 if (typeof this.ajaxActions[action] == 'undefined') {
 var self = this;
 self.ajaxActions[action] = false;
 $.each(cdzAjaxPost.replacedActions, function(needSearch, replacement) {
 if (action.search(needSearch) > -1) {
 self.ajaxActions[action] = true;
 return false;
 }
 });
 }
 return this.ajaxActions[action];
 };
 dataPost.oldPostData = dataPost.postData;
 dataPost.filterAction = function(action) {
 $.each(cdzAjaxPost.replacedActions, function(needSearch, replacement) {
 if (action.search(needSearch) > -1) {
 action = replacement;
 return false;
 }
 });
 return action;
 };
 dataPost.updateMessages = function(messages) {
 var self = this;
 if (messages) {
 self.displayMessages(messages);
 } else {
 $.get(cdzAjaxPost.updateMsgUrl, {_: $.now()}, function(rs) {
 if (rs.messages) {
 if (rs.messages.messages) {
 self.displayMessages(rs.messages.messages);
 }
 }
 });
 }
 };
 dataPost.displayMessages = function(messages) {
 var self = this;
 self.$msgContainer.show();
 $.each(messages, function(i, msg) {
 var $message = $('<div class="message cdz-translator">').addClass(msg.type).html('<span>' + msg.text + '</span>').prependTo(self.$msgContainer);
 setTimeout(function() {
 $message.fadeOut(2000, 'swing', function() {
 $message.remove();
 if (!self.$msgContainer.children().length) {
 self.$msgContainer.hide();
 }
 });
 }, 3000);
 });
 };
 dataPost.ajaxPost = function(params) {
 var self = this;
 var formKey = $(this.options.formKeyInputSelector).val();
 if (formKey) {
 params.data['form_key'] = formKey;
 }
 var action = self.filterAction(params.action);
 var postParam = params;
 if (self.notLogin && (action.search('wishlist') > -1)) {
 self._displayLoginForm(false, postParam);
 } else {
 postParam.data.currentUrl = document.URL;
 if (isCompareIndexPage()) {
 postParam.data.isCompareIndexPage = true;
 }
 $('body').addClass('cdz-ajaxpost-proccessing');
 $.ajax({
 url: action,
 data: postParam.data,
 type: 'POST',
 showLoader: true,
 success: function(rs) {
 if (rs.message) {
 self.displayMessages([{
 type: (rs.success?'success':'error'),
 text: rs.message
 }]);
 } else {
 self.updateMessages();
 }
 if (rs.login_form_html) {
 self.notLogin = true;
 self._displayLoginForm(rs.login_form_html, postParam, rs.after_login_url);
 }
 
 if (action.search('wishlist/remove') > -1) {
 $('body').trigger('cdzWishlistItemRemoved', [params, rs]);
 }
 if ((action.search('wishlist/fromcart') > -1) || (action.search('wishlist/moveallfromcart') > -1)) {
 $('body').trigger('cdzWishlistItemMovedFromCart', [params, rs]);
 }
 if (action.search('compare/remove') > -1) {
 $('body').trigger('cdzCompareItemRemoved', [params, rs]);
 }
 $('body').trigger('materialUpdated');
 $('body').trigger('contentUpdated');
 if (action.search('wishlist') > -1) {
 customerData.reload(['wishlist'], false);
 }
 if (action.search('compare') > -1) {
 customerData.reload(['compare-products'], false);
 }
 }
 }).always(function() {
 $('body').removeClass('cdz-ajaxpost-proccessing');
 });
 }
 };
 dataPost.postData = function(params) {
 var self = this;
 if (this.isAjaxAction(params.action)) {
 if (params.data.confirmation) {
 uiConfirm({
 content: params.data.confirmationMessage,
 actions: {
 confirm: function () {
 self.ajaxPost(params);
 }
 }
 });
 } else {
 self.ajaxPost(params);
 }
 } else {
 this.oldPostData(params);
 }
 };
 
 dataPost._displayLoginForm = function(html, params, action) {
 referer = btoa(referer);
 if (html) {
 $loginPopup.data('action', action);
 var referer = action + 'product/' + params.data.product + '/referer/' + btoa(document.URL) + '/form_key/' + params.data.form_key;
 $loginPopup.html(html); var $form = $loginPopup.find('form');
 $form.append($('<input type="hidden" name="referer">').val(btoa(referer)));
 } else {
 action = $loginPopup.data('action');
 var referer = action + 'product/' + params.data.product + '/referer/' + btoa(document.URL) + '/form_key/' + params.data.form_key;
 $loginPopup.find('form [name="referer"]').val(btoa(referer));
 }
 $loginPopup.trigger('triggerPopup');
 }
 
 $.widget('codazon.customDataPost', $.mage.dataPost, {
 postData: function(params) {
 dataPost.postData(params);
 }
 });
 $.mage.dataPost = $.codazon.customDataPost; 
 
 $('body').on('cdzWishlistItemRemoved', function(e, params, rs) {
 var id = params.data.item;
 var $wishlistForm = $('#wishlist-view-form');
 if ($wishlistForm.length) {
 $wishlistForm.find('.product-item[id="item_' + id +'"]').fadeOut(500, 'swing', function() {
 $(this).remove();
 if ($wishlistForm.find('.product-item').length == 0) {
 var $msg = $('<div class="message info empty">').html('<span>' + cdzAjaxPost.wishlistEmptyMsg + '</span>').prependTo($wishlistForm);
 $wishlistForm.find('.actions-toolbar, .products-grid.wishlist').remove();
 }
 });
 }
 });
 $('body').on('cdzWishlistItemMovedFromCart', function(e, params, rs) {
 if (rs.success) {
 setTimeout(function() {
 document.location.reload();
 }, 1000);
 }
 });
 
 $('body').on('cdzCompareItemRemoved', function(e, params, rs) {
 if (rs.compare_list_html && isCompareIndexPage()) {
 var $oldCompareList = $('.table-wrapper.comparison').first();
 if ($oldCompareList.length) {
 $('.action.print.hidden-print').remove();
 var $newCompareList = $('<div>').html(rs.compare_list_html);
 $oldCompareList.hide().before($newCompareList);
 $oldCompareList.remove();
 $newCompareList.children().first().unwrap();
 }
 }
 });
 }
 }
});

path : /app/code/Codazon/AjaxCartPro/view/frontend/web/js/ajaxcart.js

 define([
 'uiComponent',
 'Magento_Customer/js/customer-data',
 'jquery',
 'ko',
 'codazonSidebar',
 'Magento_Ui/js/modal/modal'
 ], function (Component, customerData, ,ドル ko, paypalCheckout) {
 'use strict';
 var sidebarCart = $('[data-block="footer_minicart"]');
 var addToCartCalls = 0;
 var sidebarInitialized = false;
 function initSidebar() {
 if (sidebarCart.data('mageSidebar')) {
 sidebarCart.codazonSidebar('update');
 }
 sidebarCart.trigger('contentUpdated');
 if (sidebarInitialized) {
 return false;
 }
 sidebarInitialized = true;
 sidebarCart.codazonSidebar({
 "targetElement": "#footer-mini-cart",
 "url": {
 "checkout": window.checkout.checkoutUrl,
 "update": window.checkout.updateItemQtyUrl,
 "remove": window.checkout.removeItemUrl,
 "loginUrl": window.checkout.customerLoginUrl,
 "isRedirectRequired": window.checkout.isRedirectRequired
 },
 "button": {
 "checkout": "#footer-cart-btn-checkout",
 "remove": ".item a.action.delete",
 "close": ""
 },
 "minicart": {
 "list": "",
 "content": "",
 "qty": "",
 "subtotal": ""
 },
 "item": {
 "qty": "input.cart-item-qty",
 "button": "button.update-cart-item"
 },
 "confirmMessage": $.mage.__(
 'Are you sure you would like to remove this item from the shopping cart?'
 )
 });
 //fix paypal express checkout cart button not work on footer cart
 $( document ).ajaxComplete(function( event, xhr, settings ) {
 if( settings.url.indexOf('customer/section/load/?sections') >= 0){
 $('.footer-cart-actions [data-action="checkout-form-submit"]').off('click');
 $('.footer-cart-actions [data-action="checkout-form-submit"]').click(function(){
 $('[data-action="checkout-form-submit"]:first').click();
 });
 }
 });
 //=== end fix ===
 }
 return Component.extend({
 ajaxcart: ko.observable({}),
 crosssell: ko.observable({}),
 addedItem: ko.observable({}),
 cartSidebar: ko.observable({summary_count: false}),
 toggleFooterSidebar: function(){
 $('#footer-cart-trigger').toggleClass('active');
 $('#footer-mini-cart').slideToggle(300); 
 },
 initSidebar: initSidebar,
 initialize: function () {
 var self = this;
 this._super();
 this.addedItem({success:false});
 this.cartSidebar = customerData.get('cart');
 window.addedItem = self.addedItem;
 window.ajaxcart = self.ajaxcart;
 window.crosssell = self.crosssell;
 window.cartSidebar = self.cartSidebar;
 $('#cart-footer').show();
 initSidebar();
 this.cartSidebar.subscribe(function () {
 addToCartCalls--;
 sidebarInitialized = false; 
 initSidebar();
 }, this);
 $('[data-block="minicart"]').on('contentLoading', function(event) {
 addToCartCalls++; 
 });
 var $ajaxPopup = $('#ajax-cart-container');
 /*$ajaxPopup.modal({
 innerScroll: true,
 trigger: '.tocart',
 wrapperClass: 'ajaxcart-modal',
 buttons: [],
 opened: function(){
 window.addedItem({success:false});
 },
 closed: function(){
 } 
 });*/
 },
 });
});

path : /app/code/Codazon/AjaxCartPro/view/frontend/web/js/sidebar.js

 define([
 "jquery",
 'Magento_Customer/js/model/authentication-popup',
 'Magento_Customer/js/customer-data',
 'Magento_Ui/js/modal/alert',
 'Magento_Ui/js/modal/confirm',
 "mage/decorate"
 ], function(,ドル authenticationPopup, customerData, alert, confirm){
 $.widget('mage.codazonSidebar', {
 options: {
 isRecursive: true,
 maxItemsVisible: 3
 },
 scrollHeight: 0,
 /**
 * Create sidebar.
 * @private
 */
 _create: function () {
 this._initContent();
 },
 /**
 * Update sidebar block.
 */
 update: function () {
 $(this.options.targetElement).trigger('contentUpdated');
 this._calcHeight();
 this._isOverflowed();
 },
 _initContent: function() {
 var self = this,
 events = {};
 this.element.decorate('list', this.options.isRecursive);
 /*events['click ' + this.options.button.close] = function(event) {
 event.stopPropagation();
 $(self.options.targetElement).dropdownDialog("close");
 };*/
 events['click ' + this.options.button.checkout] = $.proxy(function() {
 var cart = customerData.get('cart'),
 customer = customerData.get('customer');
 if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
 if (this.options.url.isRedirectRequired) {
 location.href = this.options.url.loginUrl;
 } else {
 authenticationPopup.showModal();
 }
 return false;
 }
 location.href = this.options.url.checkout;
 }, this);
 events['click ' + this.options.button.remove] = function(event) {
 event.stopPropagation();
 confirm({
 content: self.options.confirmMessage,
 actions: {
 confirm: function () {
 self._removeItem($(event.currentTarget));
 },
 always: function (event) {
 event.stopImmediatePropagation();
 }
 }
 });
 };
 events['keyup ' + this.options.item.qty] = function(event) {
 self._showItemButton($(event.target));
 };
 events['click ' + this.options.item.button] = function(event) {
 event.stopPropagation();
 self._updateItemQty($(event.currentTarget));
 };
 events['focusout ' + this.options.item.qty] = function(event) {
 self._validateQty($(event.currentTarget));
 };
 events['click .edit-icon'] = function (event) {
 event.stopPropagation();
 self._showOptions($(event.currentTarget));
 }
 this._on(this.element, events);
 //this._calcHeight();
 //this._isOverflowed();
 },
 /**
 * Add 'overflowed' class to minicart items wrapper element
 *
 * @private
 */
 _isOverflowed: function() {
 var list = $(this.options.minicart.list),
 cssOverflowClass = 'overflowed';
 if (this.scrollHeight > list.innerHeight()) {
 list.parent().addClass(cssOverflowClass);
 } else {
 list.parent().removeClass(cssOverflowClass);
 }
 },
 _showItemButton: function(elem) {
 var itemId = elem.data('cart-item');
 var itemQty = elem.data('item-qty');
 if (this._isValidQty(itemQty, elem.val())) {
 $('#cdz-update-cart-item-' + itemId).show('fade', 300);
 } else if (elem.val() == 0) {
 this._hideItemButton(elem);
 } else {
 this._hideItemButton(elem);
 }
 },
 /**
 * @param origin - origin qty. 'data-item-qty' attribute.
 * @param changed - new qty.
 * @returns {boolean}
 * @private
 */
 _isValidQty: function(origin, changed) {
 return (origin != changed)
 && (changed.length > 0)
 && (changed - 0 == changed)
 && (changed - 0 > 0);
 },
 /**
 * @param {Object} elem
 * @private
 */
 _validateQty: function(elem) {
 var itemQty = elem.data('item-qty');
 if (!this._isValidQty(itemQty, elem.val())) {
 elem.val(itemQty);
 }
 },
 _hideItemButton: function(elem) {
 var itemId = elem.data('cart-item');
 $('#cdz-update-cart-item-' + itemId).hide('fade', 300);
 },
 _updateItemQty: function(elem) {
 var itemId = elem.data('cart-item');
 this._ajax(this.options.url.update, {
 item_id: itemId,
 item_qty: $('#cdz-cart-item-' + itemId + '-qty').val()
 }, elem, this._updateItemQtyAfter);
 },
 /**
 * Update content after update qty
 *
 * @param elem
 */
 _updateItemQtyAfter: function(elem) {
 this._hideItemButton(elem);
 },
 _removeItem: function(elem) {
 var itemId = elem.data('cart-item');
 this._ajax(this.options.url.remove, {
 item_id: itemId
 }, elem, this._removeItemAfter);
 },
 /**
 * Update content after item remove
 *
 * @param elem
 * @param response
 * @private
 */
 _removeItemAfter: function(elem, response) {
 },
 /**
 * @param url - ajax url
 * @param data - post data for ajax call
 * @param elem - element that initiated the event
 * @param callback - callback method to execute after AJAX success
 */
 _ajax: function(url, data, elem, callback) {
 $.extend(data, {
 'form_key': $.mage.cookies.get('form_key')
 });
 $.ajax({
 url: url,
 data: data,
 type: 'post',
 dataType: 'json',
 context: this,
 beforeSend: function() {
 elem.attr('disabled', 'disabled');
 },
 complete: function() {
 elem.attr('disabled', null);
 }
 })
 .done(function(response) {
 if (response.success) {
 callback.call(this, elem, response);
 } else {
 var msg = response.error_message;
 if (msg) {
 alert({
 content: $.mage.__(msg)
 });
 }
 }
 })
 .fail(function(error) {
 console.log(JSON.stringify(error));
 });
 },
 _showOptions: function (elem) {
 var $elemTarget = elem.parent().parent();
 var $optionTarget = $elemTarget.find('.hover-sec');
 var $listItem = $elemTarget.parent();
 if ( $optionTarget.hasClass('show-options') ) {
 $optionTarget.removeClass('show-options');
 } else {
 $listItem.find('div.hover-sec.show-options').removeClass('show-options');
 $optionTarget.addClass('show-options');
 }
 },
 /**
 * Calculate height of minicart list
 *
 * @private
 */
 _calcHeight: function() {
 var self = this,
 height = 0,
 counter = this.options.maxItemsVisible,
 target = $(this.options.minicart.list);
 target.children().each(function () {
 var outerHeight = $(this).outerHeight();
 if (counter-- > 0) {
 height += outerHeight;
 }
 self.scrollHeight += outerHeight;
 });
 target.height(height);
 }
 });
 return $.mage.codazonSidebar;
});
asked Mar 21, 2023 at 10:01

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.