-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add dynamic shipping tax calculation #176
Conversation
@@ -55,3 +55,5 @@ SWIFT,SWIFT | |||
"CMS Page for Shipping Info","CMS-Seite für Versandkosten" | |||
"Show ""incl. Shipping Cost"" instead of ""excl. Shipping Cost""","Zeige ""inkl. Versandkosten"" anstatt ""exkl. Versandkosten""" | |||
"Display Delivery Time on Product Listing","Lieferzeit auf Produktübersichtsseiten anzeigen" | |||
"No dynamic shipping tax calculation","Keine dynamische Versandsteuerberechnung" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please re-generate the English language file and then edit the German file. Hint:
n98-magerun2.phar i18n:collect-phrases -o app/code/FireGento/MageSetup/i18n/en_US.csv app/code/FireGento/MageSetup/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you re-generated the English file. Great! Now IMHO, we need to update the German file accordingly (add the strings to the position similar to the EN file, not at the end of the file).
composer.json
Outdated
"magento/module-store": "*", | ||
"magento/module-backend": "*", | ||
"magento/framework": "*" | ||
"php": "~7.1.0|~7.2.0|~7.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this to ~7.2.0||~7.3.0
.
@@ -8,7 +8,9 @@ | |||
namespace FireGento\MageSetup\Plugin\Email\Model\Source; | |||
|
|||
/** | |||
* Plugin to add additional config variables to be inserted into emails. | |||
* Class Variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change.
Model/Config.php
Outdated
@@ -13,6 +13,9 @@ | |||
*/ | |||
class Config implements ConfigInterface | |||
{ | |||
public const DYNAMIC_TYPE_DEFAULT = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be more specific (saying that this is related to the shipping tax). Additionally, what do you think of putting them to the source model directly?
/** | ||
* @var array | ||
*/ | ||
protected $options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to private
.
|
||
class ShippingTaxPlugin | ||
{ | ||
public const CONFIG_PATH_DYNAMIC_SHIPPING_TAX_CLASS = 'tax/classes/dynamic_shipping_tax_class'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a new method in the Config
model for retrieving this configuration and use it.
Cart $cart, | ||
Session $customerSession, | ||
GroupRepository $groupRepository, | ||
Proxy $taxCalculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not depend on a proxy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Plugin does not have a around method. I think the plugin will not work in general.
@BorisovskiP, please also check the failing build (probably code style issues). |
*/ | ||
public function getDynamicShippingConfigPath(): string | ||
{ | ||
return self::CONFIG_PATH_DYNAMIC_SHIPPING_TAX_CLASS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this adds much value. I think we should add a new method in \FireGento\MageSetup\Model\System\Config
, which returns the actual configuration value of that option.
* | ||
* @return bool|mixed|null | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line.
"magento/module-store": "*", | ||
"magento/module-backend": "*", | ||
"magento/framework": "*" | ||
"php": "~7.2.0|~7.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the formatting.
@@ -55,3 +55,5 @@ SWIFT,SWIFT | |||
"CMS Page for Shipping Info","CMS-Seite für Versandkosten" | |||
"Show ""incl. Shipping Cost"" instead of ""excl. Shipping Cost""","Zeige ""inkl. Versandkosten"" anstatt ""exkl. Versandkosten""" | |||
"Display Delivery Time on Product Listing","Lieferzeit auf Produktübersichtsseiten anzeigen" | |||
"No dynamic shipping tax calculation","Keine dynamische Versandsteuerberechnung" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you re-generated the English file. Great! Now IMHO, we need to update the German file accordingly (add the strings to the position similar to the EN file, not at the end of the file).
*/ | ||
class Dynamic implements OptionSourceInterface | ||
{ | ||
public const DYNAMIC_TYPE_SHIPPING_TAX_DEFAULT = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe DYNAMIC_SHIPPING_TAX_NO
?
class Dynamic implements OptionSourceInterface | ||
{ | ||
public const DYNAMIC_TYPE_SHIPPING_TAX_DEFAULT = 0; | ||
public const DYNAMIC_TYPE_HIGHEST_PRODUCT_TAX = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe DYNAMIC_SHIPPING_TAX_HIGHEST_PRODUCT_TAX
?
* @throws \Magento\Framework\Exception\LocalizedException | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
private function getTaxPercent(int $productTaxClassId, $store): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returnType of the rate is float, not int
$group = $this->groupRepository->getById($groupId); | ||
$customerTaxClassId = $group->getTaxClassId(); | ||
|
||
$request = $this->taxCalculation->getRateRequest(null, null, $customerTaxClassId, $store); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not actually set in the constructor.
I'm using a module based on this, but I encounter a loop for the payment methods. I think the collections of the tax percentage might trigger the plugin again, so I added a static variable that prevents loops (doesn't run on nested calls). Not sure if thats always required. Also it seems the lower method is never called to get the tax percentage. At least it's not functioning right now, not sure if the fallback is needed at all? |
Hi Magesetup2 Team and all who are looking for a solution, as a suggestion you could use this extension https://github.com/JaJuMa-GmbH/magento-2-dynamic-shipping-tax |
Please make sure these boxes are checked before submitting your PR - thank you!
Issue
This PR fixes issue #22 .
Proposed changes
...