nshah143
nshah143

Reputation: 559

Magento 2 wrong base url on ajax call on checkout page

I have upgraded the Magento version to 2.3.7. After that, I have a strange issue on the checkout page that when it calls ajax function the URL is been wrongly generated. Previously it was like

/rest/default/V1/guest-carts/AC72N37Vmo3uGMIXEVQfIDt1ubuZLJws/estimate-shipping-methods

but after upgrading Magento version now it's

/checkout/undefinedrest/default/V1/guest-carts/AC72N37Vmo3uGMIXEVQfIDt1ubuZLJws/estimate-shipping-methods

Not sure from where this undefined gets added within the url ??

Research Notes: -

The secure & unsecure base url are correctly setup. I checked it again

Also i navigated to the file from where this ajax call is generated , the file is vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js

enter image description here

Here the storage.post is from the ajax call is generated and it has serviceurl & payload as arguments.

in getRates function - if we console.log "serviceUrl" then it shows the below url

rest/default/V1/guest-carts/FsS4QvllSq1vpuxZuC8ycQa0VRMOcQCy/estimate-shipping-methods

which seem to be correct, storage.post() function takes this as an argument and ajax request is called which then gets into the .fail() function

so what i think is that the problem is where the front part of the url gets added to it for making the ajax call that is http://sitename.local/checkout/undefined ---> and here somehow the undefined gets added which breaks the whole url

The same issue is encountered by other users also but no solution is available yet.

https://magento.stackexchange.com/questions/256273/undefined-rest-api-checkout-cart https://community.magento.com/t5/Magento-2-x-Programming/Magento2-Wrong-base-url-on-ajax-call/td-p/435435

Can anyone help me out from this?

Upvotes: 2

Views: 990

Answers (1)

nshah143
nshah143

Reputation: 559

I am answering my own question as i was able to fix the issue myself.

I am not sure if this solution would be a general solution to everyone facing similar issue but as in my case it helped me fix the issue , so it may guide others facing similar issue , if the solution isn`t 100% accurate in their scenario.

So in my project i had a file as

app/design/frontend/Birdbrain/default/Magento_Theme/templates/page/js/require_js.phtml

which had the following code inside it

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<script>
    var require = {
        "baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
    };
</script>

After removing this file from the source, the issue explained in the question above was fixed and no other issues arised by removing it.

Thoughts :- As i checked in my version control system , i found that this file was added in 2017 and since then no changes were done in it, so after upgrading the magento version to 2.3.x , it somehow conflicted with some latest code and was no longer meaningful and so removing it fixed the issue , atleast for me.

Upvotes: 0

Related Questions