protected function addRow($id, $name, $qty, $price, array $attributes = [])
    {
        if (!is_numeric($qty) || $qty < 1) {
            throw new Exception('Invalid quantity.');
        }

        if (!is_numeric($price) || $price < 0) {
            throw new Exception('Invalid price.');
        }

        $cart = $this->getCart();

        $rawId = $this->generateRawId($id, $attributes);

        if ($row = $cart->get($rawId)) {
            $row = $this->updateQty($rawId, $row->qty + $qty);
        } else {
            $row = $this->insertRow($rawId, $id, $name, $qty, $price, $attributes);
        }

        return $row;
    }
protected function addRow($id, $name, $qty, $price, array $attributes = [])
    {
        if (!is_numeric($qty) || $qty < 1) {
            throw new Exception('Invalid quantity.');
        }

        if (!is_numeric($price) || $price < 0) {
            throw new Exception('Invalid price.');
        }

        $cart = $this->getCart();

        $rawId = $this->generateRawId($id, $attributes);

        if ($row = $cart->get($rawId)) {
            $row = $this->updateQty($rawId, $row->qty + $qty);
        } else {
            $row = $this->insertRow($rawId, $id, $name, $qty, $price, $attributes);
        }

        return $row;
    }
protected function addRow ( $ id , $ name , $ qty , $ price , array $ attributes = [ ] ) { if ( ! is_numeric ( $ qty ) || $ qty < 1 ) { throw new Exception ( 'Invalid quantity.' ) ; } if ( ! is_numeric ( $ price ) || $ price < 0 ) { throw new Exception ( 'Invalid price.' ) ; } $ cart = $ this -> getCart ( ) ; $ rawId = $ this -> generateRawId ( $ id , $ attributes ) ; if ( $ row = $ cart -> get ( $ rawId ) ) { $ row = $ this -> updateQty ( $ rawId , $ row -> qty + $ qty ) ; } else { $ row = $ this -> insertRow ( $ rawId , $ id , $ name , $ qty , $ price , $ attributes ) ; } return $ row ; }
Add row to the cart.

@param string $id         Unique ID of the item
@param string $name       Name of the item
@param int    $qty        Item qty to add to the cart
@param float  $price      Price of one item
@param array  $attributes Array of additional options, such as 'size' or 'color'

@return string
Add row to the cart .