I have created some steps between shipping and Payment form and add some field between then and applied ajax on that but i have facing an issue for not logged in user it will gave an error of 401 and redirect on login page on saving first field.
Will anyone help me how to successfully placed order without login.
i'm using Rest Api to save data in magento 2
<route url="/V1/carts/mine/set-save-data" method="PUT">
<service class="Vendor\Module\Api\SaveNoteManagementInterface" method="saveSimpleNote"/>
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="cartId" force="true">%cart_id%</parameter>
</data>
</route>
This is my webapi.xml code it works properly for logged in user but for guest user it doesn't work and give 401 redirection. If you want i will share my full code for saving the data.
-
Can you share the code what you done?Dhiren Vasoya– Dhiren Vasoya2020年08月09日 16:32:51 +00:00Commented Aug 9, 2020 at 16:32
-
I have updated my question please check @DhirenVasoyaPrits– Prits2020年08月09日 17:01:50 +00:00Commented Aug 9, 2020 at 17:01
-
Updated my code please check tell me anything needed.Prits– Prits2020年08月11日 16:59:41 +00:00Commented Aug 11, 2020 at 16:59
1 Answer 1
It's been a while but it may be helpful for others coming accross this.
Your webapi.xml declares a requirement for a <resource ref="self" />
which limits access to logged in customers. If you replace that with <resource ref="anonymous" /> it will allow both customers and guest users.
As the guest cart may need slightly different backend code to handle the request, you may wish to declare a separate routewith its own url and and have that one use <resource ref="anonymous" />