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

fix: customer group discount tax #2757

Draft
wants to merge 1 commit into
base: 5.7
Choose a base branch
from

Conversation

Dominikrt
Copy link
Contributor

close #2608

1. Why is this change necessary?

Tax for Customer Group Discount can be 0%, currently there is a fallback for 19%

2. What does this change do, exactly?

check issue

3. Describe each step to reproduce the issue or behaviour.

check issue

4. Please link to the relevant issues (if any).

#2608

5. Which documentation changes (if any) need to be made because of this PR?

6. Checklist

  • I have written tests and verified that they fail without my change
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code
  • I have read the contribution requirements and fulfil them.

Copy link

github-actions bot commented Sep 8, 2024

Warnings
⚠️ The Pull Request doesn't contain any changes to the Upgrade file

@Dominikrt Dominikrt force-pushed the fix-customergroup-discount-tax branch from e92dd08 to 306dc0f Compare September 8, 2024 14:53
@Dominikrt Dominikrt force-pushed the fix-customergroup-discount-tax branch from 306dc0f to 8b09ee7 Compare September 8, 2024 14:54
@Dominikrt Dominikrt marked this pull request as draft September 8, 2024 15:09
Copy link
Contributor

@aragon999 aragon999 left a comment

Choose a reason for hiding this comment

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

I think I would make the check more explicit by explicitly checking that the tax is false. Maybe the if can also be moved into the if branch of the getMaxTax().

@@ -421,7 +421,7 @@ public function sInsertDiscount()
$tax = $this->config->get('sDISCOUNTTAX');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$tax = $this->config->get('sDISCOUNTTAX');
$tax = (int) $this->config->get('sDISCOUNTTAX');

Copy link
Contributor

Choose a reason for hiding this comment

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

is this the tax value? if so, it should definitely not be an integer, but a float instead

@@ -421,7 +421,7 @@ public function sInsertDiscount()
$tax = $this->config->get('sDISCOUNTTAX');
}

if (!$tax) {
if (!$tax && $tax != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!$tax && $tax != 0) {
if ($tax === false) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @aragon999 ,
this way looks much nicer, I wasn't sure, if there is another datatype that can trigger the fallback.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, the only case which needs to be handled is that getMaxTax() returns false.

It would still change the logic slightly, as when previously when the tax 0 has been configured in sDISCOUNTTAX the tax wont be 19 anymore. But that is I think in all cases like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also prefer a type safe comparison. but then we need to max sure, that $tax is really a float or false at this point.

additionally to that, I would like to remove the fallback to a hardcoded value 🙈

what do you think? throwing an exception or getting a tax value from somewhere else?

@@ -421,7 +421,7 @@ public function sInsertDiscount()
$tax = $this->config->get('sDISCOUNTTAX');
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the tax value? if so, it should definitely not be an integer, but a float instead

@@ -361,6 +367,40 @@ public function createTax(array $data = []): TaxModel
return $tax;
}

/**
* @param array<string, string|int|Customer|Group|bool> $data
Copy link
Contributor

Choose a reason for hiding this comment

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

an object shape array annotation would make more sense in this case

array{foo: string, bar: float}

}

/**
* @param array<string, string|int|Customer|Group|bool> $data
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

);

static::assertIsArray($discount);
static::assertSame(0, (int) $discount['tax_rate']);
Copy link
Contributor

Choose a reason for hiding this comment

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

tax rates should be floats!

@@ -421,7 +421,7 @@ public function sInsertDiscount()
$tax = $this->config->get('sDISCOUNTTAX');
}

if (!$tax) {
if (!$tax && $tax != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also prefer a type safe comparison. but then we need to max sure, that $tax is really a float or false at this point.

additionally to that, I would like to remove the fallback to a hardcoded value 🙈

what do you think? throwing an exception or getting a tax value from somewhere else?

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

Successfully merging this pull request may close these issues.

Static fallback to 19% in basket
3 participants