bumbummen99 / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
505 stars 234 forks source link

No cart instance information available on events #139

Closed ChrisThompsonTLDR closed 2 years ago

ChrisThompsonTLDR commented 2 years ago

The CartItem class doesn't know which cart instance it is a part of. This is an issue when, for example, you want to wire up the automatic application of tax rates to a CartItem:

Event::listen('cart.added', function (CartItem $cartItem) {
    if ($cartItem->model
        && $cartItem->model->taxable
        && !is_null(config('account.tax_rate'))
    ) {
        Cart::instance(???)->setTax($cartItem->rowId, config('account.tax_rate'));
    }
});
bumbummen99 commented 2 years ago

Could we not add the instance to the event instead of the item? Otherwise we would have to change it if we want to add it to another isntance?

ChrisThompsonTLDR commented 2 years ago

Sure, but then you'd have to change all the events and listeners, right?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

ChrisThompsonTLDR commented 2 years ago

@bumbummen99 could we get a bump on this? We're having to maintain a fork of the repo to keep this working for us.