src/Cart/ShoppingCart.php
public function add(Buyable $buyable, $quantity = 1, $filter = [])
    {
        $order = $this->findOrMake();

        // If an extension throws an exception, error out
        try {
            $order->extend('beforeAdd', $buyable, $quantity, $filter);
        } catch (Exception $exception) {
            return $this->error($exception->getMessage());
        }

        if (!$buyable) {
            return $this->error(_t(__CLASS__ . '.ProductNotFound', 'Product not found.'));
        }

        $item = $this->findOrMakeItem($buyable, $quantity, $filter);
        if (!$item) {
            return false;
        }
        if (!$item->_brandnew) {
            $item->Quantity += $quantity;
        } else {
            $item->Quantity = $quantity;
        }

        // If an extension throws an exception, error out
        try {
            $order->extend('afterAdd', $item, $buyable, $quantity, $filter);
        } catch (Exception $exception) {
            return $this->error($exception->getMessage());
        }

        $item->write();
        $this->message(_t(__CLASS__ . '.ItemAdded', 'Item has been added successfully.'));

        return $item;
    }
public function add(Buyable $buyable, $quantity = 1, $filter = [])
    {
        $order = $this->findOrMake();

        // If an extension throws an exception, error out
        try {
            $order->extend('beforeAdd', $buyable, $quantity, $filter);
        } catch (Exception $exception) {
            return $this->error($exception->getMessage());
        }

        if (!$buyable) {
            return $this->error(_t(__CLASS__ . '.ProductNotFound', 'Product not found.'));
        }

        $item = $this->findOrMakeItem($buyable, $quantity, $filter);
        if (!$item) {
            return false;
        }
        if (!$item->_brandnew) {
            $item->Quantity += $quantity;
        } else {
            $item->Quantity = $quantity;
        }

        // If an extension throws an exception, error out
        try {
            $order->extend('afterAdd', $item, $buyable, $quantity, $filter);
        } catch (Exception $exception) {
            return $this->error($exception->getMessage());
        }

        $item->write();
        $this->message(_t(__CLASS__ . '.ItemAdded', 'Item has been added successfully.'));

        return $item;
    }
Adds an item to the cart

@param Buyable $buyable
@param int     $quantity
@param array   $filter

@return boolean|OrderItem false or the new/existing item