Changeset 2395291
- Timestamp:
- 10/07/2020 02:11:10 PM (5 years ago)
- Location:
- officegest/trunk
- Files:
-
- 8 edited
-
officegest.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
src/Controllers/SyncEcoAuto.php (modified) (1 diff)
-
src/Controllers/SyncImagens.php (modified) (1 diff)
-
src/Crons.php (modified) (4 diffs)
-
src/Nif.php (modified) (9 diffs)
-
src/Templates/Containers/Settings/EcoAuto.php (modified) (2 diffs)
-
src/Tools.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
officegest/trunk/officegest.php
r2387074 r2395291 5 5 * Plugin URI: https://www.officegest.com/woocommerce 6 6 * Description: A forma mais fácil de ligar a sua loja online com a sua faturação. 7 * Version: 1.0.2 77 * Version: 1.0.28 8 8 * Author: OfficeGest 9 9 * Author URI: https://www.officegest.com -
officegest/trunk/readme.txt
r2387077 r2395291 5 5 Tested up to: 5.5 6 6 Requires PHP: 5.6 7 Stable tag: 1.0.2 77 Stable tag: 1.0.28 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 33 33 34 34 == Changelog == 35 36 = 1.0.28 = 37 Fixed Bug for nif validation for portugal 38 35 39 = 1.0.27 = 36 40 Fixed Bug for observations for ecoauto Parts and Vehicles … … 123 127 124 128 == Upgrade Notice == 125 Added Manual129 Fixed Bug for nif validation for portugal -
officegest/trunk/src/Controllers/SyncEcoAuto.php
r2329411 r2395291 19 19 public function run() 20 20 { 21 $has_ecoauto = OfficeGestDBModel::getOption('officegest_ecoauto')==1; 21 $has_ecoauto = OfficeGestDBModel::getOption('officegest_ecoauto')==1; 22 $has_syncpecas = OfficeGestDBModel::getOption('ecoauto_sync_pecas')==1; 22 23 if ($has_ecoauto){ 23 $params = [ 24 'tipos_pecas'=>OfficeGestDBModel::getOption('ecoauto_tipos_pecas'), 25 'imagens'=>OfficeGestDBModel::getOption('ecoauto_imagens'), 26 ]; 27 $filtros= OfficeGestDBModel::getAllEcoautoPartsDB(true,$params); 28 $contador = OfficeGestDBModel::cria_peca($filtros); 29 OfficeGestDBModel::limpapecas(); 30 $this->found = $contador; 24 if ($has_syncpecas){ 25 $params = [ 26 'tipos_pecas'=>OfficeGestDBModel::getOption('ecoauto_tipos_pecas'), 27 'imagens'=>OfficeGestDBModel::getOption('ecoauto_imagens'), 28 ]; 29 $filtros= OfficeGestDBModel::getAllEcoautoPartsDB(true,$params); 30 $contador = OfficeGestDBModel::cria_peca($filtros); 31 OfficeGestDBModel::limpapecas(); 32 $this->found = $contador; 33 } 31 34 } 32 35 return $this; -
officegest/trunk/src/Controllers/SyncImagens.php
r2334140 r2395291 17 17 { 18 18 global $wpdb; 19 $has_ecoauto = OfficeGestDBModel::getOption('officegest_ecoauto')==1; 19 $has_ecoauto = OfficeGestDBModel::getOption('officegest_ecoauto')==1; 20 $has_sync_imagens = OfficeGestDBModel::getOption('ecoauto_sync_imagens')==1; 21 $limit_imagens = OfficeGestDBModel::getOption('ecoauto_sync_imagens_limit'); 20 22 if ($has_ecoauto){ 21 OfficeGestDBModel::getAllPhotosDB(); 22 $query = "Select id,woo_id from ".TABLE_OFFICEGEST_ECO_PARTS." where woo_id>0 and photos_imported=0 LIMIT 60"; 23 $filtros = $wpdb->get_results($query,ARRAY_A); 24 $this->found = OfficegestProduct::update_images($filtros); 23 if ($has_sync_imagens){ 24 OfficeGestDBModel::getAllPhotosDB(); 25 $query = "Select id,woo_id from ".TABLE_OFFICEGEST_ECO_PARTS." where woo_id>0 and photos_imported=0 LIMIT ".$limit_imagens; 26 $filtros = $wpdb->get_results($query,ARRAY_A); 27 $this->found = OfficegestProduct::update_images($filtros); 28 } 25 29 } 26 30 return $this; -
officegest/trunk/src/Crons.php
r2363243 r2395291 77 77 (new SyncArvore())->run(); 78 78 } else { 79 Log::write("Sincronizacação da arvore desactiva no plugin");79 Log::write("Sincronizacação da arvore desactivada no plugin"); 80 80 } 81 81 } catch (Exception $ex) { … … 104 104 (new SyncEcoAuto())->run(); 105 105 } else { 106 Log::write("Sincronizacação de Peças desactiva no plugin");106 Log::write("Sincronizacação de Peças desactivada no plugin"); 107 107 } 108 108 } catch (Exception $ex) { … … 113 113 114 114 public function syncImagens(){ 115 global $wpdb; 116 $runningAt = time(); 115 117 try { 116 118 self::requires(); … … 119 121 return false; 120 122 } 121 (new SyncImagens())->run(); 123 $stock_sync = OfficeGestDBModel::getOption('ecoauto_sync_imagens'); 124 if ($stock_sync==1) { 125 $sync_time = OfficeGestDBModel::getOption('ecoauto_imagens_time'); 126 if ($sync_time==null) { 127 $sync_time = (int)(time() - 600); 128 OfficeGestDBModel::setOption('ecoauto_imagens_time',$sync_time); 129 } 130 (new SyncImagens())->run(); 131 } else { 132 Log::write("Sincronizacação de Imagens desactivada no plugin"); 133 } 122 134 } catch (Exception $ex) { 123 135 Log::write("Fatal Errror: " . $ex->getMessage()); 124 136 } 137 OfficeGestDBModel::setOption("ecoauto_imagens_time", (int)$runningAt); 125 138 } 126 139 -
officegest/trunk/src/Nif.php
r2284138 r2395291 43 43 //Add field to billing address fields - Globally 44 44 public function woocommerce_nif_billing_fields( $fields, $country ) { 45 $fields['billing_nif'] = array( 46 'type' => 'text', 47 'label' => __('NIF / NIPC'), 48 'placeholder' => __('Número de Identificação Fiscal'), 49 'class' => ['form-row-first'], 50 'required' => false, 51 'clear' => true, //Should be an option (?) 52 'autocomplete' => 'billing_nif', 53 'priority' => 120, //WooCommerce should order by this parameter but it doesn't seem to be doing so 54 'maxlength' => 9, 55 'validate' => [$country === 'PT'] 56 ); 57 return $fields; 58 } 45 $fields['billing_nif'] = array( 46 'type' => 'text', 47 'label' => apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ), 48 'placeholder' => apply_filters( 'woocommerce_nif_field_placeholder', __( 'Portuguese VAT identification number', 'officegest' ) ), 49 'class' => apply_filters( 'woocommerce_nif_field_class', array( 'form-row-first' ) ), //Should be an option (?) 50 'required' => ( 51 $country == 'PT' || apply_filters( 'woocommerce_nif_show_all_countries', false ) 52 ? 53 apply_filters( 'woocommerce_nif_field_required', false ) //Should be an option (?) 54 : 55 false 56 ), 57 'clear' => apply_filters( 'woocommerce_nif_field_clear', true ), //Should be an option (?) 58 'autocomplete' => apply_filters( 'woocommerce_nif_field_autocomplete', 'on' ), 59 'priority' => apply_filters( 'woocommerce_nif_field_priority', 120 ), //WooCommerce should order by this parameter but it doesn't seem to be doing so 60 'maxlength' => apply_filters( 'woocommerce_nif_field_maxlength', 9 ), 61 'validate' => ( 62 $country == 'PT' 63 ? 64 ( 65 apply_filters( 'woocommerce_nif_field_validate', false ) 66 ? 67 array( 'nif_pt' ) //Does nothing, actually - Validation is down there on the 'woocommerce_checkout_process' action 68 : 69 array() 70 ) 71 : 72 false 73 ), 74 ); 75 return $fields; 76 77 } 59 78 60 79 //Add field to order admin panel … … 62 81 public function woocommerce_nif_admin_billing_fields( $billing_fields ) { 63 82 global $post; 64 if ( $post->post_type == = 'shop_order' || $post->post_type === 'shop_subscription' ) {83 if ( $post->post_type == 'shop_order' || $post->post_type == 'shop_subscription' ) { 65 84 $order = new WC_Order( $post->ID ); 66 85 $countries = new WC_Countries(); 67 $billing_country = version_compare( $this->wc_version, '3.0', '>=' ) ? $order->get_billing_country() : $order->billing_country;86 $billing_country = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_billing_country() : $order->billing_country; 68 87 //Customer is portuguese or it's a new order ? 69 if ( $billing_country == = 'PT' || ( $billing_country == '' && $countries->get_base_country() === 'PT') ) {88 if ( $billing_country == 'PT' || ( $billing_country == '' && $countries->get_base_country() == 'PT' ) || apply_filters( 'woocommerce_nif_show_all_countries', false ) ) { 70 89 $billing_fields['nif'] = array( 71 'label' => __('NIF / NIPC') , 72 'description' => __('Número de Identificação Fiscal') 90 'label' => apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ), 73 91 ); 74 92 } 75 93 } 76 94 return $billing_fields; 95 77 96 } 78 97 … … 88 107 //3.0 and above - See https://github.com/woocommerce/woocommerce/issues/12654 89 108 public function woocommerce_nif_ajax_get_customer_details( $customer_data, $customer, $user_id ) { 90 if ( ( isset( $customer_data['billing']['country']) && $customer_data['billing']['country'] == 'PT' ) ) {109 if ( ( isset( $customer_data['billing']['country']) && $customer_data['billing']['country'] == 'PT' ) || apply_filters( 'woocommerce_nif_show_all_countries', false ) ) { 91 110 $customer_data['billing']['nif'] = $customer->get_meta( 'billing_nif' ); 92 111 } … … 99 118 if ( isset( $show_fields['billing'] ) && is_array( $show_fields['billing']['fields'] ) ) { 100 119 $show_fields['billing']['fields']['billing_nif'] = array( 101 'label' => __('NIF / NIPC'),102 'description' => __('Número de Identificação Fiscal')120 'label' => apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ), 121 'description' => apply_filters( 'woocommerce_nif_field_placeholder', __( 'Portuguese VAT identification number', 'officegest' ) ), 103 122 ); 104 123 } … … 109 128 110 129 public function woocommerce_nif_order_details_after_customer_details( $order ) { 111 $billing_country = version_compare( $this->wc_version, '3.0', '>=' ) ? $order->get_billing_country() : $order->billing_country;112 $billing_nif = version_compare( $this->wc_version, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif;113 if ( ( $billing_country == = 'PT') && $billing_nif ) {130 $billing_country = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_billing_country() : $order->billing_country; 131 $billing_nif = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif; 132 if ( ( $billing_country == 'PT' || apply_filters( 'woocommerce_nif_show_all_countries', false ) ) && $billing_nif ) { 114 133 ?> 115 134 <tr> 116 <th><?php echo __( 'NIF / NIPC'); ?>:</th>135 <th><?php echo apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ); ?>:</th> 117 136 <td><?php echo esc_html( $billing_nif ); ?></td> 118 137 </tr> 119 138 <?php 120 139 } 140 121 141 } 122 142 … … 124 144 125 145 public function woocommerce_nif_email_customer_details_fields( $fields, $sent_to_admin, $order ) { 126 $billing_nif = version_compare( $this->wc_version, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif;146 $billing_nif = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif; 127 147 if ( $billing_nif ) { 128 148 $fields['billing_nif'] = array( 129 'label' => __('NIF / NIPC'),149 'label' => apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ), 130 150 'value' => wptexturize( $billing_nif ) 131 151 ); … … 139 159 //Order 140 160 if ( isset( $order_data['billing_address'] ) ) { 141 $billing_nif = version_compare( $this->wc_version, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif;161 $billing_nif = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_meta( '_billing_nif' ) : $order->billing_nif; 142 162 $order_data['billing_address']['nif'] = $billing_nif; 143 163 } 144 164 return $order_data; 165 145 166 } 146 167 … … 157 178 158 179 public function woocommerce_nif_checkout_process() { 159 $customer_country = version_compare( $this->wc_version, '3.0', '>=' ) ? WC()->customer->get_billing_country() : WC()->customer->get_country(); 160 $countries = new WC_Countries(); 161 if ( $customer_country == 'PT' || ( $customer_country == '' && $countries->get_base_country() == 'PT' ) ) { 162 $billing_nif = wc_clean( isset( $_POST['billing_nif'] ) ? $_POST['billing_nif'] : '' ); 163 if ( Tools::validaNIFPortugal( $billing_nif, true ) || ( trim( $billing_nif ) == '' ) ) { 164 //OK 180 if ( apply_filters( 'woocommerce_nif_field_validate', false ) ) { 181 $customer_country = version_compare( WC_VERSION, '3.0', '>=' ) ? WC()->customer->get_billing_country() : WC()->customer->get_country(); 182 $countries = new WC_Countries(); 183 if ( $customer_country == 'PT' || ( $customer_country == '' && $countries->get_base_country() == 'PT' ) ) { 184 $billing_nif = wc_clean( isset( $_POST['billing_nif'] ) ? $_POST['billing_nif'] : '' ); 185 if ( Tools::validaNIFPortugal( $billing_nif, true ) || ( trim( $billing_nif ) == '' && !apply_filters( 'woocommerce_nif_field_required', false ) ) ) { //If the field is NOT required and it's empty, we shouldn't validate it 186 //OK 187 } else { 188 wc_add_notice( 189 sprintf( __( 'You have entered an invalid %s for Portugal.', 'officegest' ), '<strong>'.apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ).'</strong>' ), 190 'error' 191 ); 192 } 165 193 } else { 166 wc_add_notice( 167 sprintf( __( 'You have entered an invalid %s for Portugal.'), '<strong>'.'NIF / NIPC'.'</strong>' ), 'error' 168 ); 169 } 170 } 194 //Not Portugal 195 } 196 } else { 197 //All good - No validation required 198 } 199 171 200 } 172 201 … … 174 203 public function woocommerce_nif_after_save_address_validation( $user_id, $load_address, $address ) { 175 204 if ( $load_address == 'billing' ) { 176 $country = wc_clean( isset( $_POST['billing_country'] ) ? $_POST['billing_country'] : '' ); 177 if ( $country == 'PT' ) { 178 $billing_nif = wc_clean( isset( $_POST['billing_nif'] ) ? $_POST['billing_nif'] : '' ); 179 if ( Tools::validaNIFPortugal( $billing_nif, true ) || ( trim( $billing_nif ) == '' ) ) { //If the field is NOT required and it's empty, we shouldn't validate it 205 if ( apply_filters( 'woocommerce_nif_field_validate', false ) ) { 206 $country = wc_clean( isset( $_POST['billing_country'] ) ? $_POST['billing_country'] : '' ); 207 if ( $country == 'PT' ) { 208 $billing_nif = wc_clean( isset( $_POST['billing_nif'] ) ? $_POST['billing_nif'] : '' ); 209 if ( Tools::validaNIFPortugal( $billing_nif, true ) || ( trim( $billing_nif ) == '' && !apply_filters( 'woocommerce_nif_field_required', false ) ) ) { //If the field is NOT required and it's empty, we shouldn't validate it 180 210 //OK 181 } else { 182 wc_add_notice( sprintf( __( 'You have entered an invalid %s for Portugal.' ), '<strong>NIF / NIPC</strong>' ), 'error' ); 211 } else { 212 wc_add_notice( 213 sprintf( __( 'You have entered an invalid %s for Portugal.', 'officegest' ), '<strong>'.apply_filters( 'woocommerce_nif_field_label', __( 'NIF / NIPC', 'officegest' ) ).'</strong>' ), 214 'error' 215 ); 216 } 183 217 } 184 218 } 185 219 } 220 186 221 } 187 222 -
officegest/trunk/src/Templates/Containers/Settings/EcoAuto.php
r2376560 r2395291 10 10 $ecoauto_sync_pecas= OfficeGestDBModel::getOption('ecoauto_sync_pecas'); 11 11 $ecoauto_sync_arvore= OfficeGestDBModel::getOption('ecoauto_sync_arvore'); 12 $ecoauto_sync_imagens = OfficeGestDBModel::getOption('ecoauto_sync_imagens'); 13 $ecoauto_sync_imagens_limit = OfficeGestDBModel::getOption('ecoauto_sync_imagens_limit'); 12 14 $ecoauto_viaturas= OfficeGestDBModel::getOption('ecoauto_viaturas'); 13 15 $ecoauto_tipos_viaturas= OfficeGestDBModel::getOption('ecoauto_tipos_viaturas'); … … 118 120 <p class='description'><?= __('Sincronizar Peças Automaticamente') ?></p> 119 121 </td> 122 </tr> 123 <tr> 124 <th scope="row" class="titledesc"> 125 <label for="ecoauto_sync_imagens"><?= __("Sincronizar Imagens Automaticamente") ?></label> 126 </th> 127 <td> 128 <select id="ecoauto_sync_imagens" name='opt[ecoauto_sync_imagens]' class='officegest_select2 inputOut'> 129 <option value='1' <?= $ecoauto_sync_imagens == '1' ? 'selected' : '1' ?>><?= __("Sim") ?></option> 130 <option value='2' <?= $ecoauto_sync_imagens == '2' ? 'selected' : '2' ?>><?= __("Não") ?></option> 131 </select> 132 <p class='description'><?= __('Sincronizar Imagens Automaticamente') ?></p> 133 </td> 134 </tr> 135 <tr> 136 <th scope="row" class="titledesc"> 137 <label for="ecoauto_sync_imagens_limit"><?= __("Limite de Imagens por sincronização") ?></label> 138 </th> 139 <td> 140 <select id="ecoauto_sync_imagens_limit" name='opt[ecoauto_sync_imagens_limit]' class='officegest_select2 inputOut'> 141 <option value='20' <?= $ecoauto_sync_imagens_limit == '20' ? 'selected' : '20' ?>>20</option> 142 <option value='40' <?= $ecoauto_sync_imagens_limit == '40' ? 'selected' : '40' ?>>40</option> 143 <option value='60' <?= $ecoauto_sync_imagens_limit == '40' ? 'selected' : '60' ?>>60</option> 144 <option value='80' <?= $ecoauto_sync_imagens_limit == '40' ? 'selected' : '80' ?>>80</option> 145 <option value='100' <?= $ecoauto_sync_imagens_limit == '100' ? 'selected' : '100' ?>>100</option> 146 <option value='120' <?= $ecoauto_sync_imagens_limit == '120' ? 'selected' : '120' ?>>120</option> 147 <option value='140' <?= $ecoauto_sync_imagens_limit == '140' ? 'selected' : '140' ?>>140</option> 148 <option value='160' <?= $ecoauto_sync_imagens_limit == '160' ? 'selected' : '160' ?>>160</option> 149 <option value='180' <?= $ecoauto_sync_imagens_limit == '180' ? 'selected' : '180' ?>>180</option> 150 <option value='200' <?= $ecoauto_sync_imagens_limit == '200' ? 'selected' : '200' ?>>200</option> 151 </select> 152 <p class='description'><?= __('Limite de Imagens por sincronização') ?></p> 153 </td> 120 154 </tr> 121 155 <tr> -
officegest/trunk/src/Tools.php
r2334140 r2395291 183 183 public static function validaNIFPortugal($nif, $ignoreFirst=true) { 184 184 //Limpamos eventuais espaços a mais 185 $nif =trim($nif);185 $nif = trim( $nif ); 186 186 //Verificamos se é numérico e tem comprimento 9 187 if ( !is_numeric($nif) || strlen($nif)!=9) {187 if ( !is_numeric( $nif ) || strlen( $nif ) != 9 ) { 188 188 return false; 189 } 190 191 $nifSplit=str_split($nif); 192 //O primeiro digíto tem de ser 1, 2, 3, 5, 6, 8 ou 9 193 //Ou não, se optarmos por ignorar esta "regra" 194 if ( in_array($nifSplit[0], array(1, 2, 3, 5, 6, 8, 9)) || $ignoreFirst 195 ) { 196 //Calculamos o dígito de controlo 197 $checkDigit=0; 198 for($i=0; $i<8; $i++) { 199 $checkDigit+=$nifSplit[$i]*(10-$i-1); 200 } 201 $checkDigit=11-($checkDigit % 11); 202 //Se der 10 então o dígito de controlo tem de ser 0 203 if($checkDigit>=10) $checkDigit=0; 204 //Comparamos com o último dígito 205 return $checkDigit == $nifSplit[8] ? true : false; 206 } 207 208 return false; 189 } else { 190 $nifSplit = str_split( $nif ); 191 //O primeiro digíto tem de ser 1, 2, 5, 6, 8 ou 9 192 //Ou não, se optarmos por ignorar esta "regra" 193 if ( 194 in_array( $nifSplit[0], array( 1, 2, 5, 6, 8, 9 ) ) 195 || 196 $ignoreFirst 197 ) { 198 //Calculamos o dígito de controlo 199 $checkDigit=0; 200 for( $i=0; $i<8; $i++ ) { 201 $checkDigit += $nifSplit[$i] * ( 10-$i-1 ); 202 } 203 $checkDigit = 11 - ( $checkDigit % 11 ); 204 //Se der 10 então o dígito de controlo tem de ser 0 205 if( $checkDigit >= 10 ) $checkDigit = 0; 206 //Comparamos com o último dígito 207 if ( $checkDigit == $nifSplit[8] ) { 208 return true; 209 } else { 210 return false; 211 } 212 } else { 213 return false; 214 } 215 } 209 216 } 210 217
Note: See TracChangeset
for help on using the changeset viewer.