Skip to content

Docs: fix example usage of addLines#1429

Merged
alecritson merged 2 commits intolunarphp:0.7from
se09deluca:docs/fix-cartsession-addlines
Jan 11, 2024
Merged

Docs: fix example usage of addLines#1429
alecritson merged 2 commits intolunarphp:0.7from
se09deluca:docs/fix-cartsession-addlines

Conversation

@se09deluca
Copy link
Contributor

@se09deluca se09deluca commented Dec 29, 2023

Fixes a typo in the example of CartSession::addLines usage.

The implementation of addLines currently expects a purchasable instance as below:

public function add(Purchasable $purchasable, int $quantity = 1, array $meta = [], bool $refresh = true): Cart
{
    foreach (config('lunar.cart.validators.add_to_cart', []) as $action) {
        // Throws a validation exception?
        app($action)->using(
            cart: $this,
            purchasable: $purchasable,
            quantity: $quantity,
            meta: $meta
        )->validate();
    }

    return app(
        config('lunar.cart.actions.add_to_cart', AddOrUpdatePurchasable::class)
    )->execute($this, $purchasable, $quantity, $meta)
        ->then(fn () => $refresh ? $this->refresh()->calculate() : $this);
}

public function addLines(iterable $lines): Cart
{
    DB::transaction(function () use ($lines) {
        collect($lines)->each(function ($line) {
            $this->add(
                purchasable: $line['purchasable'],
                quantity: $line['quantity'],
                meta: (array) ($line['meta'] ?? null),
                refresh: false
            );
        });
    });

    return $this->refresh()->calculate();
}

Fixes as typo in the example of CartSession::addLines usage.
@vercel
Copy link

vercel bot commented Dec 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 11, 2024 9:56am

@se09deluca se09deluca changed the title docs: fix example usage of addLines Docs: fix example usage of addLines Dec 31, 2023
@glennjacobs glennjacobs added the documentation Improvements or additions to documentation label Jan 3, 2024
@glennjacobs glennjacobs added this to the v0.7 milestone Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants