/**
  * Transfer discount data from Mage_Sales_Model_Order_Addresses
  * to IDiscountContainer.
  *
  * @see EbayEnterprise_Order_Model_Observer::handleSalesQuoteCollectTotalsAfter
  * @param  Varien_Object      item or address object
  * @param  IDiscountContainer
  * @return IDiscountContainer
  */
 public function transferDiscounts(Varien_Object $salesObject, IDiscountContainer $discountContainer)
 {
     /** @var IDiscountIterable $discounts */
     $discounts = $discountContainer->getDiscounts();
     $data = $this->getDiscountsData($salesObject);
     foreach ($data as $loneDiscountData) {
         $discount = $this->_fillOutDiscount($discounts->getEmptyDiscount(), $loneDiscountData);
         $discounts[$discount] = $discount;
     }
     return $discountContainer->setDiscounts($discounts);
 }
 /**
  * Add tax records to discount payloads within the discount container.
  *
  * @param EbayEnterprise_Tax_Model_Record[]
  * @param IDiscountContainer
  * @return self
  */
 protected function _addDiscountTaxRecords(array $taxRecords, IDiscountContainer $discountContainer)
 {
     foreach ($discountContainer->getDiscounts() as $discountPayload) {
         $discountId = $discountPayload->getId();
         // Tax records that apply to a discount will have a discount id matching
         // the id of the discount. Filter the tax records that may apply to any
         // discount for the item to only the tax records that apply to the
         // discount being processed.
         // @TODO This is probably terribly inefficient due to having to
         // array_filter the full set of tax records for every discount. For
         // now, at least, it should be a small enough data set to not demand
         // immediate remediation.
         $this->_addTaxRecordsToContainer(array_filter($taxRecords, function ($taxRecord) use($discountId) {
             return $discountId && $taxRecord->getDiscountId() == $discountId;
         }), $discountPayload);
     }
     return $this;
 }