/** * When filtering from a list with a grouped item, the grouped item item, * which will simply be one of the items added by the group, should be included. */ public function testSelectFromGroupedProducts() { $groupedItem = $this->_mockItem(Mage_Catalog_Model_Product_Type::TYPE_GROUPED); $selectedItems = $this->_itemSelection->selectFrom([$groupedItem]); $this->assertCount(1, $selectedItems); $this->assertSame([$groupedItem], $selectedItems); }
/** * When getting items for an address, only items that should be included * in the order create request should be returned. */ public function testGetItemsForAddressFiltering() { // Create an item that is exptected to be excluded from the OCR and // an items that should be included. $excludedItem = Mage::getModel('sales/order_item', ['order_address_id' => $this->_shipAddressId]); $includedItem = Mage::getModel('sales/order_item', ['order_address_id' => $this->_shipAddressId]); $this->_order->addItem($excludedItem)->addItem($includedItem); // Stubs $api = $this->_httpApi; $config = $this->getModelMock('eb2ccore/config_registry'); $payload = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Order\\IOrderCreateRequest'); $constructorArgs = ['api' => $api, 'config' => $config, 'order' => $this->_order, 'payload' => $payload, 'item_selection' => $this->_itemSelection]; $create = Mage::getModel('ebayenterprise_order/create', $constructorArgs); // Mock the item selection helper such that if given the array of items // that belong to the address - excluded and included items - that only // the items that should be included are returned. $this->_itemSelection->expects($this->any())->method('selectFrom')->with($this->identicalTo([$excludedItem, $includedItem]))->will($this->returnValue([$includedItem])); $itemsForAddress = EcomDev_Utils_Reflection::invokeRestrictedMethod($create, '_getItemsForAddress', [$this->_shipAddress, $this->_order->getItemsCollection()]); $this->assertCount(1, $itemsForAddress); $this->assertSame($includedItem, $itemsForAddress[0]); }
/** * Get all items shipping to a given address. For billing addresses, this * will be all virtual items in the order. For shipping addresses, any * non-virtual items. Only items that are to be included in the order create * request should be returned. * * @param Mage_Customer_Model_Address_Abstract * @param Mage_Sales_Model_Resource_Order_Item_Collection * @return Mage_Sales_Model_Order_Item[] */ protected function _getItemsForAddress(Mage_Customer_Model_Address_Abstract $address, Mage_Sales_Model_Resource_Order_Item_Collection $orderItems) { // All items will have an `order_address_id` matching the id of the // address the item ships to (including virtual items which "ship" to // the billing address). // Filter the given collection instead of using address methods to get // items to prevent loading separate item collections for each address. return $this->_itemSelection->selectFrom($orderItems->getItemsByColumnValue('order_address_id', $address->getId())); }