/** * When the tax collector fails to collect new tax data, the session should * not get updated and quote totals should not be recollected. */ public function testHandleSalesQuoteCollectTotalsCollectFailure() { // Indicate new tax collection is required in the session flags. $this->coreSession->expects($this->any())->method('isTaxUpdateRequired')->will($this->returnValue(true)); // Set the tax collector to fail to make the TDF request and throw // an exception. $this->taxCollector->expects($this->once())->method('collectTaxes')->will($this->throwException(Mage::exception('EbayEnterprise_Tax_Exception_Collector'))); // Ensure session quote data is not updated, flags are not reset and // quote totals are not re-collected. $this->coreSession->expects($this->never())->method('updateWithQuote'); $this->coreSession->expects($this->never())->method('resetTaxUpdateRequired'); $this->quote->expects($this->never())->method('collectTotals'); $this->taxObserver->handleSalesQuoteCollectTotalsAfter($this->eventObserver); }
/** * Recollect quote totals to update amounts based on newly received tax * data. This collect totals call is expected to happen recursively within * collect totals. The flags in eb2ccore/session are expected to prevent * going beyond a single recursive call to collect totals. As an additional * precaution, a lock is also used to prevent unexpected recursion. * * @param Mage_Sales_Model_Quote * @return Mage_Sales_Model_Quote */ protected function recollectTotals(Mage_Sales_Model_Quote $quote) { // Guard against unexpected recursion. Session flags should prevent // this but need to be sure this can't trigger infinite recursion. // If the lock is free (set to false), expect to not be within a recursive // collectTotals triggered by taxes. if (!self::$lockRecollectTotals) { // Acquire the lock prior to triggering the recursion. Prevents taxes // from being able to trigger further recursion. self::$lockRecollectTotals = true; $quote->collectTotals(); // Free the lock once we're clear of the recursive collectTotals. self::$lockRecollectTotals = false; } else { // Do not expect further recursive attempts to occur. Something // would be potentially wrong with the session flags if it does. $this->logger->warning('Attempted to recollect totals for taxes during a recursive collection. Additional collection averted to prevent further recursion.', $this->logContext->getMetaData(__CLASS__)); } return $quote; }