LukePOLO\LaraCart\LaraCart::add PHP Method

add() public method

Creates a CartItem and then adds it to cart.
public add ( $itemID, null $name = null, integer $qty = 1, string $price = '0.00', array $options = [], boolean | false $taxable = true, boolean | false $lineItem = false ) : CartItem
$itemID
$name null
$qty integer
$price string
$options array
$taxable boolean | false
$lineItem boolean | false
return CartItem
    public function add($itemID, $name = null, $qty = 1, $price = '0.00', $options = [], $taxable = true, $lineItem = false)
    {
        if (!empty(config('laracart.item_model'))) {
            $itemModel = $itemID;
            if (!$this->isItemModel($itemModel)) {
                $itemModel = (new $this->itemModel())->with($this->itemModelRelations)->find($itemID);
            }
            if (empty($itemModel)) {
                throw new ModelNotFound('Could not find the item ' . $itemID);
            }
            $bindings = config('laracart.item_model_bindings');
            $itemID = $itemModel[$bindings[\LukePOLO\LaraCart\CartItem::ITEM_ID]];
            $name = $itemModel[$bindings[\LukePOLO\LaraCart\CartItem::ITEM_NAME]];
            if (empty($qty = $name) || !is_int($name)) {
                $qty = 1;
            }
            $price = $itemModel[$bindings[\LukePOLO\LaraCart\CartItem::ITEM_PRICE]];
            $options = array_merge($options, $this->getItemModelOptions($itemModel, $bindings[\LukePOLO\LaraCart\CartItem::ITEM_OPTIONS]));
            $taxable = $itemModel[$bindings[\LukePOLO\LaraCart\CartItem::ITEM_TAXABLE]] ? true : false;
        }
        $item = $this->addItem(new CartItem($itemID, $name, $qty, $price, $options, $taxable, $lineItem));
        $this->update();
        return $this->getItem($item->getHash());
    }