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

Cache Order Statuses in the component #1497

Closed
Anubarak opened this issue Jun 10, 2020 · 1 comment
Closed

Cache Order Statuses in the component #1497

Anubarak opened this issue Jun 10, 2020 · 1 comment
Assignees
Labels
💡 enhancement Ideas and suggestions

Comments

@Anubarak
Copy link

What are you trying to do?
I would like to fetch many orders and their statuses at once, so it would be nice if you could cache order statuses in your component

What's your proposed solution?
Cache your Order statuses, all you need to do is to include a $this->_orderStatuses = $orderStatuses here
https://github.com/craftcms/commerce/blob/develop/src/services/OrderStatuses.php#L90

    public function getAllOrderStatuses($withTrashed = false): array
    {
        // Get the caches items if we have them cached, and the request is for non-trashed items
        if ($this->_orderStatuses !== null) {
            return $this->_orderStatuses;
        }

        $results = $this->_createOrderStatusesQuery($withTrashed)->all();
        $orderStatuses = [];

        foreach ($results as $row) {
            $orderStatuses[] = new OrderStatus($row);
        }

        $this->_orderStatuses = $orderStatuses // new line

        return $orderStatuses;
    }
@Anubarak Anubarak added New 💡 enhancement Ideas and suggestions labels Jun 10, 2020
@lukeholder lukeholder self-assigned this Jun 17, 2020
@lukeholder lukeholder added bug and removed New 💡 enhancement Ideas and suggestions labels Jun 17, 2020
@lukeholder
Copy link
Member

Thanks for reporting that! I’ve just fixed it for the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-develop#97c1142d85d3f0fef455e6822f11508f31d447c0 as 3.1.8",
  "...": "..."
}

Then run composer update.

@lukeholder lukeholder added 💡 enhancement Ideas and suggestions and removed bug labels Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement Ideas and suggestions
Projects
None yet
Development

No branches or pull requests

2 participants