Skip to content

Commit

Permalink
Make get item taxes extendable. Refactoring. (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: MykolaMalovanets <mykola.malovanets@gmail.com>
  • Loading branch information
nmalevanec and MykolaMalovanets authored Nov 30, 2023
1 parent bf9826e commit d0a23bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Checkout/Service/Extractor/Quote/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function extract(Mage_Sales_Model_Quote_Address $address)
'id' => (int)$address->getId() ?: null,
'region' => $address->getRegion(),
'region_id' => (int)$address->getRegionId() ?: null,
'region_code' => $address->getRegionCode(),
'region_code' => $address->getRegionId() ? $address->getRegionCode(): null,
'country_id' => $address->getCountryId(),
'street' => $street,
'telephone' => $address->getTelephone(),
Expand Down
27 changes: 18 additions & 9 deletions Checkout/Service/Extractor/Quote/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ private static function getTaxData(
Mage_Sales_Model_Quote $quote,
Mage_Sales_Model_Quote_Item $item
) {
$itemTaxDetails = [];
$itemTaxDetails = new stdClass();
$itemTaxDetails->taxes = [];
$itemTaxAmount = $item->getTaxAmount();
foreach ($quote->getTaxesForItems() as $itemId => $taxDetails) {
if ((int)$item->getId() !== (int)$itemId) {
Expand All @@ -242,21 +243,29 @@ private static function getTaxData(
$appliedTaxNumber = count($taxDetails);
$i = 1;
foreach ($taxDetails as $tax) {
$calculatedAmount = Mage::app()->getStore()->roundPrice($item->getPrice() * ($tax['percent'] / 100));
$calculatedAmount = (float)$item->getPrice() * ($tax['percent'] / 100);
$amount = $i < $appliedTaxNumber && $calculatedAmount < $itemTaxAmount
? $calculatedAmount
: $itemTaxAmount;
$itemTaxAmount = $itemTaxAmount - $amount;
$itemTaxDetails[] = [
'id' => $tax['id'],
'amount' => $amount,
'percent' => $tax['percent'],
'rates' => $tax['rates'],
];
$taxData = new stdClass();
$taxData->id = $tax['id'];
$taxData->amount = $calculatedAmount;
$taxData->percent = $tax['percent'];
$taxData->rates = $tax['rates'];
$itemTaxDetails->taxes[] = $taxData;
$i++;
}
}
return $itemTaxDetails;
Mage::dispatchEvent(
'bold_checkout_item_tax_extract_after',
[
'item_tax_details' => $itemTaxDetails,
'quote_item' => $item,
'quote' => $quote,
]
);
return array_values($itemTaxDetails->taxes);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Checkout/Service/Extractor/Quote/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static function extractShippingMethod(Mage_Sales_Model_Quote_Address_Rat
'carrier_code' => $rate->getCarrier(),
'method_code' => $rate->getMethod(),
'carrier_title' => $rate->getCarrierTitle(),
'method_title' => $rate->getMethodTitle(),
'method_title' => strip_tags($rate->getMethodTitle()),
'amount' => (float)$rate->getPrice(),
'base_amount' => (float)$rate->getPrice(),
'available' => true,
Expand Down
67 changes: 0 additions & 67 deletions CheckoutTmFireCheckout/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
</Bold_CheckoutTmFireCheckout>
</modules>
<frontend>
<!-- Fire Checkout Index Controller. -->
<events>
<checkout_controller_onepage_save_shipping_method>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterShippingSave</method>
</bold>
</observers>
</checkout_controller_onepage_save_shipping_method>
<controller_action_predispatch_firecheckout_index_index>
<observers>
<bold>
Expand All @@ -24,64 +15,6 @@
</bold>
</observers>
</controller_action_predispatch_firecheckout_index_index>
<controller_action_predispatch_firecheckout_index>
<observers>
<bold>
<class>Bold_Checkout_Observer_CheckoutObserver</class>
<method>beforeCheckout</method>
</bold>
</observers>
</controller_action_predispatch_firecheckout_index>
<controller_action_postdispatch_firecheckout_saveBilling>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterBillingSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_saveBilling>
<controller_action_postdispatch_firecheckout_saveShipping>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterShippingSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_saveShipping>
<controller_action_postdispatch_firecheckout_index_saveShippingMethod>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterShippingMethodSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_index_saveShippingMethod>

<!-- Fire Checkout One Column Controller. -->
<controller_action_postdispatch_firecheckout_onecolumn_savebilling>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterBillingSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_onecolumn_savebilling>
<controller_action_postdispatch_firecheckout_onecolumn_saveShipping>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterShippingSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_onecolumn_saveShipping>
<controller_action_postdispatch_firecheckout_onecolumnt_saveShippingMethod>
<observers>
<bold>
<class>Bold_Checkout_Observer_OnepageControllerObserver</class>
<method>afterShippingMethodSave</method>
</bold>
</observers>
</controller_action_postdispatch_firecheckout_onecolumnt_saveShippingMethod>
</events>
</frontend>
</config>

0 comments on commit d0a23bd

Please sign in to comment.