Skip to content

Commit

Permalink
CET-191/feat: Toggle to keep or remove tax_subtotal field during orde…
Browse files Browse the repository at this point in the history
…r creation
  • Loading branch information
brtkwr committed Feb 28, 2024
1 parent 8d15a25 commit 184c07f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Api/Config/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface RepositoryInterface
public const XML_PATH_ENABLE_INTERNATIONAL_TELEPHONE = 'payment/two_payment/enable_international_telephone';
public const XML_PATH_ENABLE_COMPANY_SEARCH = 'payment/two_payment/enable_company_search';
public const XML_PATH_ENABLE_ADDRESS_SEARCH = 'payment/two_payment/enable_address_search';
public const XML_PATH_ENABLE_TAX_SUBTOTAL = 'payment/two_payment/enable_tax_subtotal';
public const XML_PATH_ENABLE_ORDER_INTENT = 'payment/two_payment/enable_order_intent';
public const XML_PATH_ENABLE_DEPARTMENT_NAME = 'payment/two_payment/enable_department';
public const XML_PATH_ENABLE_PROJECT_NAME = 'payment/two_payment/enable_project';
Expand Down Expand Up @@ -143,6 +144,15 @@ public function isCompanySearchEnabled(?int $storeId = null): bool;
*/
public function isOrderIntentEnabled(?int $storeId = null): bool;

/**
* Check if tax subtotal is enabled
*
* @param int|null $storeId
*
* @return bool
*/
public function isTaxSubtotalEnabled(?int $storeId = null): bool;

/**
* Check if department is enabled
*
Expand Down
8 changes: 8 additions & 0 deletions Model/Config/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public function isOrderIntentEnabled(?int $storeId = null): bool
return $this->isSetFlag(self::XML_PATH_ENABLE_ORDER_INTENT, $storeId);
}

/**
* @inheritDoc
*/
public function isTaxSubtotalEnabled(?int $storeId = null): bool
{
return $this->isSetFlag(self::XML_PATH_ENABLE_TAX_SUBTOTAL, $storeId);
}

/**
* @inheritDoc
*/
Expand Down
5 changes: 4 additions & 1 deletion Service/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,11 @@ public function getBuyer(OrderModel $order, ?array $additionalData): array
* @param array $linesItems
* @return array
*/
public function getTaxSubtotals(array $linesItems): array
public function getTaxSubtotals(array $linesItems): ?array
{
if (!$this->configRepository->isTaxSubtotalEnabled()) {
return null;
}
$taxSubtotals = [];
foreach ($linesItems as $linesItem) {
$taxSubtotals[$linesItem['tax_rate']][] = [
Expand Down
1 change: 0 additions & 1 deletion Service/Order/ComposeRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function execute(Creditmemo $creditmemo, float $amount, Order $order): ar
'amount' => min($this->roundAmt($amount) * -1, $grossAmount),
'currency' => $order->getOrderCurrencyCode(),
'initiate_payment_to_buyer' => true,
'tax_subtotals' => $this->getTaxSubtotals($lineItems),
'line_items' => $lineItems,
];
}
Expand Down
10 changes: 10 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@
</depends>
<config_path>payment/two_payment/enable_order_intent</config_path>
</field>
<field id="enable_tax_subtotal" translate="label" type="select" sortOrder="75" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Enable tax subtotal</label>
<comment>Add optional tax subtotal metadata during order creation to enforce additional validation (recommended).</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/two_payment/enable_tax_subtotal</config_path>
</field>
<field id="enable_department" translate="label" type="select" sortOrder="80" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Add department field</label>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<days_on_invoice>14</days_on_invoice>
<finalize_purchase>1</finalize_purchase>
<enable_order_intent>1</enable_order_intent>
<enable_tax_subtotal>1</enable_tax_subtotal>
<fulfill_trigger>shipment</fulfill_trigger>
<fulfill_order_status>complete</fulfill_order_status>
<enable_international_telephone>1</enable_international_telephone>
Expand Down

0 comments on commit 184c07f

Please sign in to comment.