Skip to content

Commit

Permalink
Update to 2.1.2 with new override and selection of tax rule
Browse files Browse the repository at this point in the history
  • Loading branch information
NKoonen committed Jun 19, 2024
1 parent 5172c54 commit 6a1f536
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 148 deletions.
9 changes: 4 additions & 5 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>vatchecker</name>
<displayName><![CDATA[Vat Checker]]></displayName>
<version><![CDATA[2.1.0]]></version>
<description><![CDATA[Check if a customers VAT number is valid and gives the customer 0 tax if the customer is not in from country.]]></description>
<displayName><![CDATA[VAT Checker]]></displayName>
<version><![CDATA[2.1.2]]></version>
<description><![CDATA[The module verifies whether a customer possesses a valid VAT EU number through the VIES VAT online service. Upon validation, it automatically applies a 0% tax rate to customers from the EU who are not from the same country as the shop.]]></description>
<author><![CDATA[Inform-All & Keraweb]]></author>
<tab><![CDATA[billing_invoicing]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
</module>
54 changes: 54 additions & 0 deletions override/classes/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

class Product extends ProductCore
{
public static function getIdTaxRulesGroupByIdProduct( $id_product, Context $context = null )
{
if ( ! $context ) {
$context = Context::getContext();
}
if(!empty($context->cart->id_address_delivery))
{
$delivery_address = new Address( $context->cart->id_address_delivery );
}else{
$delivery_address = false;
}

$key = 'product_id_tax_rules_group_' . (int) $id_product . '_' . (int) $context->shop->id;

if ( $delivery_address ) {
/** @var Vatchecker $vatchecker */
$vatchecker = Module::getInstanceByName( 'vatchecker' );
if ( $vatchecker && $vatchecker->canOrderWithoutVat( $delivery_address ) ) {
// VatChecker module is used.
$skipProduct = Db::getInstance()->getRow(
'SELECT `id_product`
FROM `' . _DB_PREFIX_ . 'vatchecker_excluded_products`
WHERE `id_product` =' . (int) $id_product
);
if ( empty($skipProduct) ) {
$taxRuleGroupId = Configuration::get( 'VATCHECKER_TAXRATE_RULE' );
if ( ! Cache::isStored( $key ) ) {
Cache::store( $key, (int) $taxRuleGroupId );
}

return (int) $taxRuleGroupId;
}
}
}

if ( ! Cache::isStored( $key ) ) {
$result = Db::getInstance( _PS_USE_SQL_SLAVE_ )->getValue(
'
SELECT `id_tax_rules_group`
FROM `' . _DB_PREFIX_ . 'product_shop`
WHERE `id_product` = ' . (int) $id_product . ' AND id_shop=' . (int) $context->shop->id
);
Cache::store( $key, (int) $result );

return (int) $result;
}

return Cache::retrieve( $key );
}
}
64 changes: 0 additions & 64 deletions override/classes/tax/TaxRulesTaxManager.php

This file was deleted.

34 changes: 0 additions & 34 deletions override/classes/tax/index.php

This file was deleted.

2 changes: 1 addition & 1 deletion upgrade/upgrade-2.1.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

/**
* This function updates your module from previous versions to the version 1.1,
* This function updates your module from previous versions to the version 2.1.0,
* usefull when you modify your database, or register a new hook ...
* Don't forget to create one file per version.
*/
Expand Down
25 changes: 25 additions & 0 deletions upgrade/upgrade-2.1.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
if ( ! defined( '_PS_VERSION_' ) ) {
exit;
}

/**
* This function updates your module from previous versions to the version 2.1.2,
* usefull when you modify your database, or register a new hook ...
* Don't forget to create one file per version.
*/
function upgrade_module_2_1_2( $module )
{
$module->uninstallOverrides();
$module->installOverrides();
Configuration::updateValue('VATCHECKER_TAXRATE_RULE', null );
$module->registerHook('displayAdminProductsMainStepLeftColumnMiddle');
$module->registerHook('actionProductUpdate');

return Db::getInstance()->Execute(
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'vatchecker_excluded_products' . '` (
`id_product` INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(`id_product`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'
);
}
Loading

0 comments on commit 6a1f536

Please sign in to comment.