magento_react_native icon indicating copy to clipboard operation
magento_react_native copied to clipboard

No such entity with customerId = 2

Open irnjunior opened this issue 4 years ago • 6 comments
trafficstars

I did the installation and the application works normally. I registered a user through the application normally.

However, when I try to add a product to the cart, the following message appears: "The consumer isn't authorized to access resource."

When I click on the cart icon, the following message is displayed: "No such entity with customerId = 2"

I'm using Magento 2.4

irnjunior avatar Dec 03 '20 12:12 irnjunior

Hello @irnjunior sorry for replying bit late, but can we discuss about the issue, if it's possible

sanjeevyadavIT avatar Feb 06 '21 17:02 sanjeevyadavIT

Hi. It's all right. I would like, if possible. Thanks.

irnjunior avatar Feb 08 '21 11:02 irnjunior

Regarding customer isn't authorized to access the resources, did you follow all the instructions explained here in wiki

especially these two

  1. Set available APIs, to All, while setting up integration (Point no 4. in wiki)

  2. Set expiry time for customer token very big, as explained here

4. Increase customer session expiry time

By default, customer token generated when user login is valid for 1 hour. You can change these values from Admin by selecting Stores > Settings > Configuration > Services > OAuth > Access Token Expiration.

Set it to 168 hours(7 days)

sanjeevyadavIT avatar Feb 08 '21 14:02 sanjeevyadavIT

I followed all the procedures correctly.

I can create and login with the client normally through the application. I add a product to the shopping cart and at that moment the message "Current Customer Does Not Have An Active Cart" is displayed. Then, when you click on the cart icon a red message is displayed "No such entity with customerId = 2"

If I create a client account directly through the browser, these errors will not appear. These errors appear only when I create an account through the app.

Any idea how to fix this?

irnjunior avatar Feb 08 '21 17:02 irnjunior

Ok, I understand, let me test tomorrow with my own local magento setup. Will let you know

sanjeevyadavIT avatar Feb 08 '21 17:02 sanjeevyadavIT

hi @irnjunior I tested it with my local magento 2.4 setup, and created new account, at my end, I am able to add products to cart.

See, one you log in, customer cart is fetched, but since, a new user, doesn't have customer cart, an error is thrown, so in app, it is handled to request quote cart, which create a cart for customer, and again customer cart is fetched.

cartSagas.js

// wroker saga: Add description
function* getCustomerCart() {
  try {
    yield put({ type: MAGENTO.CUSTOMER_CART_LOADING });
    const cart = yield call({
      content: magento,
      fn: magento.customer.getCustomerCart,
    });
    yield put({ type: MAGENTO.CUSTOMER_CART_SUCCESS, payload: { cart } });
  } catch (error) {
    yield put({
      type: MAGENTO.CUSTOMER_CART_FAILURE,
      payload: { errorMessage: error.message },
    });
    if (error.message.startsWith('No such entity with')) {
      yield put({ type: MAGENTO.CREATE_QUOTE_ID_REQUEST }); // <============== look here
    }
  }
}

This is like a hack, and possibly the problem is occurring here.

Follow these steps

  1. Open app in debug mode, you will be able to see logs in developer console of chrome
  2. Create a new account from app
  3. It will take you to login screen
  4. Clear the console of previous log
  5. Enter login credentials, and hit login button
  6. In console, you will see "MAGENTO_CUSTOMER_CART_FAILURE" action, see if ""MAGENTO_CREATE_QUOTE_ID_REQUEST" action is dispatched or not

Your console should look something like this, in this order for new account first time login

Screenshot from 2021-02-10 09-43-27

sanjeevyadavIT avatar Feb 10 '21 04:02 sanjeevyadavIT