I did this validation in a way that I know is not the most accurate. I did so:
Note: I use One Step Checkout module Brazil and Youama Ajax Login and Register, in which adcionei some fields in the record, as taxvat. Probably this will not be useful to anyone else, but did not want to leave the question unanswered.However, if anyone has any other suggestions, please tell me, I'll be grateful.
1 - First Step :
In app/code/core/Mage/Page/etc/config.xml
add:
<checktaxvat module="page" translate="label">
<label>Check taxvat</label>
<template>page/checktaxvat.phtml</template>
<layout_handle>page_checktaxvat</layout_handle>
</checktaxvat>
2 - Second Step:
So create a new document with the following code :
<?php
$requi = $_SERVER["HTTP_REFERER"];
$requi= strtolower("/$requi/"); //
$server = $_SERVER['SERVER_NAME'];
$server= strtolower("/$server/");
if(preg_match($server, $requi) == 0){
header("Location: http://www.url");
die();
}
if(isset($_POST) && isset($_POST['taxvat']) && $_POST['taxvat'] != ""){
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
if(isset($_POST['taxvatAt']) && $_POST['taxvatAt'] != ""){
$qry = "SELECT * FROM customer_entity_varchar WHERE `value` = '".addslashes($_POST['taxvat'])."' AND `value` != '".addslashes($_POST['taxvatAt'])."'";
}else{
$qry = "SELECT * FROM customer_entity_varchar WHERE `value` = '".addslashes($_POST['taxvat'])."'";
}
$res = $read->fetchAll($qry);
//$result = $read->fetchAll($sql);
$total_rows = count($res);
if($total_rows > 0){
echo 0;
}else{
echo 1;
}
}else{
echo "null";
}
die;
?>
save in app/design/frontend/default/magento-bootstrap/template/page/checktaxvat.phtml
3 - Step Three :
Magento admin - > CMS - > Pages - > Add new Page
In Information Page : Page Title = Check taxvat Key URL = checktaxvat
In design : Check taxvat = Check taxvat
then save to create the page
4 - Fourth Step
In app/design/frontend/base/default/template/youama/ajaxlogin/ajaxlogin.phtml
Added code
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("input[name=youama-taxvat]").focusout(function() {
jQuery.ajax({
type: "POST",
data: {'taxvat': jQuery("input[name=youama-taxvat]").val()},
url: "http://url/checktaxvat",
success: function (data) {
if(data == 0){
alert("taxvat já cadastrado!");
jQuery("input[name=youama-taxvat]").val("");
}
}
});
});
});
</script>
5 - Step Five
In app/design/frontend/base/default/template/onepagecheckout/persistent/customer/form/edit.phtml
Added code
<script type="text/javascript">
jQuery(document).ready(function(){
taxvatAt = "<?php echo $this->htmlEscape($this->getCustomer()->getTaxvat()) ?>";
jQuery("input[name=taxvat]").focusout(function() {
jQuery.ajax({
type: "POST",
data: {'taxvat': jQuery("input[name=taxvat]").val(), 'taxvatAt': "<?php echo $this->htmlEscape($this->getCustomer()->getTaxvat()) ?>"},
url: "http://url/checktaxvat",
success: function (data) {
if(data == 0){
alert("taxvat já cadastrado!");
jQuery("input[name=taxvat]").val("");
}
}
});
});
});
</script>
6 - Step Six
In app/design/frontend/base/default/template/onepagecheckout/onepage/billing.phtml
Added code
<script type="text/javascript">
jQuery(document).ready(function(){
if(typeof taxvatAt=='undefined'){
taxvatAt = "<?php echo $this->htmlEscape($this->getCustomer()->getTaxvat()) ?>";
}
jQuery.ajax({
type: "POST",
data: {'taxvat': jQuery("input[name='billing[taxvat]']").val(), 'taxvatAt': taxvatAt },
url: "http://url/checktaxvat",
success: function (data) {
if(data == 0){
alert("taxvat já cadastrado!");
jQuery("input[name='billing[taxvat]']").val("");
}
}
});
});
</script>
7 - Step Seven
In skin/frontend/base/default/js/onepagecheckout.js
BillingAddress.prototype locates and replaces the function newAddress by:
newAddress: function (isNew) {
if (isNew) {
this.resetSelectedAddress();
Element.show('bill_form');
if(jQuery("input[name='billing[taxvat]']").val() !=""){
taxvatAt = jQuery("input[name='billing[taxvat]']").val();
}
} else {
Element.hide('bill_form');
}
}
well, that solved my problem, but I am conscious that it is not right way to do it, but as my knowledge of magento are small, was what I could do.