Adds an item to the cart.

@param Illuminate\Database\Eloquent\Model
@param int Quantity
@return array
339384
public function add($entity, $quantity)
    {
        if ($this->itemExists($entity)) {
            $cartItemIndex = $this->items->search($this->cartItemsCheck($entity));

            return $this->incrementQuantityAt($cartItemIndex, $quantity);
        }

        $this->items->push(CartItem::createFrom($entity, $quantity));

        event(new CartItemAdded($entity));

        return $this->cartUpdates($isNewItem = true);
    }
426965
public function incrementStockCount(string $productNumber, int $amount) : array
    {
        Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0');

        return $this->incrementOrDecrementStockCount($productNumber, abs($amount));
    }
502372
public function moveItemsTo(Cart $cart){

        \DB::transaction(function () use(&$cart){
            $current_items = $cart->items()->pluck('product_id');
            $items_to_move = $this->items()->whereNotIn('product_id', $current_items->toArray())->get();
            if($items_to_move->count() === 0){
                return;
            }
            $this->items()->whereNotIn('product_id', $current_items->toArray())->update([
                'cart_id' => $cart->id
            ]);
            foreach($items_to_move as $item) {
                $this->item_count -= $item->quantity;
                $this->total_price -= $item->getPrice();
                $cart->item_count += $item->quantity;
                $cart->total_price += $item->getPrice();
            }
            $this->relations = [];
            $cart->relations = [];
            $this->save();
            $cart->save();
        });
        return $cart;
    }
792863
public function resolve(CartItem $item, Request $request)
    {
        
        $productId = $request->query->get('id');
        $itemForm = $request->request->get('cart_item_simple');

        $productRepository = $this->manager->getRepository('EcommerceBundle:Product');
        if (!$productId || !$product = $productRepository->find($productId)) {
            // no product id given, or product not found
            throw new \Exception('Requested product was not found');
        }

        // assign the product and quantity to the item
        $item->setProduct($product);
        $item->setQuantity(intval($itemForm['quantity']));

        // calculate item price adding the special charge
        $price = $product->getPrice();
        if ($this->specialPercentageCharge > 0) {
            $price += $price * ($this->specialPercentageCharge / 100);
        }
        $item->setUnitPrice(intval($price));

        return $item;
    }
44549
public function addCartItem($cartId, $cartItem)
    {
        $cartItem = $this->arraySnakeCase($cartItem);

        $cartItem['cart_id'] = $cartId;
        CartItem::create($cartItem);
    }
1336291
public function add($model)
    {
        if (is_array($model)) {
            $this->collection[] = new MarketModel($model);
        } elseif ($model instanceof MarketModel) {
            $this->collection[] = $model;
        }

        return $this;
    }
817305
public function incrementQuantityAt($cartItemIndex, $quantity = 1)
    {
        $this->existenceCheckFor($cartItemIndex);

        $this->items[$cartItemIndex]->quantity += $quantity;

        $this->cartDriver->setCartItemQuantity(
            $this->items[$cartItemIndex]->id,
            $this->items[$cartItemIndex]->quantity
        );

        return $this->cartUpdates();
    }
375356
public function items($count = false)
    {
        $this->query = $this->model->newQuery();

        return $this->query($count);
    }
72417
public function addItem($id, $name = null, $type = null, $qty = 1, Money $price = null, $uri = null, array $options = [])
    {
        $cartItem = CartItem::fromAttributes($id, $name, $type, $price, $uri, $options);

        return $this->addItemToCart($cartItem, $qty);
    }
74195
public static function create($quantity, $productCode, $description, $amount, $vat, $currency = "EUR") {
        $item = new LineItem;
        $item->quantity = $quantity;
        $item->productCode = $productCode;
        $item->description = $description;
        $item->amount = $amount;
        $item->vat = $vat;
        $item->currency = $currency;
        return $item;
    }
311405
public function updateProductQuantity(Product $product, $quantity)
    {
        $lineItem = $this->getLineItemForProduct($product);

        // Check if there is enough product available
        if ($quantity > $product->getQuantityAvailable())
        {
            throw new \Exception('Not enough product available');
        }

        // Don't remove more than is in cart
        if ($quantity < 0)
        {
            throw new \Exception('Cannot have negative quantity');
        }

        // Update quantity
        $lineItem->setQuantity($quantity);

        // Whenever we add new items, we update the price to the most recent
        $lineItem->setPrice($product->getPrice());

        // Update Order totals
        $this->updateTotals();

        return $lineItem;
    }
370107
public function addItem($product, $quantity, $detail, $price)
    {
        $item = new stdClass();
        $item->product = $product;
        $item->quantity = $quantity;
        $item->detail = $detail;
        $item->price = $this->convertAmount($price);

        $this->data->items[] = $item;

        return $this;
    }
1275903
public function addBuyable(Buyable $item, $qty = 1, array $options = [])
    {
        $cartItem = CartItem::fromBuyable($item, $options);

        return $this->addItemToCart($cartItem, $qty);
    }
539655
protected function createFromModel($entity, $quantity)
    {
        $this->modelType = get_class($entity);
        $this->modelId = $entity->{$entity->getKeyName()};
        $this->setName($entity);
        $this->setPrice($entity);
        $this->setImage($entity);
        $this->quantity = $quantity;

        return $this;
    }
741878
protected function addToWishlist(array $cart)
    {
        $data = array(
            'user_id' => $cart['user_id'],
            'store_id' => $cart['store_id'],
            'product_id' => $cart['product_id']
        );

        return $this->wishlist_action->add($data);
    }
475329
public function addCustomItem($name, $sku, $description, $price, $qty = 1)
    {
        $body = [
            'data' => [
                'type' => 'custom_item',
                'name' => $name,
                'sku' => $sku,
                'description' => $description,
                'quantity' => $qty,
                'price' => [
                    'amount' => $price
                ]
            ]
        ];
        return $this->call('POST', $body, $this->getReference() . '/items');
    }
1015872
public function addCartItem($cartId, $cartItem)
    {
        $cartItem['id'] = count(session($this->itemsKey)) + 1;

        session()->push($this->itemsKey, $cartItem);
    }