Page 1 of 2
Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 12:55 pm
by bitit
Is there a way to request a tax code or VAT number in the customer registration form or guest checkout?
I thought about modifying the suburb module for this
Enrico
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 2:24 pm
by heatherbell
app.php/addons/supporters_code/s04e03_c ... ta_modules is a pack of customer data modules, maybe something there would be a good basis for your requirement.
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 2:52 pm
by bitit
ok, thank you , i'll look it
Enrico
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 2:55 pm
by ecartz
Question is probably the closest, but is meant to be renamed before use.
There've probably been several people who have done this. Just none who contributed the working product back.
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 7:27 pm
by bitit
department, with changing translations work fine; i have also try to create a new module with relative translation, but i have a error that not understand; maybe is just more complicate, but i have just try.
this is the error:
Code: Select all
Uncaught Error: Undefined constant "ENTRY_DEPARTMENT" in /archivio/html/mysite.it/shoes/includes/modules/customer_data/cd_taxcode.php:87\nStack trace:\n#0 /archivio/html/mysite.it/shoes/templates/default/includes/pages/create_account.php(51): cd_taxcode->display_input()\n#1 /archivio/html/mysite.it/shoes/create_account.php(43): require('...')\n#2 {main}\n thrown in /archivio/html/mysite.it/shoes/includes/modules/customer_data/cd_taxcode.php on line 87, referer: http://localhost/mysite.it/shoes/
this is the code of cd_taxcode.php
Code: Select all
class cd_taxdata extends abstract_customer_data_module {
const CONFIG_KEY_BASE = 'MODULE_CUSTOMER_DATA_TAXCODE_';
const PROVIDES = [ 'taxcode' ];
const REQUIRES = [ ];
public function install($parameter_key = null) {
$structure_query = $GLOBALS['db']->query("SHOW COLUMNS FROM address_book LIKE 'entry_taxcode'");
if (!mysqli_num_rows($structure_query)) {
$GLOBALS['db']->query("ALTER TABLE address_book ADD entry_taxcode VARCHAR(255)");
}
parent::install($parameter_key);
}
protected function get_parameters() {
return [
static::CONFIG_KEY_BASE . 'STATUS' => [
'title' => 'Enable tax code module',
'value' => 'True',
'desc' => 'Do you want to add the module to your shop?',
'set_func' => "Config::select_one(['True', 'False'], ",
],
static::CONFIG_KEY_BASE . 'GROUP' => [
'title' => 'Customer data group',
'value' => '4',
'desc' => 'In what group should this appear?',
'use_func' => 'customer_data_group::fetch_name',
'set_func' => 'Config::select_customer_data_group(',
],
static::CONFIG_KEY_BASE . 'REQUIRED' => [
'title' => 'Require tax code module (if enabled)',
'value' => 'False',
'desc' => 'Do you want the tax code to be required in customer registration?',
'set_func' => "Config::select_one(['True', 'False'], ",
],
static::CONFIG_KEY_BASE . 'MIN_LENGTH' => [
'title' => 'Minimum Length',
'value' => '3',
'desc' => 'Minimum length of tax code',
],
static::CONFIG_KEY_BASE . 'PAGES' => [
'title' => 'Pages',
'value' => 'address_book;checkout_new_address',
'desc' => 'On what pages should this appear?',
'set_func' => 'Customers::select_pages(',
'use_func' => 'abstract_module::list_exploded',
],
static::CONFIG_KEY_BASE . 'SORT_ORDER' => [
'title' => 'Sort Order',
'value' => '3400',
'desc' => 'Sort order of display. Lowest is displayed first.',
],
static::CONFIG_KEY_BASE . 'TEMPLATE' => [
'title' => 'Template',
'value' => 'includes/modules/customer_data/cd_whole_row_input.php',
'desc' => 'What template should be used to surround this input?',
],
];
}
public function get($field, &$customer_details) {
switch ($field) {
case 'taxcode':
if (!isset($customer_details[$field])) {
$customer_details[$field] = $customer_details['taxcode']
?? $customer_details['entry_taxcode'] ?? null;
}
return $customer_details[$field];
}
}
public function display_input($customer_details = null) {
$label_text = ENTRY_TAXCODE;
$input_id = 'inputTaxcode';
$input = new Input('taxcode', ['id' => $input_id, 'placeholder' => ENTRY_TAXCODE_TEXT]);
if (!empty($customer_details) && is_array($customer_details)) {
$input->set('value', $this->get('taxcode', $customer_details));
}
if ($this->is_required()) {
$input->require();
$input = "$input" . FORM_REQUIRED_INPUT;
}
include $GLOBALS['Template']->map(MODULE_CUSTOMER_DATA_TAXCODE_TEMPLATE);
}
public function process(&$customer_details) {
$customer_details['taxcode'] = Text::input($_POST['taxcode']);
if (strlen($customer_details['taxcode']) < MODULE_CUSTOMER_DATA_TAXCODE_MIN_LENGTH
&& ($this->is_required()
|| !empty($customer_details['taxcode'])
)
)
{
$GLOBALS['messageStack']->add_classed(
$GLOBALS['message_stack_area'] ?? 'customer_data',
sprintf(ENTRY_TAXCODE_ERROR, MODULE_CUSTOMER_DATA_TAXCODE_MIN_LENGTH));
return false;
}
return true;
}
public function build_db_values(&$db_tables, $customer_details, $table = 'both') {
Guarantor::guarantee_subarray($db_tables, 'address_book');
$db_tables['address_book']['entry_taxcode'] = $customer_details['taxcode'];
}
public function build_db_aliases(&$db_tables, $table = 'both') {
Guarantor::guarantee_subarray($db_tables, 'address_book');
$db_tables['address_book']['entry_taxcode'] = 'taxcode';
}
}
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 7:33 pm
by bitit
if i have success to create this module, this is should be the first step to create others two modules, 1 for italian electronic invoice, 2 for certificated mail
Re: Tax code or VAT number, in the customer registration form
Posted: Tue Mar 26, 2024 8:16 pm
by ecartz
Department exists at the address level. Do you want VAT at the address level or the customer level?
The Error is saying that you're missing from the language file
Code: Select all
const ENTRY_DEPARTMENT = 'Department';
Are you sure that you're still getting that error? Changing line 87 to ENTRY_TAXCODE should have fixed it, and it looks like you already did that.
Re: Tax code or VAT number, in the customer registration form
Posted: Wed Mar 27, 2024 8:35 am
by bitit
a cache problem, working fine, only change the first line from:
Code: Select all
class cd_taxdata extends abstract_customer_data_module {
to
Code: Select all
class cd_taxcode extends abstract_customer_data_module {
in attach the full package .
can i add to my addons?
Re: Tax code or VAT number, in the customer registration form
Posted: Mon May 06, 2024 6:54 pm
by bitit
hi every one, i need adding tax id code to invoice and order process email notification.
what i must edit for it?
Enrico
Re: Tax code or VAT number, in the customer registration form
Posted: Tue May 07, 2024 5:59 am
by heatherbell