/** * Add fees calculated for the item. * * @return self */ protected function _addFees() { $feeTaxRecords = $this->_getTaxRecordsBySource(EbayEnterprise_Tax_Model_Record::SOURCE_FEE); $feeIterable = $this->_orderItemPayload->getFees(); foreach ($this->_fees as $fee) { $feeId = $fee->getId(); // Tax records that apply to a fee will have a fee id matching // the id of the fee. Filter the tax records that may apply to any // fee for the item to only the tax records that apply to the fee // being processed. // @TODO This is probably terribly inefficient due to having to // array_filter the full set of tax records for every fee. For // now, at least, it should be a small enough data set to not demand // immediate remediation. $feeTaxes = array_filter($feeTaxRecords, function ($taxRecord) use($feeId) { return $feeId && $feeId === $taxRecord->getFeeId(); }); $feePayload = $feeIterable->getEmptyFee(); $this->_payloadHelper->taxFeeToOrderFeePayload($fee, $feePayload, $feeTaxes); $feeIterable[$feePayload] = null; } $this->_orderItemPayload->setFees($feeIterable); return $this; }