0

I have to verify, at registration if the User reported an tax/vat that is already registered in the database, so I avoid a User register twice.

I not found a module for this, so plan to do this check via ajax.jquery.

To do so, I need a page to query the database looking for a tax/vat.

I do not know if this is the best way to do it. But I know little about magento, then that is what come to mind.

In entando still do not know how to do this query on the bench and not getting success with in my search for tutorials, etc..

you reading this, could you help me somehow? with materials, articles, tips, examples?

Thank you for your attention.

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.