public function setUp() { // Create a mock of the quantity results for the quote. $this->_quantityResults = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->setMethods(['getQuantityBySku', 'getQuantityByItemId'])->getMock(); // Create a quote object to use within tests. Expected by // default by the quantity collector when getting results for a quote. $this->_quote = $this->getModelMock('sales/quote', ['addErrorInfo', 'getAllItems']); // Mock the quantity collector to simply always return // the mocked quantity results throughout the tests. $this->_quantityCollector = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_collector')->disableOriginalConstructor()->setMethods(['getQuantityResultsForQuote', 'clearResults'])->getMock(); $this->_quantityCollector->expects($this->any())->method('getQuantityResultsForQuote')->with($this->identicalTo($this->_quote))->will($this->returnValue($this->_quantityResults)); // Mock of the item selection helper, used to filter // down quote items down to just the items that need // to be checked by the inventory service. $this->_inventoryItemSelection = $this->getHelperMock('ebayenterprise_inventory/item_selection', ['selectFrom']); // Mock the inventory's data helper to control // expected results from translations doing translations. $this->_inventoryHelper = $this->getHelperMock('ebayenterprise_inventory/data', ['__']); // Mock out the translate method, while it would be nice to ensure // strings are getting translated through this method, the complexity // of doing so is not currently worth the effort. $this->_inventoryHelper->expects($this->any())->method('__')->will($this->returnArgument(0)); // Mock calculations of total item quantity. $this->_quantityHelper = $this->getHelperMock('ebayenterprise_inventory/quantity', ['calculateTotalQuantityRequested']); // Instance of the model being tested, injected // with the mocked dependencies. $this->_quantityService = Mage::getModel('ebayenterprise_inventory/quantity_service', ['quantity_collector' => $this->_quantityCollector, 'inventory_item_selection' => $this->_inventoryItemSelection, 'inventory_helper' => $this->_inventoryHelper, 'quantity_helper' => $this->_quantityHelper]); $this->_product = Mage::getModel('catalog/product', ['stock_item' => Mage::getModel('catalogInventory/stock_item', ['backorders' => Mage_CatalogInventory_Model_Stock::BACKORDERS_NO])]); }
/** * Get an estimated delivery message for a quote item. * * @param Mage_Sales_Model_Quote_Item * @return string */ public function getEddMessage(Mage_Sales_Model_Quote_Item $item) { /** @var string $singularOrPluralItem */ $singularOrPluralItem = (int) $item->getQty() > 1 ? 's' : ''; /** @var EbayEnterprise_Inventory_Model_Details_Item | Varien_Object | null $eddItem */ $eddItem = $this->detailService->getDetailsForItem($item) ?: $this->inventoryHelper->getStreetDateForBackorderableItem($item); return $eddItem ? $this->inventoryHelper->__($this->inventoryConfig->estimatedDeliveryTemplate, $singularOrPluralItem, $eddItem->getDeliveryWindowFromDate()->format('m/d/y'), $eddItem->getDeliveryWindowToDate()->format('m/d/y')) : ''; }
/** * add data from the inventory service to the order item * @param IOrderItem * @param Mage_Sales_Model_Order_Item * @return self */ public function injectShippingEstimates(IOrderItem $itemPayload, Mage_Sales_Model_Order_Item $item) { $detail = $this->detailService->getDetailsForOrderItem($item) ?: $this->helper->getOcrBackorderableEddData($item); if ($detail && $detail->isAvailable()) { $itemPayload->setEstimatedDeliveryMode(IEstimatedDeliveryDate::MODE_ENABLED)->setEstimatedDeliveryMessageType(IEstimatedDeliveryDate::MESSAGE_TYPE_DELIVERYDATE)->setEstimatedDeliveryTemplate($this->edd->getEddTemplate()); $this->handleDateFields($itemPayload, $detail); } return $this; }
protected function setUp() { $this->payloadHelper = Mage::helper('ebayenterprise_inventory/quantity_payload'); $this->inventoryHelper = $this->getHelperMock('ebayenterprise_inventory', ['getRomSku']); $this->inventoryHelper->method('getRomSku')->will($this->returnArgument(0)); // Swap out the inventory helper instance referenced by the payload helper // with the mock for consistent behavior during tests. $this->origInventoryHelper = EcomDev_Utils_Reflection::getRestrictedPropertyValue($this->payloadHelper, 'inventoryHelper'); EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->payloadHelper, 'inventoryHelper', $this->inventoryHelper); }
public function setUp() { parent::setUp(); // Prevent log context from needing session while gather context data for logging. $this->logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); $this->logContext->method('getMetaData')->will($this->returnValue([])); $this->api = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi'); $this->configModel = $this->buildCoreConfigRegistry(['apiService' => 'inventory', 'apiOperation' => 'allocate']); $this->helper = $this->getHelperMock('ebayenterprise_inventory'); $this->helper->method('getConfigModel')->will($this->returnValue($this->configModel)); $this->coreHelper = $this->getHelperMock('eb2ccore', ['getSdkApi']); $this->coreHelper->method('getSdkApi')->will($this->returnValue($this->api)); }
/** * When calculating the total quantity requested for an item, the quantity * of all items with the same sku as the given item should be summed to * give the total quantity of that item requested. */ public function testCalculateTotalQuantitiesBySku() { $firstSku = 'first-sku'; $secondSku = 'second-sku'; $allItems = [$this->_mockItemWithQtyAndParent(5, $firstSku, $this->_mockItemWithQtyAndParent(2, $firstSku)), $this->_mockItemWithQtyAndParent(3, $secondSku), $this->_mockItemWithQtyAndParent(2, $firstSku)]; $qtyBySku = $this->_helper->calculateTotalQuantitiesBySku($allItems); $this->assertCount(2, $qtyBySku, 'incorrect number of sku => quantity results returned'); $this->assertSame(12, $qtyBySku[$firstSku], "wrong quantity for sku {$firstSku}"); $this->assertSame(3, $qtyBySku[$secondSku], "wrong quantity for sku {$secondSku}"); }
public function setUp() { $logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); $logContext->expects($this->any())->method('getMetaData')->will($this->returnValue([])); $this->_api = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi'); // Create two request bodies - one to serve as the "empty" request // body that needs to be populated with data and one to serve as // the "complete" payload that has been populated with data. $this->_emptyRequestBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityRequest'); $this->_completeRequestBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityRequest'); $this->_responseBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityReply'); $this->_coreHelper = $this->getHelperMock('ebayenterprise_eb2ccore', ['getSdkApi']); $this->_inventoryConfig = $this->buildCoreConfigRegistry(['apiService' => $this->_apiService, 'quantityApiOperation' => $this->_apiOperation]); $this->_inventoryHelper = $this->getHelperMock('ebayenterprise_inventory/data', ['__']); $this->_inventoryHelper->expects($this->any())->method('__')->will($this->returnArgument(0)); $this->_inventoryFactory = $this->getHelperMock('ebayenterprise_inventory/quantity_factory', ['createRequestBuilder', 'createResponseParser', 'createQuantityResults']); $this->_requestBuilder = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_request_builder')->disableOriginalConstructor()->setMethods(['getRequest'])->getMock(); $this->_responseParser = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_response_parser')->disableOriginalConstructor()->setMethods(['getQuantityResults'])->getMock(); $this->_items = [$this->getModelMock('sales/quote_item')]; $this->_sdkHelper = Mage::helper('ebayenterprise_inventory/quantity_sdk'); // As helpers do not support constructor injection, inject // dependencies by directly setting the class properties. EcomDev_Utils_Reflection::setRestrictedPropertyValues($this->_sdkHelper, ['_coreHelper' => $this->_coreHelper, '_inventoryHelper' => $this->_inventoryHelper, '_inventoryConfig' => $this->_inventoryConfig, '_logContext' => $logContext, '_inventoryQuantityFactory' => $this->_inventoryFactory]); }
/** * Get the quantity results for an item. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return EbayEnterprise_Inventory_Model_Quantity|null */ protected function _getQuantityResultForItem(Mage_Sales_Model_Quote_Item_Abstract $item) { return $this->_quantityCollector->getQuantityResultsForQuote($item->getQuote())->getQuantityBySku($this->_inventoryHelper->getRomSku($item->getSku())); }
/** * configure and get the API * * @param string * @return IBidirectionalApi */ public function prepareApi() { $config = $this->helper->getConfigModel(); $api = $this->coreHelper->getSdkApi($config->apiService, $config->apiAllocationCreateOperation); return $api; }
/** * handle the case where there is not enough stock to allocate the * full amount requested * * @param EbayEnterprise_Inventory_Model_Allocation * @param Mage_Sales_Model_Order_Item * @throws EbayEnterprise_Inventory_Exception_Allocation_Availability_Exception */ protected function handleInsufficientStock(Mage_Sales_Model_Order_Item $item) { $this->logger->debug('Unable to reserve desired quantity for item {sku}', $this->logContext->getMetaData(__CLASS__, ['sku' => $item->getSku()])); throw Mage::exception('EbayEnterprise_Inventory_Exception_Allocation_Availability', $this->invHelper->__(static::INSUFFICIENT_STOCK_MESSAGE)); }
/** * Add error info to an item when it is not available for purchase. * * @param Mage_Sales_Model_Quote_Item * @param int * @return self */ protected function _addInsufficientStockErrorInfoForItem(Mage_Sales_Model_Quote_Item $item, $availableQuantity) { return $this->_addErrorInfoForItem($item, self::INSUFFICIENT_STOCK_ERROR_CODE, $this->_inventoryHelper->__(self::ITEM_INSUFFICIENT_STOCK_MESSAGE, $item->getName(), $availableQuantity), $this->_inventoryHelper->__(self::QUOTE_INSUFFICIENT_STOCK_MESSAGE)); }
/** * Add error info to an item when it is not available for purchase. * * @param Mage_Sales_Model_Quote_Item * @param int * @return self */ protected function _addInsufficientStockErrorInfoForItem(Mage_Sales_Model_Quote_Item $item, $quantityAvailable) { return $this->_addErrorInfoForItem($item, EbayEnterprise_Inventory_Model_Quantity_Service::INSUFFICIENT_STOCK_ERROR_CODE, $this->inventoryHelper->__(EbayEnterprise_Inventory_Model_Quantity_Service::ITEM_INSUFFICIENT_STOCK_MESSAGE, $item->getName(), $quantityAvailable), $this->inventoryHelper->__(EbayEnterprise_Inventory_Model_Quantity_Service::QUOTE_INSUFFICIENT_STOCK_MESSAGE)); }
/** * Get and configure the api */ protected function prepareApi() { $config = $this->helper->getConfigModel(); $api = $this->coreHelper->getSdkApi($config->apiService, $config->apiDetailsOperation); return $api; }
/** * Transfer data from a quote item to a quantity * request item payload. * * @param Mage_Sales_Model_Quote_Item_Abstract * @param IQuantityItem * @return IQuantityItem */ public function itemToQuantityItem(Mage_Sales_Model_Quote_Item_Abstract $item, IQuantityItem $itemPayload) { return $itemPayload->setItemId($this->inventoryHelper->getRomSku($item->getSku()))->setLineId($item->getId()); }
protected function handleDesynchedFromQuantity() { throw Mage::exception('EbayEnterprise_Inventory_Exception_Details_Unavailable', $this->invHelper->__(static::ITEM_UNAVAILABLE)); }
/** * Create a fairly generic exception for the inventory module indicating * that quantity collection via the SDK has failed. * * @return EbayEnterprise_Inventory_Exception_Quantity_Collector_Exception */ protected function _failQuantityCollection() { return Mage::exception('EbayEnterprise_Inventory_Exception_Quantity_Collector', $this->_inventoryHelper->__(self::INVENTORY_QUANTITY_FAILED_MESSAGE)); }