Plugin Directory

Changeset 2415872


Ignore:
Timestamp:
11/10/2020 02:27:26 PM (5 years ago)
Author:
posturinn
Message:

Tagging version 1.0.8

Location:
posturinn
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • posturinn/tags/1.0.8/inc/admin.php

    r2396143 r2415872  
    313313       
    314314    }else{
    315         // if (substr($customer_phone, 0, 1) === '6' || substr($customer_phone, 0, 1) === '7' || substr($customer_phone, 0, 1) === '8') {
    316            
    317         // } else {
    318         //     $customer_phone = '';
    319         // }
     315        if ($shipping_service == 'DPP' OR $shipping_service == 'DPH') {
     316            if (substr($customer_phone, 0, 1) === '6' || substr($customer_phone, 0, 1) === '7' || substr($customer_phone, 0, 1) === '8') {
     317                // phoneNumber is valid
     318            } else {
     319                $valid_phonenumber = '';
     320            }
     321        }
    320322        $recipeint = array( 'name'         => $shipping_customerName,
    321323                            'addressLine1' => $shipping_address1,
     
    454456    if ($automatic_printing == 'yes') {
    455457        $print_response = wp_remote_post( $print_query, $print_headers );
    456         // postis_pa($print_response);
    457     }
     458       
     459        $print_response_code = wp_remote_retrieve_response_code( $print_response );
     460       
     461        if ($print_response_code == 204 ) {
     462            update_post_meta( $order_id, 'postis_is_shipment_printed', 'printed' );
     463        }else{
     464            update_post_meta( $order_id, 'postis_is_shipment_printed', 'not_printed' );
     465        }
     466    }
     467   
     468    // postis_pa($print_response_code); exit;
    458469   
    459470   
     
    572583           
    573584            if ($shipment_status == true && $get_shipment_meta != '') {
    574                 echo '<a class="button button-primary" href="'.esc_url($pdf_url).'" target="'.esc_attr($open_pdf_status).'">'. __("Get PDF", "postis").'</a>';
     585               
     586                $print_status = get_post_meta( $order_id, 'postis_is_shipment_printed', true );
     587               
     588                if ($print_status == 'printed') {
     589                    $tooltip = __('Shipment Printed', 'postis');
     590                    $icon = '<span data-tip="'.esc_attr($tooltip).'" class="tips dashicons dashicons-yes" style="color:#00ff00;margin-top: 4px;"></span>';
     591                }else{
     592                    $icon = '';
     593                }
     594               
     595                echo '<a class="button button-primary" href="'.esc_url($pdf_url).'" target="'.esc_attr($open_pdf_status).'">'. __("Get PDF", "postis"). $icon .'</a>';
    575596            }else{
    576597                echo '--';
     
    581602
    582603
    583 function postis_get_shipment_data($order_id, $shipmet_key){
    584    
    585     $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
     604// function postis_get_shipment_data($order_id, $shipmet_key){
     605   
     606//     $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
    586607     
    587     $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
    588    
    589     return $postval;
    590 }
     608//     $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
     609   
     610//     return $postval;
     611// }
    591612
    592613add_action( 'woocommerce_product_options_shipping', 'postis_product_custom_field' );
     
    626647    update_post_meta($post_id, 'descriptionOfContents', sanitize_text_field($descContents));
    627648}
     649
     650add_filter( 'bulk_actions-edit-shop_order', 'postis_order_bulk_action_option', 20, 1 );
     651function postis_order_bulk_action_option( $actions ) {
     652    $actions['create_shipment'] = __( 'CreateShipment', 'postis' );
     653    $actions['print_shipment'] = __( 'PrintShipments', 'postis' );
     654    return $actions;
     655}
     656
     657add_filter( 'handle_bulk_actions-edit-shop_order', 'postis_bulk_action_process', 10, 3 );
     658function postis_bulk_action_process( $redirect_to, $action, $post_ids ) {
     659    // if ( $action !== 'create_shipment' || $action !== 'print_shipment')
     660    //     return $redirect_to;
     661
     662    $processed_ids = array();
     663    $recipeint = array();
     664   
     665    $postis_apikey = postis_get_settings( 'apikey' );
     666    $domain = $_SERVER['HTTP_HOST'];
     667    $endpoint_url = postis_get_endpoints( 'create_shipment' );
     668   
     669    if ($action === 'create_shipment') {
     670       
     671        foreach ( $post_ids as $post_id ) {
     672           
     673            $order = wc_get_order( $post_id );
     674            $ship_methods          = $order->get_shipping_methods();
     675            $shipping_customerName = $order->get_formatted_shipping_full_name();
     676            $shipping_address1     = $order->get_shipping_address_1();
     677            $shipping_postcode     = $order->get_shipping_postcode();
     678            $country_code          = $order->get_shipping_country();
     679            $city                  = $order->get_shipping_city();
     680            $customer_email        = $order->get_billing_email();
     681            $customer_phone        = $order->get_billing_phone();
     682           
     683            $shipping_service      = get_post_meta( $post_id, 'postis_shipping_method', true );
     684           
     685            $recipeint = array( 'name'         => $shipping_customerName,
     686                                'addressLine1' => $shipping_address1,
     687                                "postcode"     => $shipping_postcode,
     688                                "countryCode"  => $country_code,
     689                                "mobilePhone"  => $customer_phone,
     690                            );
     691                           
     692            $recipeint['email'] =  $customer_email;
     693            $options = array('deliveryServiceId' => $shipping_service);
     694            $params = array(
     695                    'recipient'                => $recipeint,
     696                    'options'                  => $options,
     697                );
     698           
     699            $order_data = $order->get_data();
     700           
     701            $params = array_filter( $params );
     702       
     703            // postis_pa($params); exit;
     704           
     705            // Set Header
     706            $headers = array(
     707                    'headers'     => array('Content-Type' => 'application/json; charset=utf-8', 'x-api-key'=>$postis_apikey,'domain_name'=> $domain),
     708                    'body'        => json_encode($params),
     709                    'method'      => 'POST',
     710                    'data_format' => 'body',
     711                );
     712                   
     713            // Run the query
     714            $response = wp_remote_post( $endpoint_url, $headers );
     715            $get_shipment_meta = json_decode( $response['body'], true );
     716           
     717           
     718            // postis_pa($get_shipment_meta); exit;
     719           
     720            if(  $response['response']['code'] != 400 && $response['response']['code'] != 401 ) {
     721           
     722                update_post_meta( $post_id, 'postis_shipment_meta', $get_shipment_meta );
     723               
     724                $ajax_response = array('status'=>'success', 'message'=> __('Shipment Created Successfully', 'postis'));
     725                $res_msg = 'created';
     726               
     727            }else{
     728                $resp_message  = sprintf( __("Shipment Not Created.\nServer Response: %s", "postis"), $get_shipment_meta['message'] );
     729                $res_msg = 'failed';
     730               
     731                if (strpos($get_shipment_meta['message'], 'Ekki var hægt að skrá sendingu (Addressee.Gsm') !== false) {
     732                    $ajax_response = array('status'=>'error', 'type'=>'phonenumber', 'message'=> $resp_message );
     733                } else {
     734                    $ajax_response = array('status'=>'error', 'type'=>'other', 'message'=> $resp_message );
     735                }
     736               
     737            }
     738           
     739            $processed_ids[] = $post_id;
     740        }
     741    }else if($action === 'print_shipment'){
     742        foreach ( $post_ids as $post_id ) {
     743           
     744            $shipmentId         =  postis_get_shipment_data($post_id, 'shipmentId');
     745           
     746            $print_endpoint = postis_get_endpoints( 'print' );
     747            $print_params = array(
     748                'shipmentId' => $shipmentId,
     749                'outputFormat'      => 'poststod'
     750            );
     751            $print_params = array_filter( $print_params );
     752           
     753           
     754            // Query format parameters.
     755            $print_query = add_query_arg( $print_params, $print_endpoint );
     756           
     757            // Set Header
     758            $print_headers = array(
     759                    'headers'     => array('x-api-key'=>$postis_apikey, 'domain_name'=> $domain),
     760                    //'body'        => json_encode($print_params),
     761                    'method'      => 'POST',
     762                    // 'data_format' => 'body',
     763                );
     764            // postis_pa($print_headers);   
     765                   
     766            // Run the query
     767            $automatic_printing = postis_get_settings( 'pdf_print' );
     768            if ($automatic_printing == 'yes') {
     769                $print_response = wp_remote_post( $print_query, $print_headers );
     770               
     771                $print_response_code = wp_remote_retrieve_response_code( $print_response );
     772                   
     773                if ($print_response_code == 204 ) {
     774                    update_post_meta( $post_id, 'postis_is_shipment_printed', 'printed' );
     775                }else{
     776                    update_post_meta( $post_id, 'postis_is_shipment_printed', 'not_printed' );
     777                }
     778               
     779                // postis_pa($print_response); exit;
     780            }
     781           
     782        }
     783    }else{
     784        return $redirect_to;
     785    }
     786
     787    return $redirect_to = add_query_arg( array(
     788        'processed_count' => count( $processed_ids ),
     789        'status' => $res_msg,
     790    ), $redirect_to );
     791}
     792
     793if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
     794
     795    // adds the coupon filtering dropdown to the orders page
     796    add_action( 'restrict_manage_posts', 'filter_orders_by_coupon_used' );
     797
     798    // makes coupons filterable
     799//  add_filter( 'posts_join',  'add_order_items_join' );
     800//  add_filter( 'posts_where', 'add_filterable_where' );
     801
     802    add_filter( 'request', 'filter_orders_by_payment_method_query' );   
     803}
     804
     805function filter_orders_by_coupon_used() {
     806    global $typenow;
     807
     808    if ( 'shop_order' === $typenow ) {
     809
     810        ?>
     811        <select name="postis_shipment_print_status" id="postis_shipment_print_status">
     812            <option value=""><?php esc_html_e( 'Shipment Print Status', 'postis' ); ?></option>
     813            <option value="printed"><?php esc_html_e( 'Printed', 'postis' ); ?></option>
     814            <option value="not_printed"><?php esc_html_e( 'Not printed', 'postis' ); ?></option>
     815        </select>
     816        <?php
     817    }
     818}
     819
     820function filter_orders_by_payment_method_query( $vars ) {
     821    global $typenow;
     822
     823    if ( 'shop_order' === $typenow && isset( $_GET['postis_shipment_print_status'] ) && ! empty( $_GET['postis_shipment_print_status'] ) ) {
     824
     825        $vars['meta_key']   = 'postis_is_shipment_printed';
     826        $vars['meta_value'] = wc_clean( $_GET['postis_shipment_print_status'] );
     827    }
     828
     829    return $vars;
     830}
  • posturinn/tags/1.0.8/inc/functions.php

    r2402610 r2415872  
    390390   return apply_filters('postis_international_contents_fields',$options);
    391391}
     392
     393function postis_get_shipment_data($order_id, $shipmet_key){
     394   
     395    $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
     396     
     397    $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
     398   
     399    return $postval;
     400}
  • posturinn/tags/1.0.8/languages/postis-is_IS.po

    r2334877 r2415872  
    33"Project-Id-Version: Pósturinn's Shipping with WooCommerce\n"
    44"POT-Creation-Date: 2020-06-24 12:20+0000\n"
    5 "PO-Revision-Date: 2020-07-01 08:38+0000\n"
     5"PO-Revision-Date: 2020-11-10 13:33+0000\n"
    66"Last-Translator: Aron Hallsson <[email protected]>\n"
    77"Language-Team: Aron Hallsson <[email protected]>\n"
     
    1111"Content-Transfer-Encoding: 8bit\n"
    1212"Plural-Forms: nplurals=2; plural=(n%10==1 && n%100!=11);\n"
    13 "X-Generator: Poedit 2.3.1\n"
     13"X-Generator: Poedit 2.4.1\n"
    1414"X-Poedit-Basepath: ..\n"
    1515"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
     
    2121"X-Poedit-SearchPathExcluded-0: *.min.js\n"
    2222
     23#: inc/admin.php:813
     24msgid "Shipment Print Status"
     25msgstr "Prent staða"
     26
     27#: inc/admin.php:814
     28msgid "Printed"
     29msgstr "Prentað"
     30
     31#: inc/admin.php:815
     32msgid "Not printed"
     33msgstr "Ekki prentað"
     34
     35#: inc/admin.class.php:534
     36msgid "Create Shipments"
     37msgstr "Búa til sendingarmiða"
     38
     39#: inc/admin.class.php:535
     40msgid "Print Shipment PDF"
     41msgstr "Prenta sendingarmiða"
     42
     43#: inc/admin.class.php:536
     44msgid "Mark as printed"
     45msgstr "Merkja sem prentað"
     46
     47#: inc/admin.class.php:537
     48msgid "Mark as not printed"
     49msgstr "Merkja sem EKKI prentað"
     50
     51
     52#: inc/admin.class.php:685
     53msgid "Tarriff Number"
     54msgstr "Tollnúmer"
     55
     56#: inc/admin.class.php:688
     57msgid "Tarriff Number. Needs to be 6 or 8 numbers"
     58msgstr "Tollnúmer. Þarf að vera 6 eða 8 tölustafir"
     59
     60#: inc/admin.class.php:694
     61msgid "Description in english"
     62msgstr "Lýsing tollvöru á ensku"
     63
     64#: inc/admin.class.php:697
     65msgid "This needs to be written in english!"
     66msgstr "Þetta þarf að vera skrifað á ensku!"
     67
     68
     69
    2370#: inc/postis.class.php:125
    2471msgid "Use Shipping Price"
     
    3178#: inc/postis.class.php:133
    3279msgid "Include Woocommerce VAT"
    33 msgstr "Reikna með Woocommerce VSK útreikning."
     80msgstr "Reikna með Woocommerce VSK útreikning"
    3481
    3582#: inc/postis.class.php:137
  • posturinn/tags/1.0.8/languages/postis.pot

    r2295413 r2415872  
    2323
    2424
     25
     26
     27
     28#: inc/admin.php:813
     29msgid "Shipment Print Status"
     30msgstr ""
     31
     32#: inc/admin.php:814
     33msgid "Printed"
     34msgstr ""
     35
     36#: inc/admin.php:815
     37msgid "Not printed"
     38msgstr ""
     39
     40
     41
     42#: inc/admin.class.php:534
     43msgid "Create Shipments"
     44msgstr ""
     45
     46#: inc/admin.class.php:535
     47msgid "Print Shipment PDF"
     48msgstr ""
     49
     50#: inc/admin.class.php:536
     51msgid "Mark as printed"
     52msgstr ""
     53
     54#: inc/admin.class.php:537
     55msgid "Mark as not printed"
     56msgstr ""
     57
     58
     59
     60
     61
     62#: inc/admin.class.php:685
     63msgid "Tarriff Number"
     64msgstr ""
     65
     66#: inc/admin.class.php:688
     67msgid "Tarriff Number. Needs to be 6 or 8 numbers"
     68msgstr ""
     69
     70#: inc/admin.class.php:694
     71msgid "Description in english"
     72msgstr ""
     73
     74#: inc/admin.class.php:697
     75msgid "This needs to be written in english!"
     76msgstr ""
     77
     78
     79
     80
     81
     82
    2583#: templates/shipment-options.php:58
    2684msgid "Extra Options"
  • posturinn/tags/1.0.8/readme.txt

    r2402610 r2415872  
    33Tags: shipping, posturinn, icelandic post shipping, shipping rates, woocommerce
    44Requires at least: 4.3
    5 Tested up to: 5.5.1
     5Tested up to: 5.5.3
    66Requires PHP: 5.6
    77Stable tag: trunk
     
    2626
    2727== Changelog ==
     28= 1.0.8 =
     29Add bulk actions for createShipment
     30Add bulk actions for printing shipments
     31Add bulk actions for marking shipments as printed or not printed
     32Add filter by printed or not printed
     33Add admin class
     34Fixed phoneNumber issue on DPP and DPH shipments
     35
     36
    2837= 1.0.7 =
    2938Add postbox sort by nearest postcode
  • posturinn/tags/1.0.8/wc-posturinn-shipping-api.php

    r2402610 r2415872  
    33 * Plugin Name: Pósturinn's Shipping with WooCommerce
    44 * Description: This plugin is an WooCommerce extension to extend shipping method with Pósturinn's - Iceland
    5  * Version: 1.0.7
     5 * Version: 1.0.8
    66 * Author: Pósturinn
    77 * Author URI: https://postur.is
     
    3434include plugin_dir_path(__FILE__).'inc/functions.php';
    3535include plugin_dir_path(__FILE__).'inc/callbacks.php';
    36 include plugin_dir_path(__FILE__).'inc/admin.php';
     36include plugin_dir_path(__FILE__).'inc/admin.class.php';
     37// include plugin_dir_path(__FILE__).'inc/admin.php';
    3738include plugin_dir_path(__FILE__).'inc/checkout-fields.class.php';
    3839
     
    131132    $pdf->Output();
    132133}
     134
     135function postis_merge_pdf_files($pdf_files, $pdf_path){
     136    $pdf_width         = postis_get_settings( 'pdf_width' );
     137    $pdf_height        = postis_get_settings( 'pdf_height' );
     138    $pdf_rotate        = postis_get_settings( 'pdf_rotate' );
     139    $pdf_orientation   = postis_get_settings( 'pdf_orientation' );
     140    $pdf_moveright     = postis_get_settings( 'pdf_moveright' );
     141    $pdf_movedown      = postis_get_settings( 'pdf_movedown' );
     142    $pdf_biggerbarcode = postis_get_settings( 'pdf_biggerbarcode' );
     143    $pdf_size   = array($pdf_width, $pdf_height, 'Rotate' => $pdf_rotate);
     144   
     145    $pdf = new FPDI();
     146
     147    foreach ($pdf_files as $file) {
     148       
     149        if (!empty($file)) {
     150           
     151            $pageCount = $pdf->setSourceFile($file);
     152           
     153            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
     154               
     155                // import a page
     156                $templateId = $pdf->importPage($pageNo);
     157               
     158                $pdf->AddPage($pdf_orientation,$pdf_size);
     159       
     160                $pdf->useTemplate($templateId, $pdf_moveright, $pdf_movedown, $pdf_biggerbarcode);
     161            }
     162        }
     163    }
     164   
     165    $pdf->Output($pdf_path,"F");
     166}
  • posturinn/trunk/inc/admin.php

    r2396143 r2415872  
    313313       
    314314    }else{
    315         // if (substr($customer_phone, 0, 1) === '6' || substr($customer_phone, 0, 1) === '7' || substr($customer_phone, 0, 1) === '8') {
    316            
    317         // } else {
    318         //     $customer_phone = '';
    319         // }
     315        if ($shipping_service == 'DPP' OR $shipping_service == 'DPH') {
     316            if (substr($customer_phone, 0, 1) === '6' || substr($customer_phone, 0, 1) === '7' || substr($customer_phone, 0, 1) === '8') {
     317                // phoneNumber is valid
     318            } else {
     319                $valid_phonenumber = '';
     320            }
     321        }
    320322        $recipeint = array( 'name'         => $shipping_customerName,
    321323                            'addressLine1' => $shipping_address1,
     
    454456    if ($automatic_printing == 'yes') {
    455457        $print_response = wp_remote_post( $print_query, $print_headers );
    456         // postis_pa($print_response);
    457     }
     458       
     459        $print_response_code = wp_remote_retrieve_response_code( $print_response );
     460       
     461        if ($print_response_code == 204 ) {
     462            update_post_meta( $order_id, 'postis_is_shipment_printed', 'printed' );
     463        }else{
     464            update_post_meta( $order_id, 'postis_is_shipment_printed', 'not_printed' );
     465        }
     466    }
     467   
     468    // postis_pa($print_response_code); exit;
    458469   
    459470   
     
    572583           
    573584            if ($shipment_status == true && $get_shipment_meta != '') {
    574                 echo '<a class="button button-primary" href="'.esc_url($pdf_url).'" target="'.esc_attr($open_pdf_status).'">'. __("Get PDF", "postis").'</a>';
     585               
     586                $print_status = get_post_meta( $order_id, 'postis_is_shipment_printed', true );
     587               
     588                if ($print_status == 'printed') {
     589                    $tooltip = __('Shipment Printed', 'postis');
     590                    $icon = '<span data-tip="'.esc_attr($tooltip).'" class="tips dashicons dashicons-yes" style="color:#00ff00;margin-top: 4px;"></span>';
     591                }else{
     592                    $icon = '';
     593                }
     594               
     595                echo '<a class="button button-primary" href="'.esc_url($pdf_url).'" target="'.esc_attr($open_pdf_status).'">'. __("Get PDF", "postis"). $icon .'</a>';
    575596            }else{
    576597                echo '--';
     
    581602
    582603
    583 function postis_get_shipment_data($order_id, $shipmet_key){
    584    
    585     $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
     604// function postis_get_shipment_data($order_id, $shipmet_key){
     605   
     606//     $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
    586607     
    587     $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
    588    
    589     return $postval;
    590 }
     608//     $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
     609   
     610//     return $postval;
     611// }
    591612
    592613add_action( 'woocommerce_product_options_shipping', 'postis_product_custom_field' );
     
    626647    update_post_meta($post_id, 'descriptionOfContents', sanitize_text_field($descContents));
    627648}
     649
     650add_filter( 'bulk_actions-edit-shop_order', 'postis_order_bulk_action_option', 20, 1 );
     651function postis_order_bulk_action_option( $actions ) {
     652    $actions['create_shipment'] = __( 'CreateShipment', 'postis' );
     653    $actions['print_shipment'] = __( 'PrintShipments', 'postis' );
     654    return $actions;
     655}
     656
     657add_filter( 'handle_bulk_actions-edit-shop_order', 'postis_bulk_action_process', 10, 3 );
     658function postis_bulk_action_process( $redirect_to, $action, $post_ids ) {
     659    // if ( $action !== 'create_shipment' || $action !== 'print_shipment')
     660    //     return $redirect_to;
     661
     662    $processed_ids = array();
     663    $recipeint = array();
     664   
     665    $postis_apikey = postis_get_settings( 'apikey' );
     666    $domain = $_SERVER['HTTP_HOST'];
     667    $endpoint_url = postis_get_endpoints( 'create_shipment' );
     668   
     669    if ($action === 'create_shipment') {
     670       
     671        foreach ( $post_ids as $post_id ) {
     672           
     673            $order = wc_get_order( $post_id );
     674            $ship_methods          = $order->get_shipping_methods();
     675            $shipping_customerName = $order->get_formatted_shipping_full_name();
     676            $shipping_address1     = $order->get_shipping_address_1();
     677            $shipping_postcode     = $order->get_shipping_postcode();
     678            $country_code          = $order->get_shipping_country();
     679            $city                  = $order->get_shipping_city();
     680            $customer_email        = $order->get_billing_email();
     681            $customer_phone        = $order->get_billing_phone();
     682           
     683            $shipping_service      = get_post_meta( $post_id, 'postis_shipping_method', true );
     684           
     685            $recipeint = array( 'name'         => $shipping_customerName,
     686                                'addressLine1' => $shipping_address1,
     687                                "postcode"     => $shipping_postcode,
     688                                "countryCode"  => $country_code,
     689                                "mobilePhone"  => $customer_phone,
     690                            );
     691                           
     692            $recipeint['email'] =  $customer_email;
     693            $options = array('deliveryServiceId' => $shipping_service);
     694            $params = array(
     695                    'recipient'                => $recipeint,
     696                    'options'                  => $options,
     697                );
     698           
     699            $order_data = $order->get_data();
     700           
     701            $params = array_filter( $params );
     702       
     703            // postis_pa($params); exit;
     704           
     705            // Set Header
     706            $headers = array(
     707                    'headers'     => array('Content-Type' => 'application/json; charset=utf-8', 'x-api-key'=>$postis_apikey,'domain_name'=> $domain),
     708                    'body'        => json_encode($params),
     709                    'method'      => 'POST',
     710                    'data_format' => 'body',
     711                );
     712                   
     713            // Run the query
     714            $response = wp_remote_post( $endpoint_url, $headers );
     715            $get_shipment_meta = json_decode( $response['body'], true );
     716           
     717           
     718            // postis_pa($get_shipment_meta); exit;
     719           
     720            if(  $response['response']['code'] != 400 && $response['response']['code'] != 401 ) {
     721           
     722                update_post_meta( $post_id, 'postis_shipment_meta', $get_shipment_meta );
     723               
     724                $ajax_response = array('status'=>'success', 'message'=> __('Shipment Created Successfully', 'postis'));
     725                $res_msg = 'created';
     726               
     727            }else{
     728                $resp_message  = sprintf( __("Shipment Not Created.\nServer Response: %s", "postis"), $get_shipment_meta['message'] );
     729                $res_msg = 'failed';
     730               
     731                if (strpos($get_shipment_meta['message'], 'Ekki var hægt að skrá sendingu (Addressee.Gsm') !== false) {
     732                    $ajax_response = array('status'=>'error', 'type'=>'phonenumber', 'message'=> $resp_message );
     733                } else {
     734                    $ajax_response = array('status'=>'error', 'type'=>'other', 'message'=> $resp_message );
     735                }
     736               
     737            }
     738           
     739            $processed_ids[] = $post_id;
     740        }
     741    }else if($action === 'print_shipment'){
     742        foreach ( $post_ids as $post_id ) {
     743           
     744            $shipmentId         =  postis_get_shipment_data($post_id, 'shipmentId');
     745           
     746            $print_endpoint = postis_get_endpoints( 'print' );
     747            $print_params = array(
     748                'shipmentId' => $shipmentId,
     749                'outputFormat'      => 'poststod'
     750            );
     751            $print_params = array_filter( $print_params );
     752           
     753           
     754            // Query format parameters.
     755            $print_query = add_query_arg( $print_params, $print_endpoint );
     756           
     757            // Set Header
     758            $print_headers = array(
     759                    'headers'     => array('x-api-key'=>$postis_apikey, 'domain_name'=> $domain),
     760                    //'body'        => json_encode($print_params),
     761                    'method'      => 'POST',
     762                    // 'data_format' => 'body',
     763                );
     764            // postis_pa($print_headers);   
     765                   
     766            // Run the query
     767            $automatic_printing = postis_get_settings( 'pdf_print' );
     768            if ($automatic_printing == 'yes') {
     769                $print_response = wp_remote_post( $print_query, $print_headers );
     770               
     771                $print_response_code = wp_remote_retrieve_response_code( $print_response );
     772                   
     773                if ($print_response_code == 204 ) {
     774                    update_post_meta( $post_id, 'postis_is_shipment_printed', 'printed' );
     775                }else{
     776                    update_post_meta( $post_id, 'postis_is_shipment_printed', 'not_printed' );
     777                }
     778               
     779                // postis_pa($print_response); exit;
     780            }
     781           
     782        }
     783    }else{
     784        return $redirect_to;
     785    }
     786
     787    return $redirect_to = add_query_arg( array(
     788        'processed_count' => count( $processed_ids ),
     789        'status' => $res_msg,
     790    ), $redirect_to );
     791}
     792
     793if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
     794
     795    // adds the coupon filtering dropdown to the orders page
     796    add_action( 'restrict_manage_posts', 'filter_orders_by_coupon_used' );
     797
     798    // makes coupons filterable
     799//  add_filter( 'posts_join',  'add_order_items_join' );
     800//  add_filter( 'posts_where', 'add_filterable_where' );
     801
     802    add_filter( 'request', 'filter_orders_by_payment_method_query' );   
     803}
     804
     805function filter_orders_by_coupon_used() {
     806    global $typenow;
     807
     808    if ( 'shop_order' === $typenow ) {
     809
     810        ?>
     811        <select name="postis_shipment_print_status" id="postis_shipment_print_status">
     812            <option value=""><?php esc_html_e( 'Shipment Print Status', 'postis' ); ?></option>
     813            <option value="printed"><?php esc_html_e( 'Printed', 'postis' ); ?></option>
     814            <option value="not_printed"><?php esc_html_e( 'Not printed', 'postis' ); ?></option>
     815        </select>
     816        <?php
     817    }
     818}
     819
     820function filter_orders_by_payment_method_query( $vars ) {
     821    global $typenow;
     822
     823    if ( 'shop_order' === $typenow && isset( $_GET['postis_shipment_print_status'] ) && ! empty( $_GET['postis_shipment_print_status'] ) ) {
     824
     825        $vars['meta_key']   = 'postis_is_shipment_printed';
     826        $vars['meta_value'] = wc_clean( $_GET['postis_shipment_print_status'] );
     827    }
     828
     829    return $vars;
     830}
  • posturinn/trunk/inc/functions.php

    r2402610 r2415872  
    390390   return apply_filters('postis_international_contents_fields',$options);
    391391}
     392
     393function postis_get_shipment_data($order_id, $shipmet_key){
     394   
     395    $shipment_meta = get_post_meta($order_id, 'postis_shipment_meta', true );
     396     
     397    $postval       = isset($shipment_meta[$shipmet_key]) ? $shipment_meta[$shipmet_key] : '';
     398   
     399    return $postval;
     400}
  • posturinn/trunk/languages/postis-is_IS.po

    r2334877 r2415872  
    33"Project-Id-Version: Pósturinn's Shipping with WooCommerce\n"
    44"POT-Creation-Date: 2020-06-24 12:20+0000\n"
    5 "PO-Revision-Date: 2020-07-01 08:38+0000\n"
     5"PO-Revision-Date: 2020-11-10 13:33+0000\n"
    66"Last-Translator: Aron Hallsson <[email protected]>\n"
    77"Language-Team: Aron Hallsson <[email protected]>\n"
     
    1111"Content-Transfer-Encoding: 8bit\n"
    1212"Plural-Forms: nplurals=2; plural=(n%10==1 && n%100!=11);\n"
    13 "X-Generator: Poedit 2.3.1\n"
     13"X-Generator: Poedit 2.4.1\n"
    1414"X-Poedit-Basepath: ..\n"
    1515"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
     
    2121"X-Poedit-SearchPathExcluded-0: *.min.js\n"
    2222
     23#: inc/admin.php:813
     24msgid "Shipment Print Status"
     25msgstr "Prent staða"
     26
     27#: inc/admin.php:814
     28msgid "Printed"
     29msgstr "Prentað"
     30
     31#: inc/admin.php:815
     32msgid "Not printed"
     33msgstr "Ekki prentað"
     34
     35#: inc/admin.class.php:534
     36msgid "Create Shipments"
     37msgstr "Búa til sendingarmiða"
     38
     39#: inc/admin.class.php:535
     40msgid "Print Shipment PDF"
     41msgstr "Prenta sendingarmiða"
     42
     43#: inc/admin.class.php:536
     44msgid "Mark as printed"
     45msgstr "Merkja sem prentað"
     46
     47#: inc/admin.class.php:537
     48msgid "Mark as not printed"
     49msgstr "Merkja sem EKKI prentað"
     50
     51
     52#: inc/admin.class.php:685
     53msgid "Tarriff Number"
     54msgstr "Tollnúmer"
     55
     56#: inc/admin.class.php:688
     57msgid "Tarriff Number. Needs to be 6 or 8 numbers"
     58msgstr "Tollnúmer. Þarf að vera 6 eða 8 tölustafir"
     59
     60#: inc/admin.class.php:694
     61msgid "Description in english"
     62msgstr "Lýsing tollvöru á ensku"
     63
     64#: inc/admin.class.php:697
     65msgid "This needs to be written in english!"
     66msgstr "Þetta þarf að vera skrifað á ensku!"
     67
     68
     69
    2370#: inc/postis.class.php:125
    2471msgid "Use Shipping Price"
     
    3178#: inc/postis.class.php:133
    3279msgid "Include Woocommerce VAT"
    33 msgstr "Reikna með Woocommerce VSK útreikning."
     80msgstr "Reikna með Woocommerce VSK útreikning"
    3481
    3582#: inc/postis.class.php:137
  • posturinn/trunk/languages/postis.pot

    r2295413 r2415872  
    2323
    2424
     25
     26
     27
     28#: inc/admin.php:813
     29msgid "Shipment Print Status"
     30msgstr ""
     31
     32#: inc/admin.php:814
     33msgid "Printed"
     34msgstr ""
     35
     36#: inc/admin.php:815
     37msgid "Not printed"
     38msgstr ""
     39
     40
     41
     42#: inc/admin.class.php:534
     43msgid "Create Shipments"
     44msgstr ""
     45
     46#: inc/admin.class.php:535
     47msgid "Print Shipment PDF"
     48msgstr ""
     49
     50#: inc/admin.class.php:536
     51msgid "Mark as printed"
     52msgstr ""
     53
     54#: inc/admin.class.php:537
     55msgid "Mark as not printed"
     56msgstr ""
     57
     58
     59
     60
     61
     62#: inc/admin.class.php:685
     63msgid "Tarriff Number"
     64msgstr ""
     65
     66#: inc/admin.class.php:688
     67msgid "Tarriff Number. Needs to be 6 or 8 numbers"
     68msgstr ""
     69
     70#: inc/admin.class.php:694
     71msgid "Description in english"
     72msgstr ""
     73
     74#: inc/admin.class.php:697
     75msgid "This needs to be written in english!"
     76msgstr ""
     77
     78
     79
     80
     81
     82
    2583#: templates/shipment-options.php:58
    2684msgid "Extra Options"
  • posturinn/trunk/readme.txt

    r2402610 r2415872  
    33Tags: shipping, posturinn, icelandic post shipping, shipping rates, woocommerce
    44Requires at least: 4.3
    5 Tested up to: 5.5.1
     5Tested up to: 5.5.3
    66Requires PHP: 5.6
    77Stable tag: trunk
     
    2626
    2727== Changelog ==
     28= 1.0.8 =
     29Add bulk actions for createShipment
     30Add bulk actions for printing shipments
     31Add bulk actions for marking shipments as printed or not printed
     32Add filter by printed or not printed
     33Add admin class
     34Fixed phoneNumber issue on DPP and DPH shipments
     35
     36
    2837= 1.0.7 =
    2938Add postbox sort by nearest postcode
  • posturinn/trunk/wc-posturinn-shipping-api.php

    r2402610 r2415872  
    33 * Plugin Name: Pósturinn's Shipping with WooCommerce
    44 * Description: This plugin is an WooCommerce extension to extend shipping method with Pósturinn's - Iceland
    5  * Version: 1.0.7
     5 * Version: 1.0.8
    66 * Author: Pósturinn
    77 * Author URI: https://postur.is
     
    3434include plugin_dir_path(__FILE__).'inc/functions.php';
    3535include plugin_dir_path(__FILE__).'inc/callbacks.php';
    36 include plugin_dir_path(__FILE__).'inc/admin.php';
     36include plugin_dir_path(__FILE__).'inc/admin.class.php';
     37// include plugin_dir_path(__FILE__).'inc/admin.php';
    3738include plugin_dir_path(__FILE__).'inc/checkout-fields.class.php';
    3839
     
    131132    $pdf->Output();
    132133}
     134
     135function postis_merge_pdf_files($pdf_files, $pdf_path){
     136    $pdf_width         = postis_get_settings( 'pdf_width' );
     137    $pdf_height        = postis_get_settings( 'pdf_height' );
     138    $pdf_rotate        = postis_get_settings( 'pdf_rotate' );
     139    $pdf_orientation   = postis_get_settings( 'pdf_orientation' );
     140    $pdf_moveright     = postis_get_settings( 'pdf_moveright' );
     141    $pdf_movedown      = postis_get_settings( 'pdf_movedown' );
     142    $pdf_biggerbarcode = postis_get_settings( 'pdf_biggerbarcode' );
     143    $pdf_size   = array($pdf_width, $pdf_height, 'Rotate' => $pdf_rotate);
     144   
     145    $pdf = new FPDI();
     146
     147    foreach ($pdf_files as $file) {
     148       
     149        if (!empty($file)) {
     150           
     151            $pageCount = $pdf->setSourceFile($file);
     152           
     153            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
     154               
     155                // import a page
     156                $templateId = $pdf->importPage($pageNo);
     157               
     158                $pdf->AddPage($pdf_orientation,$pdf_size);
     159       
     160                $pdf->useTemplate($templateId, $pdf_moveright, $pdf_movedown, $pdf_biggerbarcode);
     161            }
     162        }
     163    }
     164   
     165    $pdf->Output($pdf_path,"F");
     166}
Note: See TracChangeset for help on using the changeset viewer.