ShoppingCart::findOrMakeItem PHP Method

findOrMakeItem() private method

Finds or makes an order item for a given product + filter.
private findOrMakeItem ( Buyable $buyable, integer $quantity = 1, array $filter = [] ) : OrderItem
$buyable Buyable the buyable
$quantity integer quantity to add
$filter array
return OrderItem the found or created item
    private function findOrMakeItem(Buyable $buyable, $quantity = 1, $filter = array())
    {
        $order = $this->findOrMake();
        if (!$buyable || !$order) {
            return false;
        }
        $item = $this->get($buyable, $filter);
        if (!$item) {
            $member = Member::currentUser();
            $buyable = $this->getCorrectBuyable($buyable);
            if (!$buyable->canPurchase($member, $quantity)) {
                return $this->error(_t('ShoppingCart.CannotPurchase', 'This {Title} cannot be purchased.', '', array('Title' => $buyable->i18n_singular_name())));
                //TODO: produce a more specific message
            }
            $item = $buyable->createItem($quantity, $filter);
            $item->OrderID = $order->ID;
            $item->write();
            $order->Items()->add($item);
            $item->_brandnew = true;
            // flag as being new
        }
        return $item;
    }