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

Add dynamic shipping tax calculation #176

Closed
wants to merge 3 commits into from

Conversation

BorisovskiP
Copy link

Please make sure these boxes are checked before submitting your PR - thank you!

  • Pull request is based against develop branch
  • README.md reflects changes (if applicable)
  • New files contain a license header

Issue

This PR fixes issue #22 .

Proposed changes

...

@sprankhub sprankhub self-requested a review June 28, 2020 12:59
@@ -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"
Copy link
Member

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/

Copy link
Member

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",
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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';
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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.

@sprankhub
Copy link
Member

@BorisovskiP, please also check the failing build (probably code style issues).

*/
public function getDynamicShippingConfigPath(): string
{
return self::CONFIG_PATH_DYNAMIC_SHIPPING_TAX_CLASS;
Copy link
Member

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
*/

Copy link
Member

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",
Copy link
Member

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"
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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

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);

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.

@barryvdh
Copy link

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?

@gino2014
Copy link

gino2014 commented Aug 7, 2022

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

@BorisovskiP BorisovskiP closed this Feb 9, 2024
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.

5 participants