![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/Checkout/view/frontend/web/js/view/cart/ |
/** * Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * Cnc * Radosław Stępień <[email protected]> <[email protected]> */ define([ 'jquery', 'ko', 'underscore', 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/action/select-shipping-method', 'Magento_Checkout/js/checkout-data' ], function ($, ko, _, quote, selectShippingMethodAction, checkoutData) { 'use strict'; return function (target) { return target.extend({ defaults: { template: 'Ecombricks_InventoryCheckout/cart/shipping-rates' }, sources: ko.observableArray([]), /** * Initialize observable * * @returns {Object} */ initObservable: function () { this._super(); this.shippingRates.subscribe(function (shippingRates) { this.sources([]); _.each(shippingRates, function (shippingRate) { var source = quote.getSource(shippingRate.source_code); if (source && this.sources.indexOf(source) === -1) { this.sources.push(source); } }, this); }, this); return this; }, /** * Get source shipping rates * * @param {String} sourceCode * @returns {Object[]} */ getSourceShippingRates: function (sourceCode) { return _.filter(this.shippingRates(), function (shippingRate) { return sourceCode === shippingRate.source_code; }); }, /** * Get source carriers * * @param {String} sourceCode * @returns {Object[]} */ getSourceCarriers: function (sourceCode) { var carriers = []; //KDC modification start: remove or apply the city field for shipping estimation var onlyPostcodeCountriesCodes = ['DZ', 'AS', 'AD', 'AR', 'AM', 'AU', 'AT', 'AZ', 'BD', 'BY', 'BE', 'BA', 'BR', 'BN', 'BG', 'KH', 'CA', 'IC', 'CN', 'CO', 'MP', 'HR', 'CU', 'CY', 'CZ', 'DK', 'EC', 'EE', 'FO', 'FI', 'FR', 'GF', 'GE', 'DE', 'XG', 'GR', 'GL', 'GP', 'GU', 'GG', 'HU', 'IS', 'IN', 'ID', 'IL', 'IT', 'JP', 'JE', 'KZ', 'KR', 'KV', 'KG', 'LV', 'LI', 'LT', 'LU', 'MG', 'MY', 'MV', 'MH', 'MQ', 'YT', 'MX', 'FM', 'XX', 'MD', 'MC', 'MN', 'ME', 'MA', 'NL', 'NC', 'NZ', 'MK', 'NO', 'PK', 'PW', 'PG', 'PH', 'PL', 'PT', 'PR', 'RE', 'RO', 'RU', 'SH', 'SM', 'RS', 'SG', 'SK', 'SI', 'ZA', 'ES', 'LK', 'XY', 'SZ', 'SE', 'CH', 'PF', 'TW', 'TJ', 'TH', 'TN', 'TR', 'TM', 'UA', 'GB', 'US', 'UZ', 'VA']; var selectedCountryId = $("select[name='country_id']").val(); if (onlyPostcodeCountriesCodes.includes(selectedCountryId)) { $("div[name='shippingAddress.city']").hide(); $("input[name='city']").val(''); } else { $("div[name='shippingAddress.city']").show(); } //KDC modification end _.each(this.getSourceShippingRates(sourceCode), function (shippingRate) { if (_.find(carriers, function (carrier) { return carrier.code === shippingRate.carrier_code; })) { return; } carriers.push({code: shippingRate.carrier_code, title: shippingRate.carrier_title}); }); return carriers; }, /** * Get source carrier shipping rates * * @param {String} sourceCode * @param {String} carrierCode * @returns {Object[]} */ getSourceCarrierShippingRates: function (sourceCode, carrierCode) { return _.filter(this.getSourceShippingRates(sourceCode), function (shippingRate) { return carrierCode === shippingRate.carrier_code; }); }, /** * Select shipping method * * @param {Object} shippingMethod * @returns {Boolean} */ selectShippingMethod: function (shippingMethod) { selectShippingMethodAction(shippingMethod); checkoutData.setSelectedSourceShippingRate(shippingMethod.source_code, shippingMethod.carrier_code + '_' + shippingMethod.method_code); return true; }, /** * Get selected source shipping method * * @param {String} sourceCode * @returns {String|null} */ getSelectedSourceShippingMethod: function (sourceCode) { var shippingMethod = quote.getSourceShippingMethod(sourceCode); if (!shippingMethod) { return null; } return shippingMethod.carrier_code + '_' + shippingMethod.method_code; } }); }; });