public function testMissingValues() { // Tests that missing values are included in the filter as IS NULL or = 0 // Missing value for a has_one relationship field. $filter = new MatchObjectFilter('Product_OrderItem', array(), array('Product')); $this->assertEquals($filter->getFilter(), array('("ProductID" = 0 OR "ProductID" IS NULL)'), 'missing ID value became IS NULL or = 0'); // Missing value for a db field. $filter = new MatchObjectFilter('Product_OrderItem', array(), array('ProductVersion')); $this->assertEquals($filter->getFilter(), array('"ProductVersion" IS NULL'), 'missing DB value became IS NULL or = 0'); }
/** * Finds an existing order item. * @param Buyable $buyable * @param string $filter * @return the item requested, or false */ public function get(Buyable $buyable, $customfilter = array()) { $order = $this->current(); if (!$buyable || !$order) { return false; } $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; }