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

[Bug]: Location Endpoint not working for PATCH #89

Open
andresrivero opened this issue Dec 13, 2024 · 1 comment
Open

[Bug]: Location Endpoint not working for PATCH #89

andresrivero opened this issue Dec 13, 2024 · 1 comment

Comments

@andresrivero
Copy link

andresrivero commented Dec 13, 2024

What happened?

Tried GET and CREATE but PATCH, no matter which of the required values are sent, it will not update. It finishes the response and returns the current location entry, but no changes. I can do PATCH requests on other endpoints like Orders. Tried changing from staff to all. Seems like something in the Transformer or the LocationRequest -> it's different from other API classes as it points to admin/requests/locationrequest.php, although it doesn't seem like that should matter as it has all the required data. Mostly was trying to use this so that I can disable or enable locations programatically.

Sample JSON I used that got a 200 response with the old unchanged data:

{
            "location_name": "Location 1",
            "location_email": "[email protected]",
            "location_address_1": "123 E Main St",
            "location_country_id": 223,
        "location_status": false,
        "options": {
            "auto_lat_lng": true
        }

 }

I'll come back to this, but wanted to document for myself as well. Also tried using 0 and 1 for location_status.

What did you expect to happen?

Expect that since a 200 response is returned, that the value would change if there was a new item in the JSON body of the PATCH
this is going to /api/locations/1

Version

3.x

What browser are you seeing the problem on?

No response

Relevant log output

No response

@andresrivero
Copy link
Author

Was doing testing and found that in ArtifactRepository.php, ~line 115, using this code, I was just testing if I could set the location_status. And I could, so something in $this->setModelAttributes($model, $attributes) or $this->setCustomerAwareAttributes($model) is not setting modelsToSave correctly, it's just saving it with whatever is in the DB so it ignores the PATCH body data. But you can see $attributes does hold the PATCH data.

$this->setModelAttributes($model, $attributes);
      
        $this->setCustomerAwareAttributes($model);
        if (!is_null($this->modelsToSave) && !empty($this->modelsToSave)) {
            if (isset($this->modelsToSave[0]->location_status) && isset($attributes['location_status'])) {
                $this->modelsToSave[0]->location_status = $attributes['location_status'];
              }
        } 

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

1 participant