craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Trying to access array offset on value of type bool #26

Closed riccardolardi closed 3 years ago

riccardolardi commented 3 years ago

I'm getting this error once I try to edit an entry that has the field attached to it.

Could it be it's related to my Shopify account being still in Demo mode?

I can though fetch data using storefront API.

error
nmaier95 commented 3 years ago

Hi @riccardolardi, this sounds more like $productData['products'] is maybe empty. Did you create any products inside your shopify account? In addition, can you post a var_dump($productData['products'] because we might have to adjust the if condition to correctly handle an empty response.

riccardolardi commented 3 years ago

Hi @nmaier95 yes that's what I thought too but I do have a product online and it's set to published.

nmaier95 commented 3 years ago

May you provide a var_dump of your productData['products'] please? I'm trying to understand in which case it is not of type array... It always worked for me with my demo shopify accounts.

riccardolardi commented 3 years ago

@nmaier95 so $productsData is false and therefore $productsData['products'] errors with Trying to access array offset on value of type bool. Is there anything else I can log out to help you?

nmaier95 commented 3 years ago

Hmm, it is also possible that you either misspelled the api credentials inside the plugin settings or access permissions of the api key are not correct. Have you double checked those? Because if the API request returns false, I don't think it has something to do withe this plugins' code but rather with the API request itself. How I create my credentials:

  1. You'll need to log in to your shopify account
  2. Go to "admin" -> "apps" url: admin/apps
  3. Activate private apps. The link says something like "work with a developer on your shop"
  4. Create an app
  5. Grant access to storefront API + all product related checkboxes (for now, or just click all access rights...)

Did you do those steps? And used the credentials correctly?

nmaier95 commented 3 years ago

Besides that, I merged an pr #23 long time ago which solves throwing an error in case data is false. I just never released it. What it doesn't solve though is WHY it is false...

riccardolardi commented 3 years ago

@nmaier95 That was it. I had only granted permissions for the storefront API but not for Admin API. Thanks a lot for your help!

a-am commented 2 years ago

Craft CMS: 3.5.19.1 Shopify: 2.2.0 PHP: 8.0.13

We are experiencing this same issue. We have checked the Admin API settings and all of them are set correctly along with the Store Front API settings. I checked our error logs and we received this error:

429 Too Many Requests` response:
{"errors":"Exceeded 2 calls per second for api client. Reduce request rates to resume uninterrupted service."}

I am wondering if this is part of the issue where the request rate is exceeded and FALSE is returned because no products are returned thus causing the boolean error. Are the products cached to speed FieldType load?