Jump to content

MarcoPLY

Members
  • Content Count

    244
  • Joined

  • Last visited

Community Reputation

53 Excellent

1 Follower

About MarcoPLY

  • Rank
    Sr. Member
  • Birthday 05/08/1987

Profile Information

  • Gender
    Male
  • Location
    Reggio Emilia

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi guys, I try to set up the option values for the options fields. Like it's write here: https://processwire.com/docs/fields/select-options-fieldtype/#separate-option-values EG: I write 123=IT|Italy and render the option value <option value="IT">Italy</option>. I read that need to use $option->value. But I would like to step up a hook to show the custom value when this value exists, otherwise continue to show the ID. Is it possible? I try to work around FieldtypeOptions::formatValue(), but I don't know how setup this hook and if it is the correct way to do it.
  2. Hi, I need to check the VAT number before the user make a registration. I start from here https://github.com/herdani/vat-validation, and this work well. But now I have to integrate this with the LoginRegister module, I'm not sure who do it, at moment I try to make the hook in this way: wire()->addHookAfter('LoginRegister::processRegisterForm', function ($event) { $form = $event->arguments[0]; $company = wire('input')->post->register_Iam; // check if you are a person or a company if ($company == '2') { // Get country code $options = wire('fieldtypes')->get('FieldtypeOptions')->getOptions(wire('fields')->get('shipping_countrycode')); foreach ($options as $value) { if(wire('input')->post->register_shipping_countrycode == $value->id) { $country_title = $value->title; $countryCode = substr($country_title, 0, 2); } } // Get VAT number $vatNumber = wire('input')->post->register_invoice_VAT; $check = new WireFileTools(); $check->include('vatValidation.class.php'); $vatValidation = new vatValidation( array('debug' => false)); $vatValidation->check($countryCode, $vatNumber); if ($vatValidation->isValid()) { return true; } else { $vatError = 'this VAT N° does not exist'; $vatNumber->error($vatError); } } }); I'm not sure but I think that everything works well until validation. How I can add the verification system? I feel like one of the problem is adding the vatValidation.class.php file in the hook. But I can't debug well this. I try to follow this post. Also I read the problem could be a namespace in the vatValidation.class file. But also, I'm not sure. vatValidation.class.php UPDATE I try also to use this $company = wire('input')->post->register_Iam; if ($company == '2'){ // Get country code $options = wire('fieldtypes')->get('FieldtypeOptions')->getOptions(wire('fields')->get('shipping_countrycode')); foreach ($options as $value) { if(wire('input')->post->register_shipping_countrycode == $value->id) { $country_title = $value->title; $countryCode = substr($country_title, 0, 2); } } // Get VAT number $vatNumber = wire('input')->post->register_invoice_VAT; function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) { $response = array (); $pattern = '/<(%s).*?>([\s\S]*)<\/\1/'; $keys = array ( 'countryCode', 'vatNumber', 'requestDate', 'valid', 'name', 'address' ); $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'> <s11:Body> <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'> <tns1:countryCode>%s</tns1:countryCode> <tns1:vatNumber>%s</tns1:vatNumber> </tns1:checkVat> </s11:Body> </s11:Envelope>"; $opts = array ( 'http' => array ( 'method' => 'POST', 'header' => "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService", 'content' => sprintf ( $content, $countryCode, $vatNumber ), 'timeout' => $timeout ) ); $ctx = stream_context_create ( $opts ); $result = file_get_contents ( 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService', false, $ctx ); if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) { foreach ( $keys as $key ) preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) && $response [$key] = $value [2]; } return $response; } $arr = viesCheckVAT($countryCode, $vatNumber); if ($arr[valid] == fasle) { ... } } This probably are better, but I'm not able to integrate with the validation of the module. ONE SOLUTION In the end I failed to make the hook as I wanted. So I thought I'd check the VAT before the module registered the user. Ok maybe it's not the best solution but it works. So, with the help of one person, we started from the PHP function I posted above, changing it this way: We sent a request via Ajax, this is activated when data is entered the input, this call via curl and returns a value that, following the logic in this case with a nice callback, enables or disables the send button <?php if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['task'] ) && $_POST['task']=='check' ){ ob_clean(); $result=null; function curl( $url=NULL, $options=NULL, $headers=false ){ /* Initialise curl request object */ $curl=curl_init(); /* Define standard options */ curl_setopt( $curl, CURLOPT_URL,trim( $url ) ); curl_setopt( $curl, CURLOPT_AUTOREFERER, true ); curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $curl, CURLOPT_FAILONERROR, true ); curl_setopt( $curl, CURLOPT_HEADER, false ); curl_setopt( $curl, CURLINFO_HEADER_OUT, false ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true ); curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 20 ); curl_setopt( $curl, CURLOPT_TIMEOUT, 60 ); curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' ); curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 ); curl_setopt( $curl, CURLOPT_ENCODING, '' ); /* Assign runtime parameters as options */ if( isset( $options ) && is_array( $options ) ){ foreach( $options as $param => $value ) curl_setopt( $curl, $param, $value ); } if( $headers && is_array( $headers ) ){ curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers ); } /* Execute the request and store responses */ $res=(object)array( 'response' => curl_exec( $curl ), 'info' => (object)curl_getinfo( $curl ), 'errors' => curl_error( $curl ) ); curl_close( $curl ); return $res; } function checkvat( $code, $vatnumber, $timeout=30 ){ $url='http://ec.europa.eu/taxation_customs/vies/services/checkVatService'; $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'> <s11:Body> <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'> <tns1:countryCode>%s</tns1:countryCode> <tns1:vatNumber>%s</tns1:vatNumber> </tns1:checkVat> </s11:Body> </s11:Envelope>"; $headers=array( 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'checkVatService' ); $options=array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => sprintf ( $content, $code, $vatnumber ) ); return curl( $url, $options, $headers ); } $code=$_POST['code']; $vatnumber=$_POST['vat']; /* check the VAT number etc */ $obj=checkvat( $code, $vatnumber ); /* if we received a valid response, process it */ if( $obj->info->http_code==200 ){ $dom=new DOMDocument; $dom->loadXML( $obj->response ); $reqdate=$dom->getElementsByTagName('requestDate')->item(0)->nodeValue; $valid=$dom->getElementsByTagName('valid')->item(0)->nodeValue; $address=$dom->getElementsByTagName('address')->item(0)->nodeValue; if ($valid == "true") { $result = "<p style='background-color: #fff;width: 30%;color:green;position: absolute;'>Valid Number</p>"; } else { $result = "<p style='background-color: #fff;width: 30%;color:red;position: absolute;'>Not Valid Number</p>"; } } exit( $result ); } ?> <script> const ajax=function( url, params, callback ){ let xhr=new XMLHttpRequest(); xhr.onload=function(){ if( this.status==200 && this.readyState==4 )callback( this.response ) }; xhr.open( 'POST', url, true ); xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); xhr.send( buildparams( params ) ); }; const buildparams=function(p){/* construct payload/querystring from object */ if( p && typeof( p )==='object' ){ p=Object.keys( p ).map(function( k ){ return typeof( p[ k ] )=='object' ? buildparams( p[ k ] ) : [ encodeURIComponent( k ), encodeURIComponent( p[ k ] ) ].join('=') }).join('&'); } return p; }; document.addEventListener('DOMContentLoaded', ()=>{ let form = document.getElementById('LoginRegisterForm'); form.register_invoice_IVA_VAT.addEventListener('keyup', e=>{ let url=location.href; let params={ 'task':'check', 'vat': form.register_invoice_IVA_VAT.value, 'code':'IT' /*need to hook the select filed because now return the ID number*/ }; let callback=function(r){ let vatF = document.getElementById('register_invoice_IVA_VAT'); var thisreturn = r.includes("Not"); var divNew = document.createElement("div"); divNew.innerHTML = r; if (thisreturn == false) { vatF.classList.add('success'); vatF.classList.remove('error'); document.getElementById("register_submit").disabled = false; document.getElementById('wrap_register_invoice_IVA_VAT').appendChild(divNew); } else { vatF.classList.add('error'); vatF.classList.remove('success'); document.getElementById("register_submit").disabled = true; document.getElementById('wrap_register_invoice_IVA_VAT').appendChild(divNew); } } ajax.call( this, url, params, callback ); }) }); </script> So, I didn't make the hard coding part to be complete honest I ask in stackoverflow here, but anyway I want also add this post here if anyone in this form needed it, it can be a starting point. (Maybe could be a interesting features for the new Padloper or some ecosystm module @kongondo)
  3. Wow super! The API system look amazing! I know you still have to tell us many things, like how works the discounts, users management, shipments, payments, etc. But I will like ask a few things The API system for get the $order data will change? eg: At the moment I am using the success page or the checkout page to send the order data to external platforms such as our management, Mailchimp, google analytic etc. Will it be possible to continue doing it from there? I see there is the discount page, but also will be possible to change the price in the shopping cart based on the items loaded? eg: discounts based on quantity. Will it be possible to do this as a backend or do it with a separate hook? Will it be possible to choose the type of shipment in the checkout process? eg: normal, super fast... A curiosity, are you also creating new payment module? I think that ProcessWire has the potential to become the cms with the best e-commerce system around!
  4. Hi, I need to check the VAT number before the user make a registration. I find a good service for check the number, now I have to integrate with the module. I'm not sure what doing. I open a different post here
  5. I am looking in the forum for a solution but I didn't find it. I redirect people based on their browser language, with I use this code (that I grab somewhere in the forum): foreach($languages as $language) { if(strpos($config->httpHost, "$language->site.it") === 0) { $user->language = $language; break; } } $name = $sanitizer->pageName(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));; $language = $languages->get($name); if($language->id && $name != $user->language->name) { $url = "https://www.site.it" . $page->localUrl($language); $session->redirect($url); } Now the problem is that: the users can't change the language because they are always redirected to theirs browser language. I would like to let the users change the language. I try to work around Session class, I thought of enabling redirection only on first arrival, but I don't know how to do it. Maybe I have to work with the cookies? I'm not sure about what I can do. I find this post, but I will not use this module but incorporate within my _func.php file, because before to get to the language selection I have other statements. If I have understand well he used this part to make the redirect only in first session, but I'm not sure how can I integrate this // Set some session variables then redirect $this->session->languageAlreadyDetected = true; if (wire('user')->language->name != $matchedLanguage AND !isset(wire('input')->get->{$this->noDetectGetParam})) { $this->session->redirect($page->localUrl($matchedLanguage), false); } MY SOLUTION: probably not the best solution, but it works // set the cookie expire after 5 min, I know is not the best because after 5 min the user not load page is forced to change language, // but the average time of a session is that and in this way I'm sure if the user cameback there isn't this cookie $user_is_first_timer = !isset( $_COOKIE["FirstTimer"] ); setcookie( "FirstTimer", 1, time() + (60 * 5) ); if( $user_is_first_timer ){ foreach($languages as $language) { if(strpos($config->httpHost, "$language->playwood.it") === 0) { $user->language = $language; break; } } $name = $sanitizer->pageName(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));; $language = $languages->get($name); if($language->id && $name != $user->language->name) { $url = "https://www.site.com" . $page->localUrl($language); $session->redirect($url); }
  6. Hi Kongondo, at moment for us the Multilingual Text Fields and the Type Options Fields works well. Maybe I wrong but perhaps the multilingual system should be something that is about the website. But sure the new Padloper must be ready to accept the multilingual version. Thank you and good work!
  7. Hi guys, sorry I don't have understood well how works the fingerprint. I have the same issue because our IP address cloud change during the session, so I have to change the setting. But I'm not sure which option use. What exactly do the fingerprint?
  8. Hi @flydev, I'm sorry you're sick. Honestly I don't know why there is this error, but if I can help, yes I use LoginRegister module, my code it's nothing particular. This problem show up in every registration from on the website, also in the subdomain with other installation that share the wire core folder.
  9. Could be a bug in the new version 3.0.125 ? Before that I update from the 3.0.098 this error doesn't show up. I have see that in the 3.0.098 and 3.0.123 this part was commented. protected function sendCURL($url, $method = 'POST', $options = array()) And in the function that give me the error at 640 row of WireHttp. I have downgraded to the version 3.0.123 and now on the registration form works.
  10. Hi, Sometime people that try to make the registration can't do and in the page load a server error 500. In the log Exceptions I see this alert: Raw data option with CURL not supported for PATCH (in /wire/core/WireHttp.php line 670) What kind of error is? and how can I solve it? Thank you.
  11. Hi @Zeka... thank you, yes the problem was that doesn't show up the file in the list. But I found the solution just now: In the end on the page there is a button: "Refresh File List" Just press that button! I didn't before because look like with disable class but it works. Now the list it's update.
  12. When I prepare the strings for translation using __('strings') and usually in the Languages > Select File(s) appears the template, but I have a couple of templates that not show up in this section. These templates are like the others. Why can this happen?
  13. I have the same problem, but I can use the searching box for looking witch file is broken. Also I can't find any phrase-index.txt, where is exactly? Sorry @PWaddict, maybe you know. This problem about the live search could be the reason why after I added a new language it does not appear in the all URL segment ? I mean, I added French, and added fr in Languages Support - Page Names. In all pages the text input field for the French show up, but in the setting section missing all URL fr/link, there is only the link name, without the fr/ About the problem for the link I have fixed, I forgot to upload in the homepage the fr link. When you create the language to defeat in the homepage it's add the defeat language, I need to correct it by hand, even if you add the tag inside the page Languages Support - Page Names.
  14. Yes. I'm not sure how I'll approach it though. It's just an idea at the moment. Can we have something like ready-api.php page, with all the variable for use just like a endpoint for connect with the API of any carriers ? Could be a backend page where for each of our Padloper fields there are editable fields to connect with the carriers API. Also will be great if there are the fields for add the link of the carriers page where send the data. Or maybe could be just a page where there are a recap of our API + documentation and that in a separate php page we will write our code.
  15. Thanks a lot @flydev. Ok, so, I have to use wire() becasue the hook is ouside the class. and I need also call $pages = $event->object. But aren't the data store in the argument? why I have to call pages object? Unfortunately the hook does not work. I think now the problem is how access to the correct date to send to Mailchimp. The Dumps I see empty, but in the Logs page now I have the Login-Facebook and I can read: Created new user: name-surname then Updated user 'name-surname' fields: role:login-register, pad_firstname, pad_firstname, pad_lastname and then Used Facebook to login for user: name-surname There isn't the email, could this be the problem that does not generate the user in Mailchimp? But, on the user page the email has been added successfully, for this type of hook only need this, correct? I can't find anywhere bd($mc). I try also to use $email = $page->email; and $email = $this->wire('user')->email but but not work, also try $email = wire('input')->post->email I know the input post it's use only in the form but I just to try. Any Idea?
×
×
  • Create New...