public function get(Buyable $buyable, $customfilter = array())
    {
        $order = $this->current();
        if (!$buyable || !$order) {
            return null;
        }

        $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 = ['OrderID', $relationship . 'ID'];
        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(__CLASS__ . '.ItemNotFound', 'Item not found.'));
        }

        return $item;
    }
public function get(Buyable $buyable, $customfilter = array())
    {
        $order = $this->current();
        if (!$buyable || !$order) {
            return null;
        }

        $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 = ['OrderID', $relationship . 'ID'];
        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(__CLASS__ . '.ItemNotFound', 'Item not found.'));
        }

        return $item;
    }
public function get ( Buyable $ buyable , $ customfilter = array ( ) ) { $ order = $ this -> current ( ) ; if ( ! $ buyable || ! $ order ) { return null ; } $ 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 = [ 'OrderID' , $ relationship . 'ID' ] ; 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 ( __CLASS__ . '.ItemNotFound' , 'Item not found.' ) ) ; } return $ item ; }
Finds an existing order item.

@param Buyable $buyable
@param array   $customfilter

@return OrderItem the item requested or null
Finds an existing order item .