';
}
return $columns;
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
add_action('manage_shop_order_posts_custom_column' , 'allpacka_order_column', 10, 2 );
function allpacka_order_column( $column_name, $order_id ) {
if( get_option( 'allpacka_allapot' ) == 'yes' ){
switch ( $column_name ) {
case 'allpacka' :
allpacka_gombok( $order_id );
break;
}
}
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
function allpacka_gombok( $order_id, $string = false ){
$kimenet = '';
$upload_dir = wp_upload_dir();
$allpacka_azonosito = get_post_meta( $order_id, '_allpacka_azonosito', true );
$allpacka_fuvarlevelszam = get_post_meta( $order_id, '_allpacka_fuvarlevelszam', true );
$kimenet .= ''.__( 'Order ID:', 'allpacka' ).' '.$allpacka_azonosito.'
'; $kimenet .= '
'.__( 'The waybill will be sent to you by the Pactic Customer Service.', 'allpacka' ).'
'.__( 'Order ID:', 'allpacka' ).' '.$allpacka_azonosito.'
'; $kimenet .= ''; $kimenet .= ''.__( 'Waybill number:', 'allpacka' ).' '.$allpacka_fuvarlevelszam.''; if( file_exists( $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$allpacka_fuvarlevelszam.'.pdf' ) ){ $kimenet .= ''; } if( $csomag_statusz = allpacka_csomag_statusz( $allpacka_fuvarlevelszam ) ){ $kimenet .= '
'.__( 'Package status:', 'allpacka' ).' '.$csomag_statusz['nev'].'
'; } else if( $nyomkovetes_url = allpacka_nyomkovetes_url( $allpacka_fuvarlevelszam ) ){ $kimenet .= ''; } $kimenet .= ''; } $kimenet .= '
';
}
echo ''.__( 'Waybills cancellation', 'allpacka' ).'
', ), 'allpacka_section_5_end' => array( 'type' => 'sectionend' ), ); return apply_filters( 'allpacka_settings', $settings ); } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_ajax_megrendeles() { if ( isset($_REQUEST) ) { $order_id = $_REQUEST['order_id']; $allpacka_megrendeles_return = allpacka_megrendeles( $order_id ); echo $allpacka_megrendeles_return; } die(); } add_action( 'wp_ajax_allpacka_ajax_megrendeles', 'allpacka_ajax_megrendeles' ); /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_megrendeles_torlese( $order_id ) { $upload_dir = wp_upload_dir(); $allpacka_azonosito = get_post_meta( $order_id, '_allpacka_azonosito', true ); $allpacka_fuvarlevelszam = get_post_meta( $order_id, '_allpacka_fuvarlevelszam', true ); if( $allpacka_azonosito ){ update_post_meta( $order_id, '_allpacka_azonosito', '' ); } if( $allpacka_fuvarlevelszam ){ update_post_meta( $order_id, '_allpacka_fuvarlevelszam', '' ); $fajlnev_dir = $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$allpacka_fuvarlevelszam.'.pdf'; if( file_exists( $fajlnev_dir ) ){ unlink( $fajlnev_dir ); } } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_megrendeles( $order_id ) { allpacka_megrendeles_torlese( $order_id ); $order = wc_get_order( $order_id ); $company = method_exists( $order, 'get_shipping_company' ) ? $order->get_shipping_company() : $order->shipping_company; $contact_first_name = method_exists( $order, 'get_shipping_first_name' ) ? $order->get_shipping_first_name() : $order->shipping_first_name; $contact_last_name = method_exists( $order, 'get_shipping_last_name' ) ? $order->get_shipping_last_name() : $order->shipping_last_name; if( !empty( $company ) ){ $nmCompanyOrPerson = $company; $nmContact = $contact_last_name.' '.$contact_first_name; } else{ $nmCompanyOrPerson = $contact_last_name.' '.$contact_first_name; $nmContact = $contact_last_name.' '.$contact_first_name; } $allpacka_kivalasztott_gls_csomagpont_json = get_post_meta( $order_id, '_allpacka_kivalasztott_gls_csomagpont', true ); if( !empty( $allpacka_kivalasztott_gls_csomagpont_json ) ) { $allpacka_kivalasztott_gls_csomagpont = json_decode( str_replace( "'", '"', $allpacka_kivalasztott_gls_csomagpont_json ), true ); $cdDropOffPoint = (string)$allpacka_kivalasztott_gls_csomagpont['Code']; $DESTINATIONADDRESS = array( 'nmCompanyOrPerson' => $nmCompanyOrPerson, 'nmContact' => $nmContact, 'cdCountry' => method_exists( $order, 'get_shipping_country' ) ? $order->get_shipping_country() : $order->shipping_country, 'cdDropOffPoint' => $cdDropOffPoint, 'txAddress' => '', 'txAddressNumber' => '.', 'txPost' => '', 'txCity' => '', 'txPhoneContact' => method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone, 'txEmailContact' => method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email, 'txInstruction' => (string)substr( ( method_exists( $order, 'get_customer_note' ) ? $order->get_customer_note() : $order->customer_note ), 0, 63 ) ); } else{ $DESTINATIONADDRESS = array( 'nmCompanyOrPerson' => $nmCompanyOrPerson, 'nmContact' => $nmContact, 'cdCountry' => method_exists( $order, 'get_shipping_country' ) ? $order->get_shipping_country() : $order->shipping_country, 'txAddress' => method_exists( $order, 'get_shipping_address_1' ) ? $order->get_shipping_address_1() : $order->shipping_address_1, 'txAddressNumber' => '.', 'txPost' => method_exists( $order, 'get_shipping_postcode' ) ? $order->get_shipping_postcode() : $order->shipping_postcode, 'txCity' => method_exists( $order, 'get_shipping_city' ) ? $order->get_shipping_city() : $order->shipping_city, 'txPhoneContact' => method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone, 'txEmailContact' => method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email, 'txInstruction' => (string)substr( ( method_exists( $order, 'get_customer_note' ) ? $order->get_customer_note() : $order->customer_note ), 0, 63 ) ); } $payment_method = method_exists( $order, 'get_payment_method' ) ? $order->get_payment_method() : $order->payment_method; if ( $payment_method == 'cod' || in_array( $payment_method, get_option( 'allpacka_fizetesi_modok' ) ) ) { $PACKAGE = array( array( 'idOrder' => (string)$order_id, 'ctPackage' => '1', 'amContent' => (string)$order->get_total(), ) ); $cod = 'true'; } else{ $PACKAGE = array( array( 'idOrder' => (string)$order_id, 'ctPackage' => '1', ) ); $cod = 'false'; } $PACKAGES = array( 'PACKAGE' => $PACKAGE ); if( get_option( 'allpacka_felado_neve' ) != '' && get_option( 'allpacka_felado_bank_neve' ) != '' && get_option( 'allpacka_felado_bankszamlaszama' ) != '' ){ $ORDER = array( 'flCOD' => $cod, 'nmRecipientCOD' => get_option( 'allpacka_felado_neve' ), 'nmBankCOD' => get_option( 'allpacka_felado_bank_neve' ), 'txBankAccountNumberCOD' => get_option( 'allpacka_felado_bankszamlaszama' ), 'flNothingProhibited' => allpacka_konvertalas( get_option( 'allpacka_tiltott_aru' ) ), 'flAgreedToTermsAndConditions' => allpacka_konvertalas( get_option( 'allpacka_aszf' ) ), 'DESTINATIONADDRESS' => $DESTINATIONADDRESS, "PACKAGES" => $PACKAGES ); } else{ $ORDER = array( 'flCOD' => $cod, 'flNothingProhibited' => allpacka_konvertalas( get_option( 'allpacka_tiltott_aru' ) ), 'flAgreedToTermsAndConditions' => allpacka_konvertalas( get_option( 'allpacka_aszf' ) ), 'DESTINATIONADDRESS' => $DESTINATIONADDRESS, "PACKAGES" => $PACKAGES ); } $REQUEST = array( 'flDebug' => allpacka_konvertalas( get_option( 'allpacka_tesztkornyezet' ) ), 'cdLang' => allpacka_nyelv(), 'txEmail' => get_option( 'allpacka_email' ), 'txPassword' => get_option( 'allpacka_jelszo' ), 'ORDER' => $ORDER ); $JSON = array( 'REQUEST' => $REQUEST, ); $allpacka_megrendeles_return = array(); $url = 'https://api.pactic.com/webservices/webshop2.ashx'; if( extension_loaded( 'curl' ) ){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE ); curl_setopt( $ch, CURLOPT_HEADER, FALSE ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE ); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $JSON ) ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) ); $allpacka_megrendeles_json = curl_exec( $ch ); curl_close($ch); } else if( ini_get( 'allow_url_fopen' ) ){ $options = array( 'http' => array( 'header' => 'Content-Type: application/x-www-form-urlencoded', 'method' => 'POST', 'content' => json_encode( $JSON ) ) ); $context = stream_context_create( $options ); $allpacka_megrendeles_json = file_get_contents( $url, false, $context ); } $allpacka_megrendeles = json_decode( $allpacka_megrendeles_json, true); if( get_option( 'allpacka_debug' ) == 'yes' ){ $allpacka_megrendeles_return['debug'] = ''.__( 'Request sent to Pactic:', 'allpacka' ).''.json_encode( $JSON, JSON_PRETTY_PRINT ).''.__( 'Response received from Pactic:', 'allpacka' ).'
'.json_encode( $allpacka_megrendeles, JSON_PRETTY_PRINT ).''; } if ( $allpacka_megrendeles_json == null ) { $allpacka_megrendeles_return['hiba'][] = ''.__( 'Error message from Pactic:', 'allpacka' ).' '.'NULL response'; } if ( $allpacka_megrendeles == null ) { $allpacka_megrendeles_return['sikertelen'] = ''.__( 'Unsuccesful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id.' '.__( 'No response received from Pactic for the ORDER request.', 'allpacka' ) .' '. __('Password or email address probably wrong.', 'allpacka' ); $allpacka_megrendeles_return['hiba'][] = ''.__( 'Error message from Pactic:', 'allpacka' ).' '.$allpacka_megrendeles_json; $order->add_order_note( ''.__( 'Error message from Pactic:', 'allpacka' ).' '.__( 'No response received from Pactic for the ORDER request.', 'allpacka' ) ); } else if( $allpacka_megrendeles ){ if( get_option( 'allpacka_tesztkornyezet' ) == 'yes' ){ //TESZT if( $allpacka_megrendeles['Messages'] ){ foreach( $allpacka_megrendeles['Messages'] as $message ){ if( $message['Text'] != 'TEST: Quote added successfully' ){ $allpacka_megrendeles_return['hiba'][] = ''.__( 'Error message from Pactic:', 'allpacka' ).' '.$message['Text']; } } } if( !empty( $allpacka_megrendeles['Order']['Labels'] ) && !empty( $allpacka_megrendeles['Order']['WayBills'] ) ){ update_post_meta( $order_id, '_allpacka_azonosito', 'teszt_'.$order_id ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', $allpacka_megrendeles['Order']['WayBills'][0] ); $minta_fuvarlevel = ALLPACKA_PLUGIN_DIR_URL.'/pdf/minta_fuvarlevel.pdf'; $upload_dir = wp_upload_dir(); $fajlnev_dir = $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$allpacka_megrendeles['Order']['WayBills'][0].'.pdf'; copy( $minta_fuvarlevel, $fajlnev_dir); $allpacka_megrendeles_return['sikeres'] = ''.__( 'Successful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id.'. '.__( 'Pactic order ID:', 'allpacka' ).' '.$allpacka_megrendeles['Order']['ID'].'. '.__( 'Waybill number:', 'allpacka' ).' '.$allpacka_megrendeles['Order']['WayBills'][0].'. '.__( 'The waybill contains fake data in test mode!', 'allpacka' ).''; $order->add_order_note( sprintf( __( 'Successful Pactic order. Pactic order ID: %s. Waybill number: %s. The waybill contains fake data in test mode!', 'allpacka' ), $allpacka_megrendeles['Order']['ID'], $allpacka_megrendeles['Order']['WayBills'][0] ) ); } else{ $allpacka_megrendeles_return['sikertelen'] = ''.__( 'Unsuccesful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( __( 'Unsuccesful Pactic order.', 'allpacka' ) ); } } else{ //ÉLES if( $allpacka_megrendeles['Messages'] ){ foreach( $allpacka_megrendeles['Messages'] as $message ){ $allpacka_megrendeles_return['hiba'][] = ''.__( 'Error message from Pactic:', 'allpacka' ).' '.$message['Text']; } } // van idQuote, nincs Waybill szám, nincs PDF if( $allpacka_megrendeles['Order']['ID'] > 0 && empty( $allpacka_megrendeles['Order']['Labels'] ) && empty( $allpacka_megrendeles['Order']['WayBills'] ) ){ update_post_meta( $order_id, '_allpacka_azonosito', $allpacka_megrendeles['Order']['ID'] ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', '' ); $allpacka_megrendeles_return['sikeres'] = ''.__( 'Successful Pactic order, but a label/waybill was not generated.', 'allpacka' ).' '.__( 'The Customer Service of Pactic corrects the mistake and sends you an email.', 'allpacka' ).' '.__('Webshop order ID:', 'allpacka' ).' '.$order_id.'. '.__( 'Pactic order ID:', 'allpacka' ).' '.$allpacka_megrendeles['Order']['ID'].'.'; $order->add_order_note( __( 'Successful Pactic order, but a label/waybill was not generated. The Customer Service of Pactic corrects the mistake and sends you an email.', 'allpacka' )); } // van idQuote, van Waybill szám, de nincs PDF else if( $allpacka_megrendeles['Order']['ID'] > 0 && empty( $allpacka_megrendeles['Order']['Labels'] ) && !empty( $allpacka_megrendeles['Order']['WayBills'] ) ){ update_post_meta( $order_id, '_allpacka_azonosito', $allpacka_megrendeles['Order']['ID'] ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', $allpacka_megrendeles['Order']['WayBills'][0] ); $allpacka_megrendeles_return['sikeres'] = ''.__( 'Successful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id.'. '. __( 'Pactic order ID:', 'allpacka' ) . ' '.$allpacka_megrendeles['Order']['ID'].'. '. __( 'Waybill number:', 'allpacka' ).' '.$allpacka_megrendeles['Order']['WayBills'][0].'.'; $order->add_order_note( sprintf( __( 'Successful Pactic order. Pactic order ID: %s. Waybill number: %s.', 'allpacka' ), $allpacka_megrendeles['Order']['ID'], $allpacka_megrendeles['Order']['WayBills'][0] ) ); } // van idQuote, van Waybill szám, és van PDF is else if( !empty( $allpacka_megrendeles['Order']['Labels'] ) && !empty( $allpacka_megrendeles['Order']['WayBills'] ) && $allpacka_megrendeles['Order']['ID'] > 0 ){ $fuvarlevel = $allpacka_megrendeles['Order']['Labels'][0]; if( !empty( $fuvarlevel ) ){ update_post_meta( $order_id, '_allpacka_azonosito', $allpacka_megrendeles['Order']['ID'] ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', $allpacka_megrendeles['Order']['WayBills'][0] ); $upload_dir = wp_upload_dir(); $fuvarlevel = base64_decode($fuvarlevel); $fajlnev_dir = $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$allpacka_megrendeles['Order']['WayBills'][0].'.pdf'; file_put_contents( $fajlnev_dir, $fuvarlevel); $allpacka_megrendeles_return['sikeres'] = ''.__( 'Successful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id.'. '. __( 'Pactic order ID:', 'allpacka' ) . ' '.$allpacka_megrendeles['Order']['ID'].'. '. __( 'Waybill number:', 'allpacka' ).' '.$allpacka_megrendeles['Order']['WayBills'][0].'.'; $order->add_order_note( sprintf( __( 'Successful Pactic order. Pactic order ID: %s. Waybill number: %s.', 'allpacka' ), $allpacka_megrendeles['Order']['ID'], $allpacka_megrendeles['Order']['WayBills'][0] ) ); } else{ $allpacka_megrendeles_return['sikertelen'] = ''.__( 'Unsuccesful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( __( 'Unsuccesful Pactic order.', 'allpacka' ) ); } } else{ $allpacka_megrendeles_return['sikertelen'] = ''.__( 'Unsuccesful Pactic order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( __( 'Unsuccesful Pactic order.', 'allpacka' ) ); } } } $allpacka_megrendeles_return['allpacka_gombok'] = allpacka_gombok( $order_id, true ); return json_encode( $allpacka_megrendeles_return ); } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_filter( 'bulk_actions-edit-shop_order', 'allpacka_bulk_actions' ); function allpacka_bulk_actions( $bulk_array ) { $bulk_array['allpacka_megrendeles'] = __( 'Generate label via Pactic', 'allpacka' ); $bulk_array['allpacka_megrendeles_fuvarlevel_letoltes'] = __( 'Generate and download labels via Pactic', 'allpacka' ); $bulk_array['allpacka_fuvarlevel_letoltes'] = __( 'Download labels generated via Pactic', 'allpacka' ); return $bulk_array; } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_filter( 'handle_bulk_actions-edit-shop_order', 'allpacka_bulk_action_handler', 10, 3 ); function allpacka_bulk_action_handler( $redirect, $doaction, $order_ids ) { $redirect = remove_query_arg( array( 'allpacka_megrendeles_kesz', 'allpacka_fuvarlevel_letoltes_kesz', 'allpacka_megrendeles_fuvarlevel_letoltes_kesz' ), $redirect ); if ( $doaction == 'allpacka_megrendeles' ) { $allpacka_tomeges_megrendeles_return = allpacka_tomeges_megrendeles( $order_ids ); if( !session_id() ){ session_start(); } $_SESSION['allpacka_tomeges_megrendeles_return'] = $allpacka_tomeges_megrendeles_return; $redirect = add_query_arg( 'allpacka_megrendeles_kesz', 1, $redirect ); } if ( $doaction == 'allpacka_fuvarlevel_letoltes' ) { $allpacka_fuvarlevel_letoltes_return = allpacka_fuvarlevel_letoltes( $order_ids ); if( !session_id() ){ session_start(); } $_SESSION['allpacka_fuvarlevel_letoltes_return'] = $allpacka_fuvarlevel_letoltes_return ; $redirect = add_query_arg( 'allpacka_fuvarlevel_letoltes_kesz', 1, $redirect ); } if ( $doaction == 'allpacka_megrendeles_fuvarlevel_letoltes' ) { $allpacka_tomeges_megrendeles_return = allpacka_tomeges_megrendeles( $order_ids ); $allpacka_fuvarlevel_letoltes_return = allpacka_fuvarlevel_letoltes( $order_ids ); if( !session_id() ){ session_start(); } $_SESSION['allpacka_tomeges_megrendeles_return'] = $allpacka_tomeges_megrendeles_return; $_SESSION['allpacka_fuvarlevel_letoltes_return'] = $allpacka_fuvarlevel_letoltes_return; $redirect = add_query_arg( 'allpacka_megrendeles_fuvarlevel_letoltes_kesz', 1, $redirect ); } return $redirect; } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_action( 'admin_notices', 'allpacka_bulk_action_notices' ); function allpacka_bulk_action_notices() { if( !empty( $_REQUEST['allpacka_megrendeles_kesz'] ) || !empty( $_REQUEST['allpacka_megrendeles_fuvarlevel_letoltes_kesz'] ) ) { if( !session_id() ){ session_start(); } if( isset( $_SESSION['allpacka_tomeges_megrendeles_return'] ) ){ foreach( json_decode( $_SESSION['allpacka_tomeges_megrendeles_return'], true ) as $order_id => $megrendeles_adatok ){ if( isset( $megrendeles_adatok['sikeres'] ) ){ $uzenet = $megrendeles_adatok['sikeres']; if( isset( $megrendeles_adatok['hiba'] ) ){ $uzenet .= '
'.$uzenet.'
'.$uzenet.'
'.$uzenet.'
'.$_SESSION['allpacka_fuvarlevel_letoltes_return']['sikeres'].'
'.$_SESSION['allpacka_fuvarlevel_letoltes_return']['sikertelen'].'
';
echo '';
echo __( 'Error message from Pactic', 'allpacka' );
echo '
';
echo '';
echo __( 'Pactic warning', 'allpacka' );
echo '';
echo ''; echo __( 'The plug-in automatically chooses the default payment method:', 'allpacka' ).' '.allpacka_engedelyezett_fizetesi_modok( 'cod' ).'.'; echo '
'; echo ''; echo __( 'Additional payment methods for COD in your webshop.', 'allpacka' ); echo ' '.__( 'Set up here.', 'allpacka' ).''; echo '
'; echo ''; echo ''; echo '
'; echo '