/** * Aggregate item applied taxes to get order applied taxes * * @param AppliedTaxBuilder $appliedTaxBuilder * @param Item[] $items * @return AppliedTax[] */ protected function aggregateAppliedTaxes(AppliedTaxBuilder $appliedTaxBuilder, $items) { $orderAppliedTaxes = []; $orderAppliedTaxesData = []; foreach ($items as $item) { $itemAppliedTaxes = $item->getAppliedTaxes(); foreach ($itemAppliedTaxes as $itemAppliedTax) { $code = $itemAppliedTax->getCode(); if (!isset($orderAppliedTaxesData[$code])) { $orderAppliedTaxesData[$code] = [AppliedTax::KEY_CODE => $code, AppliedTax::KEY_TITLE => $itemAppliedTax->getTitle(), AppliedTax::KEY_PERCENT => $itemAppliedTax->getPercent(), AppliedTax::KEY_AMOUNT => $itemAppliedTax->getAmount(), AppliedTax::KEY_BASE_AMOUNT => $itemAppliedTax->getBaseAmount()]; } else { $orderAppliedTaxesData[$code][AppliedTax::KEY_AMOUNT] += $itemAppliedTax->getAmount(); $orderAppliedTaxesData[$code][AppliedTax::KEY_BASE_AMOUNT] += $itemAppliedTax->getBaseAmount(); } } } foreach ($orderAppliedTaxesData as $orderAppliedTaxData) { $appliedTaxBuilder->setCode($orderAppliedTaxData[AppliedTax::KEY_CODE]); $appliedTaxBuilder->setTitle($orderAppliedTaxData[AppliedTax::KEY_TITLE]); $appliedTaxBuilder->setPercent($orderAppliedTaxData[AppliedTax::KEY_PERCENT]); $appliedTaxBuilder->setAmount($orderAppliedTaxData[AppliedTax::KEY_AMOUNT]); $appliedTaxBuilder->setBaseAmount($orderAppliedTaxData[AppliedTax::KEY_BASE_AMOUNT]); $orderAppliedTaxes[] = $appliedTaxBuilder->create(); } return $orderAppliedTaxes; }
/** * {@inheritdoc} */ protected function _setDataValues(array $data) { if (isset($data[Item::KEY_APPLIED_TAXES])) { $appliedTaxDataObjects = []; $appliedTaxes = $data[Item::KEY_APPLIED_TAXES]; foreach ($appliedTaxes as $appliedTax) { $appliedTaxDataObjects[] = $this->appliedTaxBuilder->populateWithArray($appliedTax)->create(); } $data[Item::KEY_APPLIED_TAXES] = $appliedTaxDataObjects; } return parent::_setDataValues($data); }
/** * {@inheritdoc} */ public function _setDataValues(array $data) { if (isset($data[OrderTaxDetails::KEY_APPLIED_TAXES])) { $appliedTaxDataObjects = []; $appliedTaxes = $data[OrderTaxDetails::KEY_APPLIED_TAXES]; foreach ($appliedTaxes as $appliedTax) { $appliedTaxDataObjects[] = $this->appliedTaxBuilder->populateWithArray($appliedTax)->create(); } $data[OrderTaxDetails::KEY_APPLIED_TAXES] = $appliedTaxDataObjects; } if (isset($data[OrderTaxDetails::KEY_ITEMS])) { $taxDetailItemDataObjects = []; $taxDetailItems = $data[OrderTaxDetails::KEY_ITEMS]; foreach ($taxDetailItems as $taxDetailItem) { $taxDetailItemDataObjects[] = $this->itemBuilder->populateWithArray($taxDetailItem)->create(); } $data[OrderTaxDetails::KEY_ITEMS] = $taxDetailItemDataObjects; } return parent::_setDataValues($data); }