-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 2.1.2 with new override and selection of tax rule
- Loading branch information
Showing
8 changed files
with
208 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
} |
Oops, something went wrong.