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;
}