コード例 #1
0
 /**
  * Add totals for collected taxes to the parent block. Totals added to the
  * parent will be displayed with order totals.
  *
  * @return self
  */
 public function initTotals()
 {
     $parent = $this->getParentBlock();
     $taxAmount = $this->totalTaxAmount();
     $parent->addTotal(new Varien_Object(['code' => self::TOTAL_CODE, 'value' => $taxAmount, 'base_value' => $taxAmount, 'label' => $this->helper->__(self::TAX_LABEL)]), 'discount');
     return $this;
 }
コード例 #2
0
 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\\TaxDutyFee\\ITaxDutyFeeQuoteRequest');
     $this->_completeRequestBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\TaxDutyFee\\ITaxDutyFeeQuoteRequest');
     $this->_responseBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\TaxDutyFee\\ITaxDutyFeeQuoteReply');
     $this->_coreHelper = $this->getHelperMock('ebayenterprise_eb2ccore', ['getSdkApi']);
     $this->_taxConfig = $this->buildCoreConfigRegistry(['apiService' => $this->_apiService, 'apiOperation' => $this->_apiOperation]);
     $this->_taxHelper = $this->getHelperMock('ebayenterprise_tax/data', ['__']);
     $this->_taxHelper->expects($this->any())->method('__')->will($this->returnArgument(0));
     $this->_taxFactory = $this->getHelperMock('ebayenterprise_tax/factory', ['createRequestBuilderQuote', 'createResponseQuoteParser', 'createTaxResults']);
     $this->_quoteRequestBuilder = $this->getModelMockBuilder('ebayenterprise_tax/request_builder_quote')->disableOriginalConstructor()->setMethods(['getTaxRequest'])->getMock();
     $this->_quoteResponseParser = $this->getModelMockBuilder('ebayenterprise_tax/response_parser_quote')->disableOriginalConstructor()->setMethods(['getTaxRecords', 'getTaxDuties', 'getTaxFees'])->getMock();
     $this->_quote = $this->getModelMock('sales/quote');
     $this->_taxHelper = $this->getHelperMock('ebayenterprise_tax', ['getConfigModel']);
     $this->_taxHelper->method('getConfigModel')->willReturn($this->_taxConfig);
     // As helpers do not support constructor injection, inject
     // dependencies by directly setting the class properties.
     EcomDev_Utils_Reflection::setRestrictedPropertyValues($this->_taxHelper, ['coreHelper' => $this->_coreHelper, 'taxFactory' => $this->_taxFactory, 'logContext' => $logContext]);
 }
コード例 #3
0
 /**
  * Update the address with totals data used for display in a total line,
  * e.g. a total line in the cart.
  *
  * @param Mage_Sales_Model_Quote_Address
  * @return self
  */
 public function fetch(Mage_Sales_Model_Quote_Address $address)
 {
     $total = $address->getTotalAmount($this->getCode());
     if ($total) {
         $address->addTotal(['code' => $this->getCode(), 'title' => $this->_helper->__(self::TAX_TOTAL_TITLE), 'value' => $total]);
     }
     return $this;
 }
コード例 #4
0
 /**
  * When the quote is invalid for making a tax request, no request should
  * be attempted and existing tax records should be cleared - reset
  * to empty arrays.
  *
  * By default, the quote used in the tests will be considered to be invalid
  * for tax requests - no item count as well as missing address data.
  */
 public function testCollectTaxesFailedInvalidQuote()
 {
     // Simulate the TDK request returning a set of tax records.
     $this->_taxHelper->expects($this->never())->method('requestTaxesForQuote');
     // Side-effect test - ensure all tax records in the session storage are
     // emptied of existing tax records when a tax request fails to be made.
     $this->_taxSession->expects($this->once())->method('setTaxRecords')->with($this->identicalTo([]))->will($this->returnSelf());
     $this->_taxSession->expects($this->once())->method('setTaxDuties')->with($this->identicalTo([]))->will($this->returnSelf());
     $this->_taxSession->expects($this->once())->method('setTaxFees')->with($this->identicalTo([]))->will($this->returnSelf());
     // Side-effect test - ensure that when a tax request was made successfully,
     // that a flag indicating that is set in the session.
     $this->_taxSession->expects($this->once())->method('setTaxRequestSuccess')->with($this->identicalTo(false))->will($this->returnSelf());
     $this->setExpectedException('EbayEnterprise_Tax_Exception_Collector_InvalidQuote_Exception');
     $this->_taxCollector->collectTaxes($this->_quote);
 }
コード例 #5
0
 /**
  * Collect taxes for quote, making an SDK tax request if necessary.
  *
  * @param Mage_Sales_Model_Quote
  * @return self
  * @throws EbayEnterprise_Tax_Exception_Collector_Exception If TDF cannot be collected.
  */
 public function collectTaxes(Mage_Sales_Model_Quote $quote)
 {
     $this->_logger->debug('Collecting new tax data.', $this->_logContext->getMetaData(__CLASS__));
     try {
         $this->_validateQuote($quote);
         $taxResults = $this->_taxHelper->requestTaxesForQuote($quote);
     } catch (EbayEnterprise_Tax_Exception_Collector_Exception $e) {
         // If tax records needed to be updated but could be collected,
         // any previously collected taxes need to be cleared out to
         // prevent tax data that is no longer applicable to the quote
         // from being preserved. E.g. taxes for an item no longer in
         // the quote or calculated for a different shipping/billing
         // address cannot be preserved. Complexity of individually
         // pruning tax data in this case does not seem worth the
         // cost at this time.
         $this->setTaxRecords([])->setTaxDuties([])->setTaxFees([])->setTaxRequestSuccess(false);
         throw $e;
     }
     // When taxes were successfully collected,
     $this->setTaxRecords($taxResults->getTaxRecords())->setTaxDuties($taxResults->getTaxDuties())->setTaxFees($taxResults->getTaxFees())->setTaxRequestSuccess(true);
     return $this;
 }
コード例 #6
0
 /**
  * Inject general item data into the order item payload.
  *
  * @return self
  */
 protected function _injectItemData()
 {
     $this->_orderItem->setLineNumber($this->_item->getId())->setItemId($this->_item->getSku())->setQuantity((int) $this->_item->getQty())->setDescription($this->_item->getName())->setHtsCode($this->_taxHelper->getProductHtsCodeByCountry($this->_itemProduct, $this->_address->getCountryId()))->setManufacturingCountryCode($this->_itemProduct->getCountryOfManufacture());
     return $this;
 }
コード例 #7
0
 /**
  * When a product has not HTS codes available, null should be returned
  * when attpemting to get an HTS code.
  */
 public function testGetProductHtsCodeByCountryNoMatchingHtsCode()
 {
     $product = Mage::getModel('catalog/product', ['hts_codes' => serialize([['destination_country' => 'US', 'hst_code' => 'US-HTS-Code']])]);
     $this->assertNull($this->_helper->getProductHtsCodeByCountry($product, 'CA'));
 }
コード例 #8
0
 /**
  * Create a fairly generic exception for the tax module indicating
  * that tax collection via the SDK has failed.
  *
  * @return EbayEnterprise_Tax_Exception_Collector_Exception
  */
 protected function _failTaxCollection()
 {
     return Mage::exception('EbayEnterprise_Tax_Exception_Collector', $this->_taxHelper->__(self::TAX_FAILED_MESSAGE));
 }