Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Shipment taxes #3907

Merged
merged 10 commits into from
Jan 26, 2016
Merged

[Core] Shipment taxes #3907

merged 10 commits into from
Jan 26, 2016

Conversation

Zales0123
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets
License MIT
Doc PR

This PR is based on #3868.

Here there comes some next improvements with taxes ;) ShippingMethod becomes taxable so no we can apply some new taxes based on shipping fee. For now, taxes are applied on Order level. There are also two new services OrderUnitsTaxesApplicator and OrderShipmentTaxesApplicator (I think naming should be discussed), which are injected to main OrderTaxesApplicator, to split taxes-application logic.

And the following payment methods exist:
| code | name | gateway | enabled | calculator | calculator_configuration |
| PM1 | Dummy | dummy | yes | fixed | amount: 0 |
| code | name | gateway | enabled | calculator | calculator_configuration |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? :)

* @param string $label
* @param bool $included
*/
private function addAdjustment($order, $taxAmount, $label, $included)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addAdjustment method is a duplicate of what appears in the Sylius\Bundle\CoreBundle\OrderProcessing\OrderShipmentTaxesApplicator service. Consider moving this out into an adjustment factory service.

@tristanbes
Copy link
Contributor

Thank you for adding this feature @Zales0123 👍

@Zales0123
Copy link
Member Author

@tristanbes My pleasure ;) Hope, that together with other tax-related features and whole order logic refactoring it will be useful and powerful solution.

@michalmarcinkowski
Copy link
Contributor

@Zales0123 required rebase, as it will make the review easier.


$percentageAmount = $taxRate->getAmountAsPercentage();
$taxAmount = $this->calculator->calculate($lastShipping->getAmount(), $taxRate);
$label = sprintf('%s (%s%%)', $taxRate->getName(), (float) $percentageAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to getLabel method on TaxRate model.

@michalmarcinkowski
Copy link
Contributor

I see it this way:

OrderTaxesApplicatorInterface

  • apply(OrderInterface $order)

OrderTaxesByZoneApplicatorInterface

  • apply(OrderInterface $order, ZoneInterface $zone)

and then two implementations of OrderTaxesByZoneApplicatorInterface:

  1. OrderItemsByZoneTaxesApplicator
  2. OrderShipmentByZoneTaxesApplicator

Then in OrderTaxesApplicator we have the following logic:

  1. Match zone
  2. $orderItemsByZoneTaxesApplicator->apply($order, $zone);
  3. $orderShipmentByZoneTaxesApplicator->apply($order, $zone);

@Zales0123 WDYT?

* @param OrderInterface $order
* @param ZoneInterface $zone
*/
protected function processUnitsTaxes(OrderInterface $order, ZoneInterface $zone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be extracted to OrderItemsByZoneTaxesApplicator

}

$units = $item->getUnits();
if ($units->isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (0 === $item->getQuantity())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for now but we need to rethink the behavior of isEmpty method on the order. Normally we should use it here, but it checks if there are any items.

/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class OrderItemsByZoneTaxesApplicator implements OrderTaxesByZoneApplicatorInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO better name OrderItemsTaxesByZoneApplicator

It should implement OrderItemsByZoneTaxesApplicatorInterface

@Zales0123 Zales0123 force-pushed the shipment-taxes branch 2 times, most recently from edc90a4 to 190369d Compare January 26, 2016 09:45
pjedrzejewski pushed a commit that referenced this pull request Jan 26, 2016
@pjedrzejewski pjedrzejewski merged commit 336b1ba into Sylius:master Jan 26, 2016
@pjedrzejewski
Copy link
Member

Wooo, great work Mateusz! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants