Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.68k stars 1.73k forks source link

Updating options makes rowId change followingly? #536

Open minhtu-cloudtek opened 5 years ago

minhtu-cloudtek commented 5 years ago

Hi, I create a controller method to update my cart row.

It functions normally if I update only qty. If I update options, the rowId of that row changes as follows. I found that annoying and I have to refresh all the cart data in my view so that I can continue to update the cart.

Is there a way for me to update options of row without changing the rowId?

bumbummen99 commented 5 years ago

The row id is the id of your item + options and allows to merge items with the same type and options. This is per design, you would have to implement a different solution to achieve what you want.

myurtsev commented 4 years ago

@minhtu-cloudtek You could disable line 216 in CartItem.php to achieve what you want.

// $this->rowId = $this->generateRowId($this->id, $this->options->all());

/**
     * Update the cart item from an array.
     *
     * @param array $attributes
     * @return void
     */
    public function updateFromArray(array $attributes)
    {
        $this->id       = array_get($attributes, 'id', $this->id);
        $this->qty      = array_get($attributes, 'qty', $this->qty);
        $this->name     = array_get($attributes, 'name', $this->name);
        $this->price    = array_get($attributes, 'price', $this->price);
        $this->priceTax = $this->price + $this->tax;
        $this->options  = new CartItemOptions(array_get($attributes, 'options', $this->options));

        // $this->rowId = $this->generateRowId($this->id, $this->options->all());
    };
minhtu-cloudtek commented 4 years ago

Thanks for your reply. I've updated my Laravel app to 6. And this package is no longer compatible. Do you have plan for Crinsane/LaravelShoppingcart for Laravel 6?

bumbummen99 commented 4 years ago

@minhtu-cloudtek there are many forks of this package, some just keeping it compatible to the latest Laravel releases and some building upon the existing codebase. Except of those there is no version for L6+.