slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 47 forks source link

ProductManager::findAll is broken after updating to v2.5.0+ #84

Closed netpok closed 3 years ago

netpok commented 4 years ago

Affected versions: v2.5.0+

We are using this package to get all products from a Shopify shop with the $shopifyClient->getProductManager()->findAll() chain, after updating to v2.5.0 or higher all attributes of the returned products are null.

image

scottlaurent commented 3 years ago

Was there ever a resolution on this? Seeing the same issue here and this seems like a serious bug. I'm completely stuck here the products I pull from the paginator do not have an id.

In our case, all attributes are there, except for ID for the root (product) and all children (orders/lines/customers/etc).

This appears to be in dev-master and 2.5.x -- I downgraded to 2.4.x and this is not occurring there.

netpok commented 3 years ago

I changed the constraints to 2.4.* and probably will remove this package later in favor of simple http queries since I also need to support some graphql queries.

slince commented 3 years ago

Sorry, I haven't reproduced the problem so far; I think you should provide more detailed information.

 composer show slince/shopify-api-php
 composer show symfony/yaml
 composer show jms/serializer
slince commented 3 years ago

@netpok Please feel free to remove this package

lars-29palms commented 3 years ago

Same for me after updating to ^2.5 Although I noticed this with a call to the order manager like so:

        $orders = $this->order_manager->findAll(['status' => 'any', 'fields' => 'id']);

        foreach($orders as $order)
        {
            $id = $order->getId();
            $this->order_manager->update($id, $data);
        }

The order_manager->update call fails since the $id is empty and Shopify then returns a HTTP 406 error. Noticed the same with the ProductManager->findAll() method which throws a NotAcceptableException in jms\serializer\src\JsonDeserializationVisitor.php on line 173

For now I'm reverting back to ^2.4 which is working fine. I had just hoped for an update of the API version in the client, which still references 2019-10

Thanks for your work guys!

slince commented 3 years ago

Hello, can you try again using 2.5.2, we realized that it may be caused by the different versions of jms/serializer

lars-29palms commented 3 years ago

This seems to have fixed the afore mentioned issue for me, thank you!

lars-29palms commented 3 years ago

Hey, sorry for re-opening this but I couldn't get v2.6.0 to work either. Maybe this is of interest to others dealing with the same issue:

After updating to v2.6 I noticed that jms/serializer was still set to v3.11 in my composer.lock although slince/shopify requires ^3.8. I then explicitly required ^3.8 using composer. But still, all manager calls (order, product, customer) to "findAll" and "paginate" return empty objects (all variables are NULL)

I'm reverting to v2.4 for now and will give v3 a try soon 👍

About my last reply 16 days ago: Sorry about that, I think I might have confused repositories and reported this as fixed by mistake :/

jstoone commented 3 years ago

Preface

@lars-29palms I've tried reproducing your error, without much luck.

Although I while doing so, I did get a hunch that the results you're experiencing could be the effects of juggling between versions of this package, as well as the jms/serializer. Meaning that you have two moving parts that are causing conflicts:

  1. The yaml configs: Defining the serialization schema
  2. The metadata cache: Generated and reused by the serializer when hydrating/extracting models

Story time!

So, as a means to spare our dear serializer the soul-crushing job of reading and parsing through the YAML file(s) for each time it either hydrates or extracts given model(s), we've given it a temporary folder (metaCacheDir) in which it can store it's intermediate calculations, for use 'till next time a model of same type needs massaging into or from an array.

Since both the schema - the formulae used in the intermediate calculations - and the serializer used to read those temporary intermediate sticky-notes have changed, it's not a surprice to us that the calculations are wrong.

Conclusion

OKAY MR. STORY DUDE, BUT HOW DO I SOLVE MY PROBLEM??

I actually don't know. But, I would suggest to locate the temporary folder (metaCacheDir) that you kindly told your Slince/Shopify/Client-clas it could use for cache storage, and delete both the annotations and metadata folders.

Now, within your sparklingly newly composer update slince/shopify-api-php-ed project, go ahead and try fetching some products. Without looking, go ahead and assert that the two (annotations and metatdata) folders have been re-created.

OKOK. Now look on the response from your $client->getProductsManager()->findAll()-call. Is it good news, or bad news?


P.S: If you're using any CI/CD pipelines remember to make this a part of your deployment strategy together with e.g. existing clearing of route/config/view caches.

lars-29palms commented 3 years ago

@jstoone Hey Jakob, thanks so much for this! I totally forgot about the cache... Just tested v2.6 after clearing the cache and it's working perfectly. Problem solved!