Mooon Posted July 14, 2011 Share Posted July 14, 2011 EU VAT has been quite discussed here but my client need is a mix of the threads I've seen. Prestashop 1.4 may bring solutions but obviously, theme and plugins have been bought for 1.3.7 and budget is empty.Here is the need :[*] The website is b2b : only pro customers[*] there is a minimum amount for order[*] we want customers that enter EU VAT Number (in DNI field) to be VAT free and transport free[*] customers without DNI filled are charged VAT of the shop country and transport by weightHere is how I see it :[*] Customer registering without DNI stays in default group for taxes, and in zone with pay carrier[*] Customer registering with DNI is assigned to special group only and has only free carrier available[*] AND[*] Customer changing DNI in his account have also same effects.Uf !FIRST STEP is unlocking the DNI registration based on this EU VAT ThreadIn classes classes/validate.php I tried regexp based on a code seen somewhere to validate number form (by the way it's certainly bugged so if you have improvement) Replace : if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $dni)) By : if (!preg_match('/^(RO[0-9]{2,10}|GB[0-9]{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)[0-9]{8}|IE[A-Z0-9]{8}|(DE|BG|EE|EL|LT|BE0| PT|CZ)[0-9]{9}|CY[0-9]{8}[A-Z]|(ES|GB)[A-Z0-9]{9}|(BE0|PL|SK|CZ)[0-9]{10}|(FR|IT|LV)[0-9]{11}|(LT|SE)[0-9]{12}| (NL|GB)[A-Z0-9]{12})$/', $dni)) Then I tried to assign customer with DNI to a free tax group in authentification.php, based on same thread : else { if (Tools::getValue('dni') != '') $customer->addGroups(array(2)); $address->id_customer = intval($customer->id); at registration customer goes to the good group, but prices in order doesn't change. I haven't tested yet this solution but it seems to be the same.SECOND STEP is configuring into admin- Payment / taxes : two taxes (one at 0), both on the same zones... (delivery zones by weight)- Shipping : 2 carriers, one with prices by weight and zone, other with weight and 0 price for each zone- Shipping / carrier : one is tax included other is tax excludedDNI or not DNI, taxes doesn't show up !THIRD STEP is making shipping free if DNI filled, based on this : if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration ['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 AND $id_zone==6) return $shipping_cost; I tried to adapt : if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0 AND intval($id_carrier) == 2 AND ((intval($id_zone) == 6 OR intval($id_zone) == 18) && Tools::getValue('dni') != '')) Doesn't work and I don't have idea on how to get DNI here. I tried to adapt a solution based on address validation :add anywhere in classes/customer.php static public function getDni($id_customer) { $result = Db::getInstance()->getRow(' SELECT `dni` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.intval($id_customer)); return isset($result['dni']) ? $result['dni'] : false; } order.php (root) around l.320 [b]under :[/b] function displayCarrier() { global $smarty, $cart, $cookie, $defaultCountry, $link; $address = new Address (intval($cart->id_address_delivery)); $id_zone = Address::getZoneById(intval($address->id)); [b]Add[/b] $dni = Address::getDni($customer->id); in order-carrier.tpl [b]Replace[/b] <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier| intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)} checked="checked"{/if} /> By {if $carrier.id_carrier=='2'} {if $dni != ''} <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)}checked="checked"{/if} /> {else}- {/if} {else} <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier {$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers| @sizeof == 1)}checked="checked"{/if} /> {/if} And around l.380 after $smarty->assign(array( add 'dni' => $dni, // EU VAT I have more code and options, but I'd like to debate a little beforeSo, I know I won't have all the answers (but hope some), but my brain really needs fresh eye to tell me what is wrong. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now