Spamworldpro Mini Shell
Spamworldpro


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/model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Cnc/Checkout/view/frontend/web/js/model/shipping-service-mixin.js
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Ɓukasz Wojciechowski <[email protected]>
 * @copyright Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com)
 */

define([
    'jquery',
    'mage/utils/wrapper',
    'underscore',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/action/select-shipping-method',
    'Magento_Checkout/js/checkout-data',
    'Magento_Checkout/js/model/cart/totals-processor/default'
], function (
    $,
    wrapper,
    _,
    quote,
    selectShippingMethodAction,
    checkoutData,
    totalsDefaultProvider
) {
    'use strict';

    return function (target) {
        var setShippingRates = wrapper.wrap(
            target.setShippingRates,
            function (_super, ratesData) {
                var sourceCodes = ['cnc_fr', 'cnc_usa'];
                if (!checkoutData.getSelectedShippingRate() && _.size(ratesData) > 1) {
                    var self = this;
                    sourceCodes.forEach(function(code){
                        var method = self.getMethod(ratesData, code);
                        if (!_.isUndefined(method)) {
                            selectShippingMethodAction(method);
                            totalsDefaultProvider.estimateTotals(quote.shippingAddress());
                        }
                    });
                }

                return _super(ratesData);
            }
        );

        return _.extend(target, {
            setShippingRates: setShippingRates,

            /**
             * @param availableMethods
             * @param code
             * @returns {*}
             */
            getMethod: function (availableMethods, code) {
                var preselected = this.getPreselectedMethod(code),
                    self = this;
                var matchedMethod;
                if (!_.isUndefined(preselected)) {
                    matchedMethod = availableMethods.find(function (method) {
                        return self.getMethodCode(method) === preselected && self.getMethodSource(method) === code;
                    });
                }

                return matchedMethod;
            },

            /**
             * @return {String|undefined}
             */
            getPreselectedMethod: function (store) {
                return window.checkoutConfig.preselected_shipping_method[store];
            },

            /**
             * @param  {Object} method
             * @return {String}
             */
            getMethodCode: function (method) {
                return method.carrier_code + '_' + method.method_code;
            },

            /**
             * @param method
             * @returns {*}
             */
            getMethodSource: function (method) {
                return method.source_code;
            }
        })
    };
});

Spamworldpro Mini