/** * Extract tax data from the ship group. * * Extracts all three sets of tax data as each set of data can be retrieved * from the same item parser. Extracting all three sets at once prevents * nearly identical steps from being repeated for each item for each type of * tax data. * * @return EbayEnterprise_Tax_Model_Record[] */ protected function _extractTaxData() { // Each of these will hold an array of arrays of data extracted from each // ship group - e.g. $taxRecords = [[$recordA, $recordB], [$recordC, $recordD]]. // Prepopulate tax records with data extracted for the address for gifting // so it will get merged together with item taxes. $taxRecords = [$this->_extractGiftingTaxRecords()]; $duties = []; $fees = []; /** @var ITaxedOrderItem $orderItem */ foreach ($this->_shipGroup->getItems() as $orderItem) { /** @var Mage_Sales_Model_Quote_Item $item */ $item = $this->_getItemForItemPayload($orderItem); if ($item) { $itemParser = $this->_taxFactory->createResponseItemParser($orderItem, $item, $this->_addressId, $this->_quoteId); $taxRecords[] = $itemParser->getTaxRecords(); $duties[] = $itemParser->getTaxDuties(); $fees[] = $itemParser->getTaxFees(); } else { $this->_logger->warning('Tax response item does not relate to any known quote item.', $this->_logContext->getMetaData(__CLASS__, ['rom_response_body' => $orderItem->serialize()])); } } // Flatten each nested array of tax data - allows for a single array_merge // instead of iteratively calling array_merge on each pass when extracting // tax data for each item. $this->_taxRecords = $this->_flattenArray($taxRecords); $this->_taxDuties = $this->_flattenArray($duties); $this->_taxFees = $this->_flattenArray($fees); return $this; }