public function setUp() { // Mock session storage for previously collected quantity results $this->_inventorySession = $this->getModelMockBuilder('ebayenterprise_inventory/session')->setMethods(['getQuantityResults', 'setQuantityResults', 'getResultsCollectedFor', 'setResultsCollectedFor'])->disableOriginalConstructor()->getMock(); // Mock of the sdk helper for getting new quantity results from the API $this->_quantitySdkHelper = $this->getHelperMock('ebayenterprise_inventory/quantity_sdk', ['requestQuantityForItems']); // A quantity results stub, expected to be returned by the session or // sdk helper. $this->_quantityResults = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->setMethods(['checkResultsApplyToItems'])->getMock(); // Stub quote object to collect quantity records for. $this->_quote = $this->getModelMock('sales/quote', ['getAllItems']); // Stub quote item that should be sent to the inventory service. $this->_quoteItem = $this->getModelMock('sales/quote_item', []); // Quote items and filtered quote items allow tests to distinguish // between all items in the quote and just items that matter to the // inventory service. All quote items includes an additional quote item // that is not expected to be sent to the quantity API. $this->_quoteItems = [$this->_quoteItem, $this->getModelMock('sales/quote_item', [])]; $this->_filteredQuoteItems = [$this->_quoteItem]; // Stub quote to return all quote items. $this->_quote->expects($this->any())->method('getAllItems')->will($this->returnValue($this->_quoteItems)); // Stub filtering from the full quote items down to the filtered // array of quote items. Tests that expect a list of items that matter // to the inventory service can expect the filted quote items array // instead of the unfiltered quote items array. $this->_itemSelection = $this->getHelperMock('ebayenterprise_inventory/item_selection', ['selectFrom']); $this->_itemSelection->expects($this->any())->method('selectFrom')->with($this->identicalTo($this->_quoteItems))->will($this->returnValue($this->_filteredQuoteItems)); // Mock helper for calculating item quantities. $this->_quantityHelper = $this->getHelperMock('ebayenterprise_inventory/quantity', ['calculateTotalQuantitiesBySku']); $this->_currentItemQuantityData = ['a-sku' => 100]; $this->_quantityHelper->expects($this->any())->method('calculateTotalQuantitiesBySku')->with($this->_filteredQuoteItems)->will($this->returnValue($this->_currentItemQuantityData)); $this->_quantityCollector = Mage::getModel('ebayenterprise_inventory/quantity_collector', ['quantity_sdk_helper' => $this->_quantitySdkHelper, 'quantity_helper' => $this->_quantityHelper, 'item_selection' => $this->_itemSelection, 'inventory_session' => $this->_inventorySession]); }
/** * Mock out the collection of items to be checked - quote should return an * array containing the item the the item selector, given that array, should * return it (assume the item isn't filtered out). * * @param Mage_Sales_Model_Quote_Item * @return self */ protected function _mockQuoteItemSelection($quoteItem, $dupeSkuQuoteItem = null) { $quoteItems = $dupeSkuQuoteItem ? [$quoteItem, $dupeSkuQuoteItem] : [$quoteItem]; $invokeArgument = $dupeSkuQuoteItem ? $this->logicalOr($this->identicalTo($quoteItem), $this->identicalTo($dupeSkuQuoteItem)) : $this->identicalTo($quoteItem); $this->_quote->expects($this->any())->method('getAllItems')->will($this->returnValue($quoteItems)); $this->_inventoryItemSelection->expects($this->any())->method('isExcludedItem')->with($invokeArgument)->willReturn(false); $this->_inventoryItemSelection->expects($this->any())->method('isStockManaged')->with($invokeArgument)->willReturn(true); return $this; }
/** * Calculate the total quantity requested of a given item. All items in the * quote with the same SKU as the given item will be counted toward the * total quantity. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return int */ protected function _calculateTotalQuantityRequested(Mage_Sales_Model_Quote_Item_Abstract $item) { $inventoryItems = $this->_inventoryItemSelection->selectFrom($item->getQuote()->getAllItems()); return $this->_quantityHelper->calculateTotalQuantityRequested($item, $inventoryItems); }
/** * Mock out the collection of items to be checked - quote should return an * array containing the item the the item selector, given that array, should * return it (assume the item isn't filtered out). * * @param Mage_Sales_Model_Quote_Item[] * @return self */ protected function _mockQuoteItemSelection($quoteItems) { $this->_quote->expects($this->any())->method('getAllItems')->will($this->returnValue($quoteItems)); $this->_inventoryItemSelection->expects($this->any())->method('selectFrom')->with($this->identicalTo($quoteItems))->will($this->returnArgument(0)); return $this; }
/** * Get quantity results for a quote. * * @param Mage_Sales_Model_Quote * @return EbayEnterprise_Inventory_Model_Quantity_Results */ public function getQuantityResultsForQuote(Mage_Sales_Model_Quote $quote) { $items = $this->_itemSelection->selectFrom($quote->getAllItems()); return $this->_getSessionResults($items) ?: $this->_requestNewResults($items); }
/** * Select items to be sent in the request from the given array * based on product type. * * @param Mage_Sales_Model_Quote_Item_Abstract[] * @return Mage_Sales_Model_Quote_Item_Abstract[] */ public function selectFrom(array $items) { return array_filter($this->selector->selectFrom($items), [$this->qtyService, 'isItemAvailable']); }