Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return created/updated objects #175

Open
1 of 2 tasks
MagicLegend opened this issue Apr 19, 2022 · 35 comments
Open
1 of 2 tasks

Return created/updated objects #175

MagicLegend opened this issue Apr 19, 2022 · 35 comments
Assignees

Comments

@MagicLegend
Copy link

MagicLegend commented Apr 19, 2022

Overview

The API itself will already return the full object if you do a create/update operation. However, the library swallows this response here:
https://github.com/Shopify/shopify-php-api/blob/0556edf274ceb83346533bd22b662d7622e58c66/src/Rest/Base.php#L60-L74

Solution

Adding return $response->getDecodedBody(); at the end of the function should suffice. Note that the saveAndUpdate function would also need to be updated, with return $this->save(true);. Implementation can be found in my fork: MagicLegend@d43bc94

Type

  • New feature
  • Changes to existing features

Motivation

What inspired this feature request? What problems were you facing?

I would like to verify the saved object myself, without needing to query the API again for data that was already returned in the first place. This also allows immediate access to the ID of the newly created object.

@shota
Copy link

shota commented May 29, 2022

+1
I don't know why this has NOT been implemented yet.

@shota
Copy link

shota commented May 29, 2022

I have created PR for this. This is what should be (save return response, saveAndUpdate update object itself)
#185

@Zelfapp
Copy link

Zelfapp commented Jul 28, 2022

This is a pretty serious issues that the Base.php save() method returns void. E.g. the rest api order docs incorrectly state there will be a response. Getting the response with the new order's id is mission critical for our use case, but I don't see a way to access the updated object.

image

Any contributors able to post a workaround until this is resolved?

@MagicLegend
Copy link
Author

MagicLegend commented Jul 29, 2022

@Zelfapp Yeah, as stated in the original message, I have fixed this (along with other improvements to the library) in my fork: MagicLegend@d43bc94

@Zelfapp
Copy link

Zelfapp commented Jul 29, 2022

@MagicLegend I saw your PR. This library has too many issues for a private app at this point and feels too hacky. It has great potential though.

For the sake of anyone else battling this alpha lib for a private app, likely you're better off simply using guzzle to make REST api endpoint requests. E.g. in just few lines of code you can dynamically pass in any endpoint and payload.

Again, this is a great lib, but I would not classify as ready for production.

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

/// Guzzle client
$client = new Client();
$request = new Request(
    'GET',
    "https://$this->shop/admin/api/2022-07/$endpoint",
    [
        'X-Shopify-Access-Token' => $this->permanentAccessToken,
    ],
    $endpointParams['payload'] ?? null,
);
$response = $client->sendAsync($request)->wait();
$response = $response->getBody();

@MagicLegend
Copy link
Author

I respectfully disagree, and we have my fork running in production right now. It works fine, it just has some quirks that Shopify is not allocating resources to to solve. I prefer using a library that's providing typing over doing it manually in Guzzle, but both will of course work fine.

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Sep 28, 2022
@MagicLegend
Copy link
Author

Still waiting on Shopify...

@github-actions github-actions bot removed the Stale label Sep 29, 2022
@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Nov 29, 2022
@MagicLegend
Copy link
Author

Still waiting on Shopify...

@github-actions github-actions bot removed the Stale label Nov 30, 2022
@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Jan 30, 2023
@MagicLegend
Copy link
Author

Still waiting on Shopify...

@github-actions github-actions bot removed the Stale label Jan 31, 2023
@brrrm
Copy link

brrrm commented Jan 31, 2023

I fully agree on this issue. I would like to see PR #185 to be committed.

@brrrm
Copy link

brrrm commented Jan 31, 2023

On second thought. When you do for instance:


$product = new Product($session);
$product->title = "my awesome product"

echo $product->id // NULL as it's a fresh unsaved product

// now we save it and set the param $updateObject to true
$product->save($updateObject = true);

echo $product->id // 1234567876 !!!!
// our $product object has been replaced with the object from the response.

@MagicLegend
Copy link
Author

@brrrm Well, you don't pass $updateObject if that's not what you intended to do, so the save() call will return the updated entity instead of overwriting the existing entity.

@brrrm
Copy link

brrrm commented Feb 1, 2023

the param $updateObject is not about updating an existing entity or creating a new entity. All it does is update the Object with the returned entity from Shopify's response. Or am I misunderstanding what you mean?

if ($updateObject) {
   $body = $response->getDecodedBody();
   self::createInstance($body[$this->getJsonBodyName()], $this->session, $this);
}

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Apr 3, 2023
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Apr 4, 2023
@github-actions
Copy link

github-actions bot commented Jun 3, 2023

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Jun 3, 2023
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Jun 6, 2023
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Aug 6, 2023
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Oct 8, 2023

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Oct 8, 2023
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@robthompsonweb
Copy link

FYI for anyone still struggling with this, instead of calling just save(), use saveAndUpdate() and then the original item is populated.

$newFulfillmentServiceResponse = new ShopifyFulfillmentService($session); $newFulfillmentServiceResponse->saveAndUpdate(); $id = $newFulfillmentServiceResponse->id; //this is now populated by using saveAndUpdate over save

@github-actions github-actions bot removed the Stale label Oct 10, 2023
Copy link

github-actions bot commented Dec 9, 2023

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Dec 9, 2023
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Dec 11, 2023
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Feb 10, 2024
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Feb 14, 2024
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Apr 14, 2024
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Apr 16, 2024
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Jun 15, 2024
@MagicLegend
Copy link
Author

Yeah, and why is it stale bot? Because Shopify doesn't reply ;)

@github-actions github-actions bot removed the Stale label Jun 18, 2024
@paulomarg
Copy link
Contributor

Hey folks, thanks for your patience here. We've removed the stalebot from this repo, and I'm going to add this issue to our tracking.

Once again, thank you for your patience!

@MagicLegend
Copy link
Author

No worries. You can find an implementation of this issue in my fork: MagicLegend@d43bc94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants