public function get(Buyable $buyable, $customfilter = array())
{
$order = $this->current();
if (!$buyable || !$order) {
return false;
}
$buyable = $this->getCorrectBuyable($buyable);
$filter = array('OrderID' => $order->ID);
$itemclass = Config::inst()->get(get_class($buyable), 'order_item');
$relationship = Config::inst()->get($itemclass, 'buyable_relationship');
$filter[$relationship . "ID"] = $buyable->ID;
$required = array('Order', $relationship);
if (is_array($itemclass::config()->required_fields)) {
$required = array_merge($required, $itemclass::config()->required_fields);
}
$query = new MatchObjectFilter($itemclass, array_merge($customfilter, $filter), $required);
$item = $itemclass::get()->where($query->getFilter())->first();
if (!$item) {
return $this->error(_t("ShoppingCart.ItemNotFound", "Item not found."));
}
return $item;
}