Overtrue\LaravelShoppingCart\Cart::addRow PHP 메소드

addRow() 보호된 메소드

Add row to the cart.
protected addRow ( string $id, string $name, integer $qty, float $price, array $attributes = [] ) : string
$id string Unique ID of the item
$name string Name of the item
$qty integer Item qty to add to the cart
$price float Price of one item
$attributes array Array of additional options, such as 'size' or 'color'
리턴 string
    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;
    }