Changeset 2894437
- Timestamp:
- 04/05/2023 02:10:30 PM (3 years ago)
- Location:
- ship-to-ecourier
- Files:
-
- 112 added
- 18 edited
-
tags/1.1.1 (added)
-
tags/1.1.1/LICENSE (added)
-
tags/1.1.1/assets (added)
-
tags/1.1.1/assets/css (added)
-
tags/1.1.1/assets/css/admin.css (added)
-
tags/1.1.1/assets/css/frontend.css (added)
-
tags/1.1.1/assets/images (added)
-
tags/1.1.1/assets/images/menu_icon.png (added)
-
tags/1.1.1/assets/images/not-found.svg (added)
-
tags/1.1.1/assets/js (added)
-
tags/1.1.1/assets/js/admin.js (added)
-
tags/1.1.1/assets/js/frontend.js (added)
-
tags/1.1.1/assets/js/lodash.js (added)
-
tags/1.1.1/assets/js/moment.js (added)
-
tags/1.1.1/composer.json (added)
-
tags/1.1.1/includes (added)
-
tags/1.1.1/includes/Admin (added)
-
tags/1.1.1/includes/Admin.php (added)
-
tags/1.1.1/includes/Admin/Menu.php (added)
-
tags/1.1.1/includes/Admin/STE_Metabox.php (added)
-
tags/1.1.1/includes/Admin/STE_Order_Status_Shipped.php (added)
-
tags/1.1.1/includes/Admin/Settings.php (added)
-
tags/1.1.1/includes/Admin/index.php (added)
-
tags/1.1.1/includes/Admin/views (added)
-
tags/1.1.1/includes/Admin/views/settings-view.php (added)
-
tags/1.1.1/includes/Admin/views/ste-booking-metabox-view.php (added)
-
tags/1.1.1/includes/Ajax.php (added)
-
tags/1.1.1/includes/Appsero_Tracker.php (added)
-
tags/1.1.1/includes/Assets.php (added)
-
tags/1.1.1/includes/Ecourier_Handler.php (added)
-
tags/1.1.1/includes/Frontend (added)
-
tags/1.1.1/includes/Frontend.php (added)
-
tags/1.1.1/includes/Frontend/Parcel_Tracker_Shortcode.php (added)
-
tags/1.1.1/includes/Frontend/index.php (added)
-
tags/1.1.1/includes/Frontend/views (added)
-
tags/1.1.1/includes/Frontend/views/form-parcel-tracker.php (added)
-
tags/1.1.1/includes/Installer.php (added)
-
tags/1.1.1/includes/functions.php (added)
-
tags/1.1.1/includes/index.php (added)
-
tags/1.1.1/index.php (added)
-
tags/1.1.1/readme.txt (added)
-
tags/1.1.1/ship-to-ecourier.php (added)
-
tags/1.1.1/uninstall.php (added)
-
tags/1.1.1/vendor (added)
-
tags/1.1.1/vendor/appsero (added)
-
tags/1.1.1/vendor/appsero/client (added)
-
tags/1.1.1/vendor/appsero/client/.git (added)
-
tags/1.1.1/vendor/appsero/client/.git/HEAD (added)
-
tags/1.1.1/vendor/appsero/client/.git/ORIG_HEAD (added)
-
tags/1.1.1/vendor/appsero/client/.git/config (added)
-
tags/1.1.1/vendor/appsero/client/.git/description (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/applypatch-msg.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/commit-msg.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/fsmonitor-watchman.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/post-update.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/pre-applypatch.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/pre-commit.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/pre-push.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/pre-rebase.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/pre-receive.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/prepare-commit-msg.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/hooks/update.sample (added)
-
tags/1.1.1/vendor/appsero/client/.git/index (added)
-
tags/1.1.1/vendor/appsero/client/.git/info (added)
-
tags/1.1.1/vendor/appsero/client/.git/info/exclude (added)
-
tags/1.1.1/vendor/appsero/client/.git/info/refs (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/HEAD (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs/heads (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs/heads/develop (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs/remotes (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs/remotes/origin (added)
-
tags/1.1.1/vendor/appsero/client/.git/logs/refs/remotes/origin/HEAD (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects/info (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects/info/packs (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects/pack (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects/pack/pack-92e0a31e4261a8edc41a03c78339646696fa73c2.idx (added)
-
tags/1.1.1/vendor/appsero/client/.git/objects/pack/pack-92e0a31e4261a8edc41a03c78339646696fa73c2.pack (added)
-
tags/1.1.1/vendor/appsero/client/.git/packed-refs (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/heads (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/heads/develop (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/remotes (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/remotes/origin (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/remotes/origin/HEAD (added)
-
tags/1.1.1/vendor/appsero/client/.git/refs/tags (added)
-
tags/1.1.1/vendor/appsero/client/.gitignore (added)
-
tags/1.1.1/vendor/appsero/client/composer.json (added)
-
tags/1.1.1/vendor/appsero/client/readme.md (added)
-
tags/1.1.1/vendor/appsero/client/src (added)
-
tags/1.1.1/vendor/appsero/client/src/Client.php (added)
-
tags/1.1.1/vendor/appsero/client/src/Insights.php (added)
-
tags/1.1.1/vendor/appsero/client/src/License.php (added)
-
tags/1.1.1/vendor/appsero/client/src/Updater.php (added)
-
tags/1.1.1/vendor/autoload.php (added)
-
tags/1.1.1/vendor/composer (added)
-
tags/1.1.1/vendor/composer/ClassLoader.php (added)
-
tags/1.1.1/vendor/composer/InstalledVersions.php (added)
-
tags/1.1.1/vendor/composer/LICENSE (added)
-
tags/1.1.1/vendor/composer/autoload_classmap.php (added)
-
tags/1.1.1/vendor/composer/autoload_files.php (added)
-
tags/1.1.1/vendor/composer/autoload_namespaces.php (added)
-
tags/1.1.1/vendor/composer/autoload_psr4.php (added)
-
tags/1.1.1/vendor/composer/autoload_real.php (added)
-
tags/1.1.1/vendor/composer/autoload_static.php (added)
-
tags/1.1.1/vendor/composer/installed.json (added)
-
tags/1.1.1/vendor/composer/installed.php (added)
-
tags/1.1.1/vendor/composer/platform_check.php (added)
-
trunk/assets/js/admin.js (modified) (4 diffs)
-
trunk/includes/Admin/STE_Metabox.php (modified) (3 diffs)
-
trunk/includes/Admin/views/ste-booking-metabox-view.php (modified) (4 diffs)
-
trunk/includes/Ajax.php (modified) (11 diffs)
-
trunk/includes/Ecourier_Handler.php (added)
-
trunk/includes/functions.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/ship-to-ecourier.php (modified) (6 diffs)
-
trunk/vendor/autoload.php (modified) (1 diff)
-
trunk/vendor/composer/ClassLoader.php (modified) (17 diffs)
-
trunk/vendor/composer/InstalledVersions.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_files.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_namespaces.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_psr4.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_real.php (modified) (3 diffs)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.json (modified) (1 diff)
-
trunk/vendor/composer/installed.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ship-to-ecourier/trunk/assets/js/admin.js
r2528332 r2894437 14 14 let bookingForm = $( '#ste-booking-metabox-form' ); 15 15 let bookingMetaBoxMessage = $( '#ste-booking-metabox-message' ); 16 let recipientCity = $( '#recipient_city' ); 17 let recipientArea = $( '#recipient_area' ); 18 let recipientThana = $( '#recipient_thana' ); 19 let recipientZip = $( '#recipient_zip' ); 20 21 /** 22 * Setting area on change of city/district. 23 */ 24 recipientCity.on( 'change', function ( event ) { 25 let data = { 26 action: 'ste_get_area_by_district', 27 district: this.value, 28 _nonce: STE_ADMIN.nonce, 29 }; 30 31 recipientArea.prop( 'disabled', true ); 32 33 $.post( STE_ADMIN.ajaxurl, data, function ( response ) { 34 recipientArea.empty(); 35 recipientThana.val( '' ); 36 recipientZip.val( '' ); 37 38 if ( ! response.success ) { 39 errorMessage.text( response.data ); 40 parcelSubmitButton.prop( 'disabled', true ); 41 return; 42 } 43 44 errorMessage.text( '' ); 45 46 recipientArea.prop( 'disabled', false ); 47 48 let areas = response.data; 49 50 areas.map( function ( area, index ) { 51 recipientArea.append( `<option data-thana="${area.thana}" data-post_code="${area.post_code}" value="${area.name.toLowerCase()}">${area.name}</option>` ); 52 53 if ( index === 0 ) { 54 recipientThana.val( area.thana ); 55 recipientZip.val( area.post_code ); 56 } 57 } ); 58 } ); 59 } ); 60 61 /** 62 * Setting thana and post code on change of area. 63 */ 64 recipientArea.on( 'change', function ( event ) { 65 let optionSelected = $( 'option:selected', this ); 66 67 recipientThana.val( optionSelected.data( 'thana' ) ); 68 recipientZip.val( optionSelected.data( 'post_code' ) ); 69 } ); 16 70 17 71 parcelSubmitButton.on("click", function (e) { … … 34 88 comments: $( "#comments", bookingFormWrap ).val(), 35 89 submit_ste_ecourier_parcel: $( "#submit_ste_ecourier_parcel", bookingFormWrap ).val(), 90 original_order_number: $( "#original_order_number", bookingFormWrap ).val(), 36 91 action: 'ste_booking_metabox_form', 37 92 _nonce: STE_ADMIN.nonce, … … 113 168 let orderData = { 114 169 tracking: cancleOrderButton.val(), 170 original_order_number: $( '#original_order_number' ).val(), 115 171 action: 'ste_cancel_parcel_request', 116 172 _nonce: STE_ADMIN.nonce, … … 118 174 119 175 $.post(STE_ADMIN.ajaxurl, orderData, function (response) { 120 console.log( response );121 176 if (!response.success) { 122 177 errorMessage.text(response.data.message); -
ship-to-ecourier/trunk/includes/Admin/STE_Metabox.php
r2525816 r2894437 64 64 // Set all necessary Shipping Information. 65 65 $this->set_shipping_info( $theorder ); 66 67 $cities = ship_to_ecourier()->ecourier->get_city_list(); 68 69 if ( is_wp_error( $cities ) ) { 70 $cities = []; 71 } 72 73 $areas = ship_to_ecourier()->ecourier->get_area_by_district( $this->shipping_info['recipient_city'] ); 74 75 if ( is_wp_error( $cities ) ) { 76 $areas = []; 77 } 78 66 79 } else { 67 80 $order_shipped->user = get_user_by( 'ID', $order_shipped->created_by )->display_name; … … 85 98 $this->shipping_info['recipient_name'] = '' !== trim( $order->get_formatted_shipping_full_name() ) ? $order->get_formatted_shipping_full_name() : $order->get_formatted_billing_full_name(); 86 99 $this->shipping_info['recipient_mobile'] = $order->get_billing_phone(); 87 $this->shipping_info['recipient_city'] = '' !== trim( $order->get_shipping_ city() ) ? $order->get_shipping_city() : $order->get_billing_city();88 $this->shipping_info['recipient_area'] = '' ;100 $this->shipping_info['recipient_city'] = '' !== trim( $order->get_shipping_state() ) ? strtolower( $order->get_shipping_state() ) : strtolower( $order->get_billing_state() ); 101 $this->shipping_info['recipient_area'] = '' !== trim( $order->get_shipping_city() ) ? strtolower( $order->get_shipping_city() ) : strtolower( $order->get_billing_city() ); 89 102 $this->shipping_info['recipient_thana'] = ''; 90 103 $this->shipping_info['recipient_zip'] = '' !== trim( $order->get_shipping_postcode() ) ? $order->get_shipping_postcode() : $order->get_billing_postcode(); … … 100 113 $this->shipping_info['comments'] .= $item->get_name() . ' x' . $item->get_quantity() . PHP_EOL; 101 114 } 115 116 $this->shipping_info = apply_filters( 'ste_set_shipping_info', $this->shipping_info, $order ); 102 117 } 103 118 -
ship-to-ecourier/trunk/includes/Admin/views/ste-booking-metabox-view.php
r2528332 r2894437 5 5 * @package SendToEcourier\Admin 6 6 */ 7 8 $recipient_thana = ''; 9 $recipient_post_code = ''; 7 10 8 11 ?> … … 21 24 </li> 22 25 <li class="wide"> 23 <label for="recipient_city"><?php esc_attr_e( 'Recipient City', 'ship-to-ecourier' ); ?></label> 24 <input class="input-text" type="text" name="recipient_city" id="recipient_city" placeholder="<?php esc_attr__( 'Recipient City', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $this->shipping_info['recipient_city'] ); ?>"> 26 <label for="recipient_city"><?php esc_attr_e( 'Recipient District', 'ship-to-ecourier' ); ?></label> 27 <select name="recipient_city" id="recipient_city" class="wc-enhanced-select"> 28 <?php 29 foreach ( $cities as $city ) : 30 $city_val = strtolower( $city['value'] ); 31 ?> 32 <option value="<?php echo $city_val; ?>" <?php echo $city_val === $this->shipping_info['recipient_city'] ? 'selected' : false; ?> ><?php echo $city['name']; ?></option> 33 <?php endforeach; ?> 34 </select> 25 35 </li> 26 36 <li class="wide"> 27 37 <label for="recipient_area"><?php esc_attr_e( 'Recipient Area', 'ship-to-ecourier' ); ?></label> 28 <input class="input-text" type="text" name="recipient_area" id="recipient_area" placeholder="<?php esc_attr__( 'Recipient Area', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $this->shipping_info['recipient_area'] ); ?>"> 38 39 <select name="recipient_area" id="recipient_area" class="wc-enhanced-select"> 40 <?php 41 foreach ( $areas as $area ) : 42 $area_val = strtolower( $area['name'] ); 43 44 if ( $area_val === $this->shipping_info['recipient_area'] ) { 45 $recipient_thana = strtolower( $area['thana'] ); 46 $recipient_post_code = $area['post_code']; 47 } 48 ?> 49 <option 50 data-thana="<?php echo $area['thana']; ?>" 51 data-post_code="<?php echo $area['post_code']; ?>" 52 value="<?php echo $area_val; ?>" <?php echo $area_val === $this->shipping_info['recipient_area'] ? 'selected' : false; ?> > 53 <?php echo $area['name']; ?> 54 </option> 55 <?php endforeach; ?> 56 </select> 29 57 </li> 30 58 <li class="wide"> 31 59 <label for="recipient_thana"><?php esc_attr_e( 'Recipient Thana', 'ship-to-ecourier' ); ?></label> 32 <input class="input-text" type="text" name="recipient_thana" id="recipient_thana" placeholder="<?php esc_attr__( 'Recipient Thana', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $ this->shipping_info['recipient_thana'] ); ?>">60 <input class="input-text" type="text" name="recipient_thana" id="recipient_thana" placeholder="<?php esc_attr__( 'Recipient Thana', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $recipient_thana ); ?>" readonly> 33 61 </li> 34 62 <li class="wide"> 35 63 <label for="recipient_zip"><?php esc_attr_e( 'Recipient Zip', 'ship-to-ecourier' ); ?></label> 36 <input class="input-text" type="text" name="recipient_zip" id="recipient_zip" placeholder="<?php esc_attr__( 'Recipient Zip', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $ this->shipping_info['recipient_zip'] ); ?>">64 <input class="input-text" type="text" name="recipient_zip" id="recipient_zip" placeholder="<?php esc_attr__( 'Recipient Zip', 'ship-to-ecourier' ); ?>" value="<?php echo esc_attr( $recipient_post_code ); ?>" readonly> 37 65 </li> 38 66 <li class="wide"> … … 42 70 <li class="wide"> 43 71 <label for="payment_method"><?php esc_attr_e( 'Payment Method', 'ship-to-ecourier' ); ?></label> 44 <select name="payment_method" id="payment_method" >45 <option value="CCRD" ><?php esc_html_e( 'Card Payment', 'ship-to-ecourier' ); ?></option>72 <select name="payment_method" id="payment_method" class="wc-enhanced-select"> 73 <option value="CCRD" <?php echo 'ccrd' === $this->shipping_info['payment_method'] ? 'selected' : false; ?>><?php esc_html_e( 'Card Payment', 'ship-to-ecourier' ); ?></option> 46 74 <option value="COD" <?php echo 'cod' === $this->shipping_info['payment_method'] ? 'selected' : false; ?>><?php esc_html_e( 'Cash On Delivery', 'ship-to-ecourier' ); ?></option> 47 <option value="MPAY" ><?php esc_html_e( 'Mobile Payment', 'ship-to-ecourier' ); ?></option>48 <option value="POS" ><?php esc_html_e( 'POS', 'ship-to-ecourier' ); ?></option>75 <option value="MPAY" <?php echo 'mpay' === $this->shipping_info['payment_method'] ? 'selected' : false; ?>><?php esc_html_e( 'Mobile Payment', 'ship-to-ecourier' ); ?></option> 76 <option value="POS" <?php echo 'pos' === $this->shipping_info['payment_method'] ? 'selected' : false; ?>><?php esc_html_e( 'POS', 'ship-to-ecourier' ); ?></option> 49 77 </select> 50 78 </li> 51 79 <li class="wide"> 52 80 <label for="package_code"><?php esc_attr_e( 'Package', 'ship-to-ecourier' ); ?></label> 53 <select name="package_code" id="package_code" >81 <select name="package_code" id="package_code" class="wc-enhanced-select"> 54 82 <?php 55 83 foreach ( $this->shipping_info['package_code'] as $package ) { … … 107 135 </div> 108 136 <?php } ?> 137 138 <input type="hidden" name="original_order_number" id="original_order_number" value="<?php echo esc_attr( $post->ID ); ?>"> 109 139 </div> -
ship-to-ecourier/trunk/includes/Ajax.php
r2528332 r2894437 44 44 $this->ecourier_base_url = 'live' === $this->settings['api_environment'] ? STE_API_BASE_URL_LIVE : STE_API_BASE_URL_STAGING; 45 45 46 add_action( 'wp_ajax_ste_get_area_by_district', array( $this, 'handle_ste_get_area_by_district' ) ); 46 47 add_action( 'wp_ajax_ste_parcel_tracking_form', array( $this, 'handle_parcel_tracker_form_submission' ) ); 47 48 add_action( 'wp_ajax_nopriv_ste_parcel_tracking_form', array( $this, 'handle_parcel_tracker_form_submission' ) ); … … 52 53 } 53 54 55 public function handle_ste_get_area_by_district() { 56 if ( ! isset( $_POST['_nonce'] ) || empty( $_POST['district'] ) ) { 57 wp_send_json_error( __( 'Something went wrong here!', 'ship-to-ecourier' ) ); 58 wp_die(); 59 } 60 61 // Block if _nonce field is not available and valid. 62 check_ajax_referer( 'ste-admin-nonce', '_nonce' ); 63 64 $areas = ship_to_ecourier()->ecourier->get_area_by_district( sanitize_text_field( $_POST['district'] ) ); 65 66 if ( is_wp_error( $areas ) ) { 67 wp_send_json_error( $areas->get_error_message() ); 68 wp_die(); 69 } 70 71 wp_send_json_success( $areas ); 72 } 73 54 74 /** 55 75 * Handle the tracking form submission. Get parcel status from eCourier and return back to front end. … … 70 90 // Make request to eCourier API. 71 91 $response = $this->make_request( $ecourier_api_url, array( 'ecr' => $tracking_code ) ); 92 93 if ( is_wp_error( $response ) ) { 94 wp_send_json_error( 95 array( 96 'message' => $response->get_error_data(), 97 ) 98 ); 99 } 72 100 73 101 // Send response to front-end. … … 123 151 ) 124 152 ); 153 return; 125 154 } 126 155 … … 129 158 'recipient_name' => sanitize_text_field( wp_unslash( $_POST['recipient_name'] ) ), 130 159 'recipient_mobile' => sanitize_text_field( wp_unslash( $_POST['recipient_mobile'] ) ), 131 'recipient_city' => sanitize_text_field( wp_unslash( $_POST['recipient_city']) ),132 'recipient_area' => sanitize_text_field( wp_unslash( $_POST['recipient_area']) ),133 'recipient_thana' => sanitize_text_field( wp_unslash( $_POST['recipient_thana']) ),160 'recipient_city' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_city'] ) ) ), 161 'recipient_area' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_area'] ) ) ), 162 'recipient_thana' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_thana'] ) ) ), 134 163 'recipient_zip' => sanitize_text_field( wp_unslash( $_POST['recipient_zip'] ) ), 135 164 'recipient_address' => sanitize_text_field( wp_unslash( $_POST['recipient_address'] ) ), … … 147 176 $response = $this->make_request( $ecourier_api_url, $parcel_data ); 148 177 178 if ( is_wp_error( $response ) ) { 179 wp_send_json_error( 180 array( 181 'message' => $response->get_error_data(), 182 ) 183 ); 184 return; 185 } 186 149 187 $result = json_decode( $response['body'], true ); 150 188 … … 165 203 ) 166 204 ); 205 return; 167 206 } 168 207 169 // Get the order to update the order status. 170 $order = new \WC_Order( $parcel_data['product_id'] ); 208 $user = get_user_by( 'id', get_current_user_id() ); 209 210 $order_shipped_note = ''; 211 212 if ( $user ) { 213 $order_shipped_note = sprintf( 214 __( 'Order shipped to Ecourier by %s', 'ship-to-ecourier' ), 215 $user->display_name 216 ); 217 } 218 219 /** 220 * Get the order to update the order status. 221 * 222 * using original order number here because sometimes the order 223 * number might be modified through `woocommerce_order_number` filter 224 * by third party plugin. 225 */ 226 $order = new \WC_Order( sanitize_text_field( wp_unslash( $_POST['original_order_number'] ) ) ); 227 ! empty( $order_shipped_note ) ? $order->add_order_note( $order_shipped_note ) : null; 171 228 $order->update_status( 'shipped' ); 172 229 } … … 209 266 $response = $this->make_request( $ecourier_api_url, $label_data ); 210 267 268 if ( is_wp_error( $response ) ) { 269 wp_send_json_error( 270 array( 271 'message' => $response->get_error_data(), 272 ) 273 ); 274 } 275 211 276 $result = json_decode( $response['body'], true ); 212 277 … … 244 309 check_ajax_referer( 'ste-admin-nonce', '_nonce' ); 245 310 311 $user = get_user_by( 'id', get_current_user_id() ); 312 246 313 // Generate label print data to send to eCourier. 247 314 $label_data = array( 248 315 'tracking' => sanitize_text_field( wp_unslash( $_POST['tracking'] ) ), 249 'comment' => __( 'Please canc le the parcel.', 'ship-to-ecourier' ),316 'comment' => __( 'Please cancel the parcel. Requested by ' . $user->display_name , 'ship-to-ecourier' ), 250 317 ); 251 318 … … 254 321 // Send parcel cancel request to eCourier. 255 322 $response = $this->make_request( $ecourier_api_url, $label_data ); 323 324 if ( is_wp_error( $response ) ) { 325 wp_send_json_error( 326 array( 327 'message' => $response->get_error_data(), 328 ) 329 ); 330 } 256 331 257 332 $result = json_decode( $response['body'], true ); … … 274 349 ); 275 350 } 351 } 352 353 $order = wc_get_order( wp_unslash( $_POST['original_order_number'] ) ); 354 355 if ( $order instanceof \WC_Order) { 356 $order_cancel_note = ''; 357 358 if ( $user ) { 359 $order_cancel_note = sprintf( 360 __( 'Shipping cancelled at Ecourier by %s', 'ship-to-ecourier' ), 361 $user->display_name 362 ); 363 } 364 365 ! empty( $order_cancel_note ) ? $order->add_order_note( $order_cancel_note ) : null; 366 367 $order->update_status( 'processing' ); 276 368 } 277 369 -
ship-to-ecourier/trunk/includes/functions.php
r2528332 r2894437 43 43 * Get eCourier packages for the connected account. 44 44 * 45 * @return array 45 * @return array|\WP_Error 46 46 */ 47 47 function ste_get_ecourier_packages() { 48 49 $cache_key = 'ste_packages_list'; 50 51 $packages = get_transient( $cache_key ); 52 53 if ( $packages ) { 54 return $packages; 55 } 48 56 49 57 // Get eCourier API configs. … … 66 74 ); 67 75 76 if ( is_wp_error( $response ) ) { 77 return new WP_Error( 'ste_package_fetch_error', 'Error in getting packages', [ 'status' => 500 ] ); 78 } 79 68 80 $packages = json_decode( $response['body'] ); 81 82 //keeping data in cache. Expire in 48 hours. 83 set_transient( $cache_key, $packages, 172800 ); 69 84 70 85 return $packages; -
ship-to-ecourier/trunk/readme.txt
r2529341 r2894437 4 4 Tags: ecourier, ecourier-parcel, ship-to-ecourier, ecourier-booking, ecourier-parcel-booking, ecourier-booking-automation, ecourier-parcel-tracker 5 5 Requires at least: 4.0 6 Tested up to: 5.7.16 Tested up to: 6.2.0 7 7 Requires PHP: 5.6 8 Stable tag: 1.1. 08 Stable tag: 1.1.1 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 79 79 == Changelog == 80 80 81 = 1.1.1 = 82 83 * Fetch City and area from Ecourier API and display in Dropdown 84 * Add caching for storing API data to avoid redundancy 85 * Error handling for HTTP requests. 86 * Add order note when shipped and cancel 87 * added a filter to allow modification in shipping info by 3rd party plugin 88 81 89 = 1.1.0 = 82 90 * Added: Label printing feature -
ship-to-ecourier/trunk/ship-to-ecourier.php
r2528332 r2894437 8 8 * Text Domain: ship-to-ecourier 9 9 * Domain Path: /languages 10 * Version: 1.1. 010 * Version: 1.1.1 11 11 * License: GPLv3 12 12 * License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 68 68 69 69 /** 70 * Holds various class instances. 71 * 72 * @var array 73 */ 74 private $container = []; 75 76 /** 70 77 * Ship_To_Ecourier constructor. 71 78 * … … 78 85 79 86 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); 87 88 add_action( 'init', [ $this, 'init_classes' ] ); 80 89 } 81 90 … … 86 95 */ 87 96 public static function init() { 88 $instance = false;97 static $instance = false; 89 98 90 99 if ( ! $instance ) { … … 93 102 94 103 return $instance; 104 } 105 106 /** 107 * Magic getter to bypass referencing plugin. 108 * 109 * @param mixed $prop Properties to find. 110 * 111 * @return mixed 112 */ 113 public function __get( $prop ) { 114 if ( array_key_exists( $prop, $this->container ) ) { 115 return $this->container[ $prop ]; 116 } 117 118 return $this->{$prop}; 119 } 120 121 /** 122 * Magic isset to bypass referencing plugin. 123 * 124 * @param mixed $prop Properties to find. 125 * 126 * @return mixed 127 */ 128 public function __isset( $prop ) { 129 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); 95 130 } 96 131 … … 138 173 139 174 /** 175 * Initialize classes 176 * 177 * @return void 178 */ 179 public function init_classes() { 180 $this->container['ecourier'] = new ShipToEcourier\Ecourier_Handler(); 181 } 182 183 /** 140 184 * Necessary setup on plugin activation. 141 185 * -
ship-to-ecourier/trunk/vendor/autoload.php
r2525816 r2894437 3 3 // autoload.php @generated by Composer 4 4 5 if (PHP_VERSION_ID < 50600) { 6 if (!headers_sent()) { 7 header('HTTP/1.1 500 Internal Server Error'); 8 } 9 $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; 10 if (!ini_get('display_errors')) { 11 if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { 12 fwrite(STDERR, $err); 13 } elseif (!headers_sent()) { 14 echo $err; 15 } 16 } 17 trigger_error( 18 $err, 19 E_USER_ERROR 20 ); 21 } 22 5 23 require_once __DIR__ . '/composer/autoload_real.php'; 6 24 7 return ComposerAutoloaderInit 623e2aa6265ae73da9cc7e7f68ee232a::getLoader();25 return ComposerAutoloaderInit55922fb54980b576755edaecda902c54::getLoader(); -
ship-to-ecourier/trunk/vendor/composer/ClassLoader.php
r2525816 r2894437 43 43 class ClassLoader 44 44 { 45 /** @var \Closure(string):void */ 46 private static $includeFile; 47 48 /** @var ?string */ 49 private $vendorDir; 50 45 51 // PSR-4 52 /** 53 * @var array[] 54 * @psalm-var array<string, array<string, int>> 55 */ 46 56 private $prefixLengthsPsr4 = array(); 57 /** 58 * @var array[] 59 * @psalm-var array<string, array<int, string>> 60 */ 47 61 private $prefixDirsPsr4 = array(); 62 /** 63 * @var array[] 64 * @psalm-var array<string, string> 65 */ 48 66 private $fallbackDirsPsr4 = array(); 49 67 50 68 // PSR-0 69 /** 70 * @var array[] 71 * @psalm-var array<string, array<string, string[]>> 72 */ 51 73 private $prefixesPsr0 = array(); 74 /** 75 * @var array[] 76 * @psalm-var array<string, string> 77 */ 52 78 private $fallbackDirsPsr0 = array(); 53 79 80 /** @var bool */ 54 81 private $useIncludePath = false; 82 83 /** 84 * @var string[] 85 * @psalm-var array<string, string> 86 */ 55 87 private $classMap = array(); 88 89 /** @var bool */ 56 90 private $classMapAuthoritative = false; 91 92 /** 93 * @var bool[] 94 * @psalm-var array<string, bool> 95 */ 57 96 private $missingClasses = array(); 97 98 /** @var ?string */ 58 99 private $apcuPrefix; 59 100 101 /** 102 * @var self[] 103 */ 104 private static $registeredLoaders = array(); 105 106 /** 107 * @param ?string $vendorDir 108 */ 109 public function __construct($vendorDir = null) 110 { 111 $this->vendorDir = $vendorDir; 112 self::initializeIncludeClosure(); 113 } 114 115 /** 116 * @return string[] 117 */ 60 118 public function getPrefixes() 61 119 { … … 67 125 } 68 126 127 /** 128 * @return array[] 129 * @psalm-return array<string, array<int, string>> 130 */ 69 131 public function getPrefixesPsr4() 70 132 { … … 72 134 } 73 135 136 /** 137 * @return array[] 138 * @psalm-return array<string, string> 139 */ 74 140 public function getFallbackDirs() 75 141 { … … 77 143 } 78 144 145 /** 146 * @return array[] 147 * @psalm-return array<string, string> 148 */ 79 149 public function getFallbackDirsPsr4() 80 150 { … … 82 152 } 83 153 154 /** 155 * @return string[] Array of classname => path 156 * @psalm-return array<string, string> 157 */ 84 158 public function getClassMap() 85 159 { … … 88 162 89 163 /** 90 * @param array $classMap Class to filename map 164 * @param string[] $classMap Class to filename map 165 * @psalm-param array<string, string> $classMap 166 * 167 * @return void 91 168 */ 92 169 public function addClassMap(array $classMap) … … 103 180 * appending or prepending to the ones previously set for this prefix. 104 181 * 105 * @param string $prefix The prefix 106 * @param array|string $paths The PSR-0 root directories 107 * @param bool $prepend Whether to prepend the directories 182 * @param string $prefix The prefix 183 * @param string[]|string $paths The PSR-0 root directories 184 * @param bool $prepend Whether to prepend the directories 185 * 186 * @return void 108 187 */ 109 188 public function add($prefix, $paths, $prepend = false) … … 148 227 * appending or prepending to the ones previously set for this namespace. 149 228 * 150 * @param string $prefix The prefix/namespace, with trailing '\\'151 * @param array|string $paths The PSR-4 base directories152 * @param bool $prepend Whether to prepend the directories229 * @param string $prefix The prefix/namespace, with trailing '\\' 230 * @param string[]|string $paths The PSR-4 base directories 231 * @param bool $prepend Whether to prepend the directories 153 232 * 154 233 * @throws \InvalidArgumentException 234 * 235 * @return void 155 236 */ 156 237 public function addPsr4($prefix, $paths, $prepend = false) … … 196 277 * replacing any others previously set for this prefix. 197 278 * 198 * @param string $prefix The prefix 199 * @param array|string $paths The PSR-0 base directories 279 * @param string $prefix The prefix 280 * @param string[]|string $paths The PSR-0 base directories 281 * 282 * @return void 200 283 */ 201 284 public function set($prefix, $paths) … … 212 295 * replacing any others previously set for this namespace. 213 296 * 214 * @param string $prefix The prefix/namespace, with trailing '\\'215 * @param array|string $paths The PSR-4 base directories297 * @param string $prefix The prefix/namespace, with trailing '\\' 298 * @param string[]|string $paths The PSR-4 base directories 216 299 * 217 300 * @throws \InvalidArgumentException 301 * 302 * @return void 218 303 */ 219 304 public function setPsr4($prefix, $paths) … … 235 320 * 236 321 * @param bool $useIncludePath 322 * 323 * @return void 237 324 */ 238 325 public function setUseIncludePath($useIncludePath) … … 257 344 * 258 345 * @param bool $classMapAuthoritative 346 * 347 * @return void 259 348 */ 260 349 public function setClassMapAuthoritative($classMapAuthoritative) … … 277 366 * 278 367 * @param string|null $apcuPrefix 368 * 369 * @return void 279 370 */ 280 371 public function setApcuPrefix($apcuPrefix) … … 297 388 * 298 389 * @param bool $prepend Whether to prepend the autoloader or not 390 * 391 * @return void 299 392 */ 300 393 public function register($prepend = false) 301 394 { 302 395 spl_autoload_register(array($this, 'loadClass'), true, $prepend); 396 397 if (null === $this->vendorDir) { 398 return; 399 } 400 401 if ($prepend) { 402 self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; 403 } else { 404 unset(self::$registeredLoaders[$this->vendorDir]); 405 self::$registeredLoaders[$this->vendorDir] = $this; 406 } 303 407 } 304 408 305 409 /** 306 410 * Unregisters this instance as an autoloader. 411 * 412 * @return void 307 413 */ 308 414 public function unregister() 309 415 { 310 416 spl_autoload_unregister(array($this, 'loadClass')); 417 418 if (null !== $this->vendorDir) { 419 unset(self::$registeredLoaders[$this->vendorDir]); 420 } 311 421 } 312 422 … … 315 425 * 316 426 * @param string $class The name of the class 317 * @return bool|null True if loaded, null otherwise427 * @return true|null True if loaded, null otherwise 318 428 */ 319 429 public function loadClass($class) 320 430 { 321 431 if ($file = $this->findFile($class)) { 322 includeFile($file); 432 $includeFile = self::$includeFile; 433 $includeFile($file); 323 434 324 435 return true; 325 436 } 437 438 return null; 326 439 } 327 440 … … 368 481 } 369 482 483 /** 484 * Returns the currently registered loaders indexed by their corresponding vendor directories. 485 * 486 * @return self[] 487 */ 488 public static function getRegisteredLoaders() 489 { 490 return self::$registeredLoaders; 491 } 492 493 /** 494 * @param string $class 495 * @param string $ext 496 * @return string|false 497 */ 370 498 private function findFileWithExtension($class, $ext) 371 499 { … … 433 561 return false; 434 562 } 563 564 /** 565 * @return void 566 */ 567 private static function initializeIncludeClosure() 568 { 569 if (self::$includeFile !== null) { 570 return; 571 } 572 573 /** 574 * Scope isolated include. 575 * 576 * Prevents access to $this/self from included files. 577 * 578 * @param string $file 579 * @return void 580 */ 581 self::$includeFile = \Closure::bind(static function($file) { 582 include $file; 583 }, null, null); 584 } 435 585 } 436 437 /**438 * Scope isolated include.439 *440 * Prevents access to $this/self from included files.441 */442 function includeFile($file)443 {444 include $file;445 } -
ship-to-ecourier/trunk/vendor/composer/InstalledVersions.php
r2527180 r2894437 1 1 <?php 2 2 3 4 5 6 7 8 9 10 11 3 /* 4 * This file is part of Composer. 5 * 6 * (c) Nils Adermann <naderman@naderman.de> 7 * Jordi Boggiano <j.boggiano@seld.be> 8 * 9 * For the full copyright and license information, please view the LICENSE 10 * file that was distributed with this source code. 11 */ 12 12 13 13 namespace Composer; 14 14 15 use Composer\Autoload\ClassLoader; 15 16 use Composer\Semver\VersionParser; 16 17 17 18 19 20 21 18 /** 19 * This class is copied in every Composer installed project and available to all 20 * 21 * See also https://getcomposer.org/doc/07-runtime.md#installed-versions 22 * 23 * To require its presence, you can require `composer-runtime-api ^2.0` 24 * 25 * @final 26 */ 22 27 class InstalledVersions 23 28 { 24 private static $installed = array ( 25 'root' => 26 array ( 27 'pretty_version' => 'dev-master', 28 'version' => 'dev-master', 29 'aliases' => 30 array ( 31 ), 32 'reference' => '1ef747b756c8fbab66af71841f05497b44b3f959', 33 'name' => 'simongomes/ship-to-ecourier', 34 ), 35 'versions' => 36 array ( 37 'appsero/client' => 38 array ( 39 'pretty_version' => 'dev-develop', 40 'version' => 'dev-develop', 41 'aliases' => 42 array ( 43 0 => '9999999-dev', 44 ), 45 'reference' => 'd631da21bccbd0a4ea752cd3b827889883f378af', 46 ), 47 'simongomes/ship-to-ecourier' => 48 array ( 49 'pretty_version' => 'dev-master', 50 'version' => 'dev-master', 51 'aliases' => 52 array ( 53 ), 54 'reference' => '1ef747b756c8fbab66af71841f05497b44b3f959', 55 ), 56 ), 57 ); 58 59 60 61 62 63 64 65 public static function getInstalledPackages() 66 { 67 return array_keys(self::$installed['versions']); 29 /** 30 * @var mixed[]|null 31 * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null 32 */ 33 private static $installed; 34 35 /** 36 * @var bool|null 37 */ 38 private static $canGetVendors; 39 40 /** 41 * @var array[] 42 * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> 43 */ 44 private static $installedByVendor = array(); 45 46 /** 47 * Returns a list of all package names which are present, either by being installed, replaced or provided 48 * 49 * @return string[] 50 * @psalm-return list<string> 51 */ 52 public static function getInstalledPackages() 53 { 54 $packages = array(); 55 foreach (self::getInstalled() as $installed) { 56 $packages[] = array_keys($installed['versions']); 57 } 58 59 if (1 === \count($packages)) { 60 return $packages[0]; 61 } 62 63 return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); 64 } 65 66 /** 67 * Returns a list of all package names with a specific type e.g. 'library' 68 * 69 * @param string $type 70 * @return string[] 71 * @psalm-return list<string> 72 */ 73 public static function getInstalledPackagesByType($type) 74 { 75 $packagesByType = array(); 76 77 foreach (self::getInstalled() as $installed) { 78 foreach ($installed['versions'] as $name => $package) { 79 if (isset($package['type']) && $package['type'] === $type) { 80 $packagesByType[] = $name; 81 } 82 } 83 } 84 85 return $packagesByType; 86 } 87 88 /** 89 * Checks whether the given package is installed 90 * 91 * This also returns true if the package name is provided or replaced by another package 92 * 93 * @param string $packageName 94 * @param bool $includeDevRequirements 95 * @return bool 96 */ 97 public static function isInstalled($packageName, $includeDevRequirements = true) 98 { 99 foreach (self::getInstalled() as $installed) { 100 if (isset($installed['versions'][$packageName])) { 101 return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; 102 } 103 } 104 105 return false; 106 } 107 108 /** 109 * Checks whether the given package satisfies a version constraint 110 * 111 * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: 112 * 113 * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') 114 * 115 * @param VersionParser $parser Install composer/semver to have access to this class and functionality 116 * @param string $packageName 117 * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package 118 * @return bool 119 */ 120 public static function satisfies(VersionParser $parser, $packageName, $constraint) 121 { 122 $constraint = $parser->parseConstraints((string) $constraint); 123 $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); 124 125 return $provided->matches($constraint); 126 } 127 128 /** 129 * Returns a version constraint representing all the range(s) which are installed for a given package 130 * 131 * It is easier to use this via isInstalled() with the $constraint argument if you need to check 132 * whether a given version of a package is installed, and not just whether it exists 133 * 134 * @param string $packageName 135 * @return string Version constraint usable with composer/semver 136 */ 137 public static function getVersionRanges($packageName) 138 { 139 foreach (self::getInstalled() as $installed) { 140 if (!isset($installed['versions'][$packageName])) { 141 continue; 142 } 143 144 $ranges = array(); 145 if (isset($installed['versions'][$packageName]['pretty_version'])) { 146 $ranges[] = $installed['versions'][$packageName]['pretty_version']; 147 } 148 if (array_key_exists('aliases', $installed['versions'][$packageName])) { 149 $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); 150 } 151 if (array_key_exists('replaced', $installed['versions'][$packageName])) { 152 $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); 153 } 154 if (array_key_exists('provided', $installed['versions'][$packageName])) { 155 $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); 156 } 157 158 return implode(' || ', $ranges); 159 } 160 161 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 162 } 163 164 /** 165 * @param string $packageName 166 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present 167 */ 168 public static function getVersion($packageName) 169 { 170 foreach (self::getInstalled() as $installed) { 171 if (!isset($installed['versions'][$packageName])) { 172 continue; 173 } 174 175 if (!isset($installed['versions'][$packageName]['version'])) { 176 return null; 177 } 178 179 return $installed['versions'][$packageName]['version']; 180 } 181 182 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 183 } 184 185 /** 186 * @param string $packageName 187 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present 188 */ 189 public static function getPrettyVersion($packageName) 190 { 191 foreach (self::getInstalled() as $installed) { 192 if (!isset($installed['versions'][$packageName])) { 193 continue; 194 } 195 196 if (!isset($installed['versions'][$packageName]['pretty_version'])) { 197 return null; 198 } 199 200 return $installed['versions'][$packageName]['pretty_version']; 201 } 202 203 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 204 } 205 206 /** 207 * @param string $packageName 208 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference 209 */ 210 public static function getReference($packageName) 211 { 212 foreach (self::getInstalled() as $installed) { 213 if (!isset($installed['versions'][$packageName])) { 214 continue; 215 } 216 217 if (!isset($installed['versions'][$packageName]['reference'])) { 218 return null; 219 } 220 221 return $installed['versions'][$packageName]['reference']; 222 } 223 224 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 225 } 226 227 /** 228 * @param string $packageName 229 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. 230 */ 231 public static function getInstallPath($packageName) 232 { 233 foreach (self::getInstalled() as $installed) { 234 if (!isset($installed['versions'][$packageName])) { 235 continue; 236 } 237 238 return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; 239 } 240 241 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 242 } 243 244 /** 245 * @return array 246 * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} 247 */ 248 public static function getRootPackage() 249 { 250 $installed = self::getInstalled(); 251 252 return $installed[0]['root']; 253 } 254 255 /** 256 * Returns the raw installed.php data for custom implementations 257 * 258 * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. 259 * @return array[] 260 * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} 261 */ 262 public static function getRawData() 263 { 264 @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); 265 266 if (null === self::$installed) { 267 // only require the installed.php file if this file is loaded from its dumped location, 268 // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 269 if (substr(__DIR__, -8, 1) !== 'C') { 270 self::$installed = include __DIR__ . '/installed.php'; 271 } else { 272 self::$installed = array(); 273 } 274 } 275 276 return self::$installed; 277 } 278 279 /** 280 * Returns the raw data of all installed.php which are currently loaded for custom implementations 281 * 282 * @return array[] 283 * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> 284 */ 285 public static function getAllRawData() 286 { 287 return self::getInstalled(); 288 } 289 290 /** 291 * Lets you reload the static array from another file 292 * 293 * This is only useful for complex integrations in which a project needs to use 294 * this class but then also needs to execute another project's autoloader in process, 295 * and wants to ensure both projects have access to their version of installed.php. 296 * 297 * A typical case would be PHPUnit, where it would need to make sure it reads all 298 * the data it needs from this class, then call reload() with 299 * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure 300 * the project in which it runs can then also use this class safely, without 301 * interference between PHPUnit's dependencies and the project's dependencies. 302 * 303 * @param array[] $data A vendor/composer/installed.php data set 304 * @return void 305 * 306 * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data 307 */ 308 public static function reload($data) 309 { 310 self::$installed = $data; 311 self::$installedByVendor = array(); 312 } 313 314 /** 315 * @return array[] 316 * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> 317 */ 318 private static function getInstalled() 319 { 320 if (null === self::$canGetVendors) { 321 self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); 322 } 323 324 $installed = array(); 325 326 if (self::$canGetVendors) { 327 foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { 328 if (isset(self::$installedByVendor[$vendorDir])) { 329 $installed[] = self::$installedByVendor[$vendorDir]; 330 } elseif (is_file($vendorDir.'/composer/installed.php')) { 331 /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */ 332 $required = require $vendorDir.'/composer/installed.php'; 333 $installed[] = self::$installedByVendor[$vendorDir] = $required; 334 if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { 335 self::$installed = $installed[count($installed) - 1]; 336 } 337 } 338 } 339 } 340 341 if (null === self::$installed) { 342 // only require the installed.php file if this file is loaded from its dumped location, 343 // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 344 if (substr(__DIR__, -8, 1) !== 'C') { 345 /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */ 346 $required = require __DIR__ . '/installed.php'; 347 self::$installed = $required; 348 } else { 349 self::$installed = array(); 350 } 351 } 352 353 if (self::$installed !== array()) { 354 $installed[] = self::$installed; 355 } 356 357 return $installed; 358 } 68 359 } 69 70 71 72 73 74 75 76 77 78 public static function isInstalled($packageName)79 {80 return isset(self::$installed['versions'][$packageName]);81 }82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 public static function satisfies(VersionParser $parser, $packageName, $constraint)97 {98 $constraint = $parser->parseConstraints($constraint);99 $provided = $parser->parseConstraints(self::getVersionRanges($packageName));100 101 return $provided->matches($constraint);102 }103 104 105 106 107 108 109 110 111 112 113 public static function getVersionRanges($packageName)114 {115 if (!isset(self::$installed['versions'][$packageName])) {116 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');117 }118 119 $ranges = array();120 if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {121 $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];122 }123 if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {124 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);125 }126 if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {127 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);128 }129 if (array_key_exists('provided', self::$installed['versions'][$packageName])) {130 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);131 }132 133 return implode(' || ', $ranges);134 }135 136 137 138 139 140 public static function getVersion($packageName)141 {142 if (!isset(self::$installed['versions'][$packageName])) {143 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');144 }145 146 if (!isset(self::$installed['versions'][$packageName]['version'])) {147 return null;148 }149 150 return self::$installed['versions'][$packageName]['version'];151 }152 153 154 155 156 157 public static function getPrettyVersion($packageName)158 {159 if (!isset(self::$installed['versions'][$packageName])) {160 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');161 }162 163 if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {164 return null;165 }166 167 return self::$installed['versions'][$packageName]['pretty_version'];168 }169 170 171 172 173 174 public static function getReference($packageName)175 {176 if (!isset(self::$installed['versions'][$packageName])) {177 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');178 }179 180 if (!isset(self::$installed['versions'][$packageName]['reference'])) {181 return null;182 }183 184 return self::$installed['versions'][$packageName]['reference'];185 }186 187 188 189 190 191 public static function getRootPackage()192 {193 return self::$installed['root'];194 }195 196 197 198 199 200 201 202 public static function getRawData()203 {204 return self::$installed;205 }206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 public static function reload($data)226 {227 self::$installed = $data;228 }229 } -
ship-to-ecourier/trunk/vendor/composer/autoload_classmap.php
r2525816 r2894437 3 3 // autoload_classmap.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
ship-to-ecourier/trunk/vendor/composer/autoload_files.php
r2525816 r2894437 3 3 // autoload_files.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
ship-to-ecourier/trunk/vendor/composer/autoload_namespaces.php
r2525816 r2894437 3 3 // autoload_namespaces.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
ship-to-ecourier/trunk/vendor/composer/autoload_psr4.php
r2527180 r2894437 3 3 // autoload_psr4.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
ship-to-ecourier/trunk/vendor/composer/autoload_real.php
r2527180 r2894437 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 623e2aa6265ae73da9cc7e7f68ee232a5 class ComposerAutoloaderInit55922fb54980b576755edaecda902c54 6 6 { 7 7 private static $loader; … … 25 25 require __DIR__ . '/platform_check.php'; 26 26 27 spl_autoload_register(array('ComposerAutoloaderInit 623e2aa6265ae73da9cc7e7f68ee232a', 'loadClassLoader'), true, true);28 self::$loader = $loader = new \Composer\Autoload\ClassLoader( );29 spl_autoload_unregister(array('ComposerAutoloaderInit 623e2aa6265ae73da9cc7e7f68ee232a', 'loadClassLoader'));27 spl_autoload_register(array('ComposerAutoloaderInit55922fb54980b576755edaecda902c54', 'loadClassLoader'), true, true); 28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 29 spl_autoload_unregister(array('ComposerAutoloaderInit55922fb54980b576755edaecda902c54', 'loadClassLoader')); 30 30 31 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 32 if ($useStaticLoader) { 33 require __DIR__ . '/autoload_static.php'; 34 35 call_user_func(\Composer\Autoload\ComposerStaticInit623e2aa6265ae73da9cc7e7f68ee232a::getInitializer($loader)); 36 } else { 37 $map = require __DIR__ . '/autoload_namespaces.php'; 38 foreach ($map as $namespace => $path) { 39 $loader->set($namespace, $path); 40 } 41 42 $map = require __DIR__ . '/autoload_psr4.php'; 43 foreach ($map as $namespace => $path) { 44 $loader->setPsr4($namespace, $path); 45 } 46 47 $classMap = require __DIR__ . '/autoload_classmap.php'; 48 if ($classMap) { 49 $loader->addClassMap($classMap); 50 } 51 } 31 require __DIR__ . '/autoload_static.php'; 32 call_user_func(\Composer\Autoload\ComposerStaticInit55922fb54980b576755edaecda902c54::getInitializer($loader)); 52 33 53 34 $loader->register(true); 54 35 55 if ($useStaticLoader) { 56 $includeFiles = Composer\Autoload\ComposerStaticInit623e2aa6265ae73da9cc7e7f68ee232a::$files; 57 } else { 58 $includeFiles = require __DIR__ . '/autoload_files.php'; 59 } 60 foreach ($includeFiles as $fileIdentifier => $file) { 61 composerRequire623e2aa6265ae73da9cc7e7f68ee232a($fileIdentifier, $file); 36 $filesToLoad = \Composer\Autoload\ComposerStaticInit55922fb54980b576755edaecda902c54::$files; 37 $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { 38 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { 39 $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; 40 41 require $file; 42 } 43 }, null, null); 44 foreach ($filesToLoad as $fileIdentifier => $file) { 45 $requireFile($fileIdentifier, $file); 62 46 } 63 47 … … 65 49 } 66 50 } 67 68 function composerRequire623e2aa6265ae73da9cc7e7f68ee232a($fileIdentifier, $file)69 {70 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {71 require $file;72 73 $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;74 }75 } -
ship-to-ecourier/trunk/vendor/composer/autoload_static.php
r2527180 r2894437 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 623e2aa6265ae73da9cc7e7f68ee232a7 class ComposerStaticInit55922fb54980b576755edaecda902c54 8 8 { 9 9 public static $files = array ( … … 40 40 { 41 41 return \Closure::bind(function () use ($loader) { 42 $loader->prefixLengthsPsr4 = ComposerStaticInit 623e2aa6265ae73da9cc7e7f68ee232a::$prefixLengthsPsr4;43 $loader->prefixDirsPsr4 = ComposerStaticInit 623e2aa6265ae73da9cc7e7f68ee232a::$prefixDirsPsr4;44 $loader->classMap = ComposerStaticInit 623e2aa6265ae73da9cc7e7f68ee232a::$classMap;42 $loader->prefixLengthsPsr4 = ComposerStaticInit55922fb54980b576755edaecda902c54::$prefixLengthsPsr4; 43 $loader->prefixDirsPsr4 = ComposerStaticInit55922fb54980b576755edaecda902c54::$prefixDirsPsr4; 44 $loader->classMap = ComposerStaticInit55922fb54980b576755edaecda902c54::$classMap; 45 45 46 46 }, null, ClassLoader::class); -
ship-to-ecourier/trunk/vendor/composer/installed.json
r2527180 r2894437 22 22 "default-branch": true, 23 23 "type": "library", 24 "installation-source": " source",24 "installation-source": "dist", 25 25 "autoload": { 26 26 "psr-4": { -
ship-to-ecourier/trunk/vendor/composer/installed.php
r2527180 r2894437 1 <?php return array ( 2 'root' => 3 array ( 4 'pretty_version' => 'dev-master', 5 'version' => 'dev-master', 6 'aliases' => 7 array ( 1 <?php return array( 2 'root' => array( 3 'name' => 'simongomes/ship-to-ecourier', 4 'pretty_version' => 'dev-master', 5 'version' => 'dev-master', 6 'reference' => '7b6fc0329290a128434d1e42f1790857dccee2e9', 7 'type' => 'wordpress-plugin', 8 'install_path' => __DIR__ . '/../../', 9 'aliases' => array(), 10 'dev' => true, 8 11 ), 9 'reference' => '1ef747b756c8fbab66af71841f05497b44b3f959', 10 'name' => 'simongomes/ship-to-ecourier', 11 ), 12 'versions' => 13 array ( 14 'appsero/client' => 15 array ( 16 'pretty_version' => 'dev-develop', 17 'version' => 'dev-develop', 18 'aliases' => 19 array ( 20 0 => '9999999-dev', 21 ), 22 'reference' => 'd631da21bccbd0a4ea752cd3b827889883f378af', 12 'versions' => array( 13 'appsero/client' => array( 14 'pretty_version' => 'dev-develop', 15 'version' => 'dev-develop', 16 'reference' => 'd631da21bccbd0a4ea752cd3b827889883f378af', 17 'type' => 'library', 18 'install_path' => __DIR__ . '/../appsero/client', 19 'aliases' => array( 20 0 => '9999999-dev', 21 ), 22 'dev_requirement' => false, 23 ), 24 'simongomes/ship-to-ecourier' => array( 25 'pretty_version' => 'dev-master', 26 'version' => 'dev-master', 27 'reference' => '7b6fc0329290a128434d1e42f1790857dccee2e9', 28 'type' => 'wordpress-plugin', 29 'install_path' => __DIR__ . '/../../', 30 'aliases' => array(), 31 'dev_requirement' => false, 32 ), 23 33 ), 24 'simongomes/ship-to-ecourier' =>25 array (26 'pretty_version' => 'dev-master',27 'version' => 'dev-master',28 'aliases' =>29 array (30 ),31 'reference' => '1ef747b756c8fbab66af71841f05497b44b3f959',32 ),33 ),34 34 );
Note: See TracChangeset
for help on using the changeset viewer.