Skip to content

Fixing unstructured data without count attribute #14

Description

@orangutangle

The Lightspeed Retail API (irritatingly) returns results as a single array if count = 1, and a multi-dimensional array if count > 1. The following code normalises this in ApiClient.php:

        // fix Lightspeed unstructured way of returning an array when a multi dimensional array is expected
        if (isset($response['@attributes']['count']) && $response['@attributes']['count'] === 1) {
            $response[$resource] = [$response[$resource]];
        }

However, since v3.0 (?), the count attribute is not returned with a set of results, so this test does not work. Perhaps this?

        // fix Lightspeed unstructured way of returning an array when a multi dimensional array is expected
        if (!is_array($response[$resource][array_key_first($response[$resource])])) {
            $response[$resource] = [$response[$resource]];
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions