Changeset 3837719
- Timestamp:
- 12/01/2026 01:23:10 PM (less than one hour ago)
- Location:
- softsquare-shipping-gateway-for-woocommerce
- Files:
-
- 6 added
- 24 edited
- 1 copied
-
tags/1.6.2 (copied) (copied from softsquare-shipping-gateway-for-woocommerce/trunk )
-
tags/1.6.2/admin/class-ssg-admin-orders.php (modified) (5 diffs)
-
tags/1.6.2/admin/class-ssg-admin-review.php (added)
-
tags/1.6.2/admin/class-ssg-admin-settings.php (modified) (6 diffs)
-
tags/1.6.2/admin/class-ssg-admin.php (modified) (3 diffs)
-
tags/1.6.2/assets/css/admin.css (modified) (1 diff)
-
tags/1.6.2/assets/js/admin.js (modified) (2 diffs)
-
tags/1.6.2/includes/class-ssg-install.php (modified) (2 diffs)
-
tags/1.6.2/includes/class-ssg-notifier.php (modified) (3 diffs)
-
tags/1.6.2/includes/class-ssg-qr.php (added)
-
tags/1.6.2/includes/class-ssg-settings.php (modified) (3 diffs)
-
tags/1.6.2/includes/class-ssg-shipment.php (modified) (6 diffs)
-
tags/1.6.2/includes/class-ssg-thermal-label.php (added)
-
tags/1.6.2/readme.txt (modified) (3 diffs)
-
tags/1.6.2/softsquare-shipping-gateway.php (modified) (4 diffs)
-
tags/1.6.2/uninstall.php (modified) (1 diff)
-
trunk/admin/class-ssg-admin-orders.php (modified) (5 diffs)
-
trunk/admin/class-ssg-admin-review.php (added)
-
trunk/admin/class-ssg-admin-settings.php (modified) (6 diffs)
-
trunk/admin/class-ssg-admin.php (modified) (3 diffs)
-
trunk/assets/css/admin.css (modified) (1 diff)
-
trunk/assets/js/admin.js (modified) (2 diffs)
-
trunk/includes/class-ssg-install.php (modified) (2 diffs)
-
trunk/includes/class-ssg-notifier.php (modified) (3 diffs)
-
trunk/includes/class-ssg-qr.php (added)
-
trunk/includes/class-ssg-settings.php (modified) (3 diffs)
-
trunk/includes/class-ssg-shipment.php (modified) (6 diffs)
-
trunk/includes/class-ssg-thermal-label.php (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/softsquare-shipping-gateway.php (modified) (4 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/admin/class-ssg-admin-orders.php
r3834387 r3837719 262 262 <h4><?php esc_html_e( 'Booking details', 'softsquare-shipping-gateway-for-woocommerce' ); ?></h4> 263 263 <p class="ssg-muted"><?php esc_html_e( 'Filled in from the order. Change a box only if this parcel is different, then press Book.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 264 <?php foreach ( SSGW_Shipment::address_problems( $order ) as $address_problem ) : ?> 265 <p class="ssg-warn"><?php echo esc_html( $address_problem ); ?></p> 266 <?php endforeach; ?> 264 267 <?php self::booking_fields( $order ); ?> 265 268 <?php if ( SSGW_Features::is_enabled( 'cost_sync' ) ) : ?> … … 304 307 <?php endif; ?> 305 308 <a href="<?php echo esc_url( SSGW_Label_Print::url( $order->get_id() ) ); ?>" target="_blank" rel="noopener" class="ssg-label-link"><?php esc_html_e( 'Print at label size', 'softsquare-shipping-gateway-for-woocommerce' ); ?></a> 309 <a href="<?php echo esc_url( SSGW_Thermal_Label::url( $order->get_id() ) ); ?>" target="_blank" rel="noopener" class="ssg-label-link"><?php esc_html_e( '4 x 6 thermal label (PDF)', 'softsquare-shipping-gateway-for-woocommerce' ); ?></a> 306 310 </p> 307 311 … … 674 678 $actions['tcsg_book'] = __( 'TCS: book shipments', 'softsquare-shipping-gateway-for-woocommerce' ); 675 679 $actions['tcsg_labels'] = __( 'TCS: print labels', 'softsquare-shipping-gateway-for-woocommerce' ); 680 $actions['tcsg_thermal'] = __( 'TCS: download 4 x 6 thermal labels (PDF)', 'softsquare-shipping-gateway-for-woocommerce' ); 676 681 $actions['tcsg_refresh'] = __( 'TCS: refresh tracking status', 'softsquare-shipping-gateway-for-woocommerce' ); 677 682 $actions['tcsg_sheet'] = sprintf( … … 693 698 */ 694 699 public function handle_bulk_actions( $redirect_to, $action, $ids ) { 695 if ( ! in_array( $action, array( 'tcsg_book', 'tcsg_labels', 'tcsg_refresh', 'tcsg_sheet' ), true ) ) {700 if ( ! in_array( $action, array( 'tcsg_book', 'tcsg_labels', 'tcsg_refresh', 'tcsg_sheet', 'tcsg_thermal' ), true ) ) { 696 701 return $redirect_to; 697 702 } … … 702 707 703 708 $ids = array_map( 'absint', (array) $ids ); 709 710 if ( 'tcsg_thermal' === $action ) { 711 return SSGW_Thermal_Label::url( $ids ); 712 } 704 713 705 714 if ( 'tcsg_sheet' === $action ) { -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/admin/class-ssg-admin-settings.php
r3834387 r3837719 115 115 'validate_mobile', 116 116 'call_ahead_remark', 117 'allow_open', 117 118 'cn_in_wc_emails', 118 119 'collect_area_block', … … 277 278 $values['print_extra_params'] = isset( $_POST['print_extra_params'] ) ? sanitize_textarea_field( wp_unslash( $_POST['print_extra_params'] ) ) : ''; 278 279 $values['email_format'] = isset( $_POST['email_format'] ) && 'html' === $_POST['email_format'] ? 'html' : 'plain'; 280 $logo_id = isset( $_POST['label_logo_id'] ) ? absint( wp_unslash( $_POST['label_logo_id'] ) ) : 0; 281 $values['label_logo_id'] = $logo_id && wp_attachment_is_image( $logo_id ) ? $logo_id : 0; 279 282 $values['email_accent'] = isset( $_POST['email_accent'] ) ? (string) sanitize_hex_color( wp_unslash( $_POST['email_accent'] ) ) : ''; 280 283 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- SSGW_Status_Rules::sanitize() cleans each field. … … 283 286 // Nothing ticked means every status change, which is what the empty 284 287 // default means too — see SSGW_Notifier::status_is_selected(). 285 $values['notify_statuses'] = isset( $_POST['notify_statuses'] ) && is_array( $_POST['notify_statuses'] ) 286 ? array_map( 'sanitize_text_field', wp_unslash( $_POST['notify_statuses'] ) ) 287 : array(); 288 foreach ( array( 'notify_customer_statuses', 'notify_admin_statuses' ) as $list_key ) { 289 $values[ $list_key ] = isset( $_POST[ $list_key ] ) && is_array( $_POST[ $list_key ] ) 290 ? array_values( array_intersect( array_map( 'sanitize_key', wp_unslash( $_POST[ $list_key ] ) ), array_keys( SSGW_Notifier::selectable_statuses() ) ) ) 291 : array(); 292 } 288 293 // phpcs:enable 289 294 … … 897 902 $extra = array( 898 903 'cn_in_wc_emails' => array( __( 'Add the consignment number and tracking link to WooCommerce order emails', 'softsquare-shipping-gateway-for-woocommerce' ), true ), 899 'call_ahead_remark' => array( __( 'Ask the rider to call first: adds "Call me before delivery on" and the customer\'s number to the consignment note', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 904 'call_ahead_remark' => array( __( 'Ask the rider to call first: adds "Please call the customer before delivery:" and the customer\'s number to the remarks', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 905 'allow_open' => array( __( 'Allow to open: the customer may open and check the parcel before paying. Added to the remarks, and printed on the 4 x 6 label.', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 900 906 'validate_mobile' => array( __( 'At checkout, require a valid Pakistani mobile number (03XXXXXXXXX)', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 901 907 'collect_area_block' => array( __( 'At checkout, ask for the area and block as well as the city. Each new city or area a customer picks is looked up through the SoftSquare service.', 'softsquare-shipping-gateway-for-woocommerce' ), false ), … … 917 923 <h2 class="title"><?php esc_html_e( 'Label printing', 'softsquare-shipping-gateway-for-woocommerce' ); ?></h2> 918 924 <table class="form-table" role="presentation"> 925 <tr> 926 <th scope="row"><?php esc_html_e( 'Logo on labels', 'softsquare-shipping-gateway-for-woocommerce' ); ?></th> 927 <td> 928 <?php 929 $logo_id = (int) SSGW_Settings::get( 'label_logo_id', 0 ); 930 $logo_src = $logo_id ? wp_get_attachment_image_url( $logo_id, 'medium' ) : ''; 931 ?> 932 <div class="ssg-logo-field"> 933 <input type="hidden" name="label_logo_id" id="label_logo_id" value="<?php echo esc_attr( $logo_src ? $logo_id : 0 ); ?>"> 934 <div class="ssg-logo-preview"<?php echo $logo_src ? '' : ' hidden'; ?>> 935 <img src="<?php echo esc_url( (string) $logo_src ); ?>" alt=""> 936 </div> 937 <button type="button" class="button ssg-logo-pick" 938 data-title="<?php esc_attr_e( 'Logo for labels', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" 939 data-button="<?php esc_attr_e( 'Use this logo', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"><?php esc_html_e( 'Choose logo', 'softsquare-shipping-gateway-for-woocommerce' ); ?></button> 940 <button type="button" class="button-link ssg-logo-remove"<?php echo $logo_src ? '' : ' hidden'; ?>><?php esc_html_e( 'Remove', 'softsquare-shipping-gateway-for-woocommerce' ); ?></button> 941 </div> 942 <p class="description"> 943 <?php esc_html_e( 'Printed at the top left of the 4 x 6 thermal label PDF, in a space 50 x 11 mm (about 2 x 0.4 inches). TCS\'s own A4 labels are TCS\'s artwork and are not changed.', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 944 </p> 945 <p class="description"> 946 <strong><?php esc_html_e( 'Best size: 600 x 130 pixels', 'softsquare-shipping-gateway-for-woocommerce' ); ?></strong> 947 <?php esc_html_e( '(a wide logo, about 4.5 : 1), PNG or JPG, black or dark on a white or transparent background. A square logo still works but prints only 11 mm tall. Thermal printers print in black only, so light colours fade.', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 948 </p> 949 </td> 950 </tr> 919 951 <tr> 920 952 <th scope="row"><label for="label_size"><?php esc_html_e( 'Label size', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> … … 1199 1231 </tr> 1200 1232 <tr> 1201 <th scope="row"><?php esc_html_e( 'Which changes', 'softsquare-shipping-gateway-for-woocommerce' ); ?></th> 1202 <td> 1203 <?php 1204 $chosen_statuses = (array) SSGW_Settings::get( 'notify_statuses', array() ); 1205 1206 foreach ( SSGW_Notifier::selectable_statuses() as $key => $label ) : 1207 ?> 1208 <label class="ssg-check"> 1209 <input type="checkbox" name="notify_statuses[]" value="<?php echo esc_attr( $key ); ?>" 1210 <?php checked( in_array( $key, $chosen_statuses, true ) ); ?>> 1211 <?php echo esc_html( $label ); ?> 1212 </label><br> 1213 <?php endforeach; ?> 1214 <p class="description"> 1215 <?php esc_html_e( 'Tick nothing to be told about every change. TCS wording varies by account, so these are matched loosely — "Delivered" also catches "Delivered to consignee".', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 1216 </p> 1233 <th scope="row"><label for="notify_customer_statuses"><?php esc_html_e( 'Customer email for', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> 1234 <td> 1235 <?php $chosen_statuses = SSGW_Notifier::chosen( 'customer' ); ?> 1236 <select name="notify_customer_statuses[]" id="notify_customer_statuses" class="ssg-searchable ssg-multi" multiple="multiple" data-no-results="<?php esc_attr_e( 'No such status', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" data-placeholder="<?php esc_attr_e( 'Every status change', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"> 1237 <?php foreach ( SSGW_Notifier::selectable_statuses() as $key => $status_label ) : ?> 1238 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key, $chosen_statuses, true ) ); ?>><?php echo esc_html( $status_label ); ?></option> 1239 <?php endforeach; ?> 1240 </select> 1241 <p class="description"><?php esc_html_e( 'Statuses that email the customer. Leave empty for every change.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 1242 </td> 1243 </tr> 1244 <tr> 1245 <th scope="row"><label for="notify_admin_statuses"><?php esc_html_e( 'Store email for', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> 1246 <td> 1247 <?php $chosen_statuses = SSGW_Notifier::chosen( 'admin' ); ?> 1248 <select name="notify_admin_statuses[]" id="notify_admin_statuses" class="ssg-searchable ssg-multi" multiple="multiple" data-no-results="<?php esc_attr_e( 'No such status', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" data-placeholder="<?php esc_attr_e( 'Every status change', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"> 1249 <?php foreach ( SSGW_Notifier::selectable_statuses() as $key => $status_label ) : ?> 1250 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key, $chosen_statuses, true ) ); ?>><?php echo esc_html( $status_label ); ?></option> 1251 <?php endforeach; ?> 1252 </select> 1253 <p class="description"><?php esc_html_e( 'Statuses that email the store address above. Leave empty for every change.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 1254 </td> 1255 </tr> 1256 <tr> 1257 <td colspan="2" class="ssg-muted"> 1258 <?php esc_html_e( 'TCS wording varies by account, so statuses are matched loosely: "Delivered" also catches "Delivered to consignee".', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 1217 1259 </td> 1218 1260 </tr> -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/admin/class-ssg-admin.php
r3826921 r3837719 80 80 */ 81 81 public $print; 82 83 /** 84 * Review request. 85 * 86 * @var SSGW_Admin_Review 87 */ 88 public $review; 89 90 /** 91 * 4 x 6 thermal labels. 92 * 93 * @var SSGW_Thermal_Label 94 */ 95 public $thermal; 82 96 83 97 /** … … 94 108 $this->email_test = new SSGW_Admin_Email_Test(); 95 109 $this->print = new SSGW_Label_Print(); 110 $this->review = new SSGW_Admin_Review(); 111 $this->thermal = new SSGW_Thermal_Label(); 96 112 97 113 add_action( 'admin_menu', array( $this, 'register_menu' ) ); … … 259 275 if ( wp_style_is( 'woocommerce_admin_styles', 'registered' ) ) { 260 276 wp_enqueue_style( 'woocommerce_admin_styles' ); 277 } 278 279 // The logo picker on the settings screen. 280 if ( 'toplevel_page_' . self::SLUG === $hook && function_exists( 'wp_enqueue_media' ) ) { 281 wp_enqueue_media(); 261 282 } 262 283 -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/assets/css/admin.css
r3826905 r3837719 1077 1077 margin: .4em 0; 1078 1078 } 1079 1080 /* Label logo */ 1081 .ssg-logo-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } 1082 .ssg-logo-preview { width: 236px; height: 52px; border: 1px dashed #c3c4c7; background: #fff; display: flex; align-items: center; justify-content: flex-start; padding: 4px; box-sizing: border-box; } 1083 .ssg-logo-preview[hidden] { display: none; } 1084 .ssg-logo-preview img { max-width: 100%; max-height: 100%; } -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/assets/js/admin.js
r3834301 r3837719 250 250 width: '100%', 251 251 placeholder: $select.data( 'placeholder' ) || '', 252 language: { noResults: function () { return i18n.noCity || 'No city found'; } }252 language: { noResults: function () { return $select.data( 'no-results' ) || i18n.noCity || 'No city found'; } } 253 253 } ); 254 254 } ); … … 256 256 257 257 $( enhanceSelects ); 258 259 /* --------------------------------------------------------------------- 260 * Label logo 261 * ------------------------------------------------------------------ */ 262 263 $( document ).on( 'click', '.ssg-logo-pick', function ( event ) { 264 event.preventDefault(); 265 266 if ( ! window.wp || ! wp.media ) { 267 return; 268 } 269 270 var $field = $( this ).closest( '.ssg-logo-field' ); 271 var frame = wp.media( { 272 title: $( this ).data( 'title' ), 273 button: { text: $( this ).data( 'button' ) }, 274 library: { type: 'image' }, 275 multiple: false 276 } ); 277 278 frame.on( 'select', function () { 279 var image = frame.state().get( 'selection' ).first().toJSON(); 280 var src = image.sizes && image.sizes.medium ? image.sizes.medium.url : image.url; 281 282 $field.find( '#label_logo_id' ).val( image.id ); 283 $field.find( '.ssg-logo-preview' ).prop( 'hidden', false ).find( 'img' ).attr( 'src', src ); 284 $field.find( '.ssg-logo-remove' ).prop( 'hidden', false ); 285 } ); 286 287 frame.open(); 288 } ); 289 290 $( document ).on( 'click', '.ssg-logo-remove', function ( event ) { 291 event.preventDefault(); 292 293 var $field = $( this ).closest( '.ssg-logo-field' ); 294 295 $field.find( '#label_logo_id' ).val( 0 ); 296 $field.find( '.ssg-logo-preview' ).prop( 'hidden', true ).find( 'img' ).attr( 'src', '' ); 297 $( this ).prop( 'hidden', true ); 298 } ); 258 299 259 300 // The order box is redrawn after every action. -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/includes/class-ssg-install.php
r3826905 r3837719 246 246 247 247 /** 248 * One-off changes to an existing site's settings, made when it updates. 249 * 250 * 1.6.0: the status check moves to once a day at 1 pm, site time. Checking 251 * every hour called TCS 24 times a day for parcels that move once or twice. 252 * 253 * @return void 254 */ 255 public static function migrate_settings() { 256 $from = (string) get_option( 'tcsg_version', '' ); 257 258 if ( SSGW_VERSION === $from ) { 259 return; 260 } 261 262 if ( '' !== $from && version_compare( $from, '1.6.0', '<' ) ) { 263 SSGW_Settings::update( 264 array( 265 'sync_schedule' => 'daily', 266 'sync_time' => '13:00', 267 ) 268 ); 269 } 270 271 update_option( 'tcsg_version', SSGW_VERSION ); 272 } 273 274 /** 248 275 * Run pending upgrades on load. 249 276 * … … 251 278 */ 252 279 public static function maybe_upgrade() { 280 self::migrate_settings(); 281 253 282 if ( get_option( 'tcsg_db_version' ) === self::DB_VERSION ) { 254 283 return; -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/includes/class-ssg-notifier.php
r3826905 r3837719 45 45 } 46 46 47 if ( ! $this->status_is_selected( $status ) ) {48 return;49 }50 51 47 // A status rule that emails has already told the customer about this. 52 if ( SSGW_Settings::is_on( 'notify_customer', true ) && ! SSGW_Status_Rules::emails_for( $status, (string) $order->get_meta( SSGW_Order_Manager::META_STATUS_CODE ) ) ) { 48 if ( SSGW_Settings::is_on( 'notify_customer', true ) 49 && $this->status_is_selected( $status, self::chosen( 'customer' ) ) 50 && ! SSGW_Status_Rules::emails_for( $status, (string) $order->get_meta( SSGW_Order_Manager::META_STATUS_CODE ) ) ) { 53 51 $this->mail_customer( $order, $status ); 54 52 } 55 53 56 if ( SSGW_Settings::is_on( 'notify_admin', false ) ) {54 if ( SSGW_Settings::is_on( 'notify_admin', false ) && $this->status_is_selected( $status, self::chosen( 'admin' ) ) ) { 57 55 $this->mail_admin( $order, $status, $previous ); 58 56 } … … 67 65 * 68 66 * @param string $status Courier status. 67 * @param array $wanted Keywords chosen for this email. 69 68 * @return bool 70 69 */ 71 protected function status_is_selected( $status ) { 72 $wanted = SSGW_Settings::get( 'notify_statuses', array() ); 73 70 protected function status_is_selected( $status, $wanted ) { 74 71 if ( ! is_array( $wanted ) || array() === $wanted ) { 75 72 return true; … … 121 118 return false !== strpos( $status, $candidate ); 122 119 } 120 } 121 122 /** 123 * The statuses chosen for one email. 124 * 125 * Before 1.6.0 one list served both emails, so a site that has not chosen 126 * separately yet keeps what it had for both. 127 * 128 * @param string $who customer or admin. 129 * @return array Keywords; empty means every change. 130 */ 131 public static function chosen( $who ) { 132 $all = SSGW_Settings::all(); 133 $key = 'admin' === $who ? 'notify_admin_statuses' : 'notify_customer_statuses'; 134 $list = array_key_exists( $key, $all ) && is_array( $all[ $key ] ) ? $all[ $key ] : null; 135 136 if ( null === $list ) { 137 $list = isset( $all['notify_statuses'] ) && is_array( $all['notify_statuses'] ) ? $all['notify_statuses'] : array(); 138 } 139 140 return array_values( array_intersect( array_map( 'strval', $list ), array_keys( self::selectable_statuses() ) ) ); 123 141 } 124 142 -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/includes/class-ssg-settings.php
r3834387 r3837719 164 164 'store_labels' => 'yes', 165 165 'auto_sync_status' => 'yes', 166 'sync_schedule' => ' hourly',166 'sync_schedule' => 'daily', 167 167 'sync_time' => '13:00', 168 168 'shipper_city_id' => 0, … … 180 180 'validate_mobile' => 'no', 181 181 'call_ahead_remark' => 'no', 182 'allow_open' => 'no', 182 183 'cn_in_wc_emails' => 'yes', 183 184 'validate_city' => 'yes', … … 204 205 // Label printing. 205 206 'label_size' => '6x4', 207 'label_logo_id' => 0, 206 208 'label_page' => 1, 207 209 'label_zoom' => 100, -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/includes/class-ssg-shipment.php
r3834387 r3837719 16 16 */ 17 17 class SSGW_Shipment { 18 19 /** 20 * The most TCS accepts in one address line. 21 */ 22 const ADDRESS_MAX = 120; 18 23 19 24 /** … … 212 217 * The remarks printed on the consignment note. 213 218 * 219 * Short instructions for the rider, each its own sentence, in a fixed order: 220 * what was typed for this order or in the settings, then "call first", then 221 * "allow to open". 222 * 214 223 * @param WC_Order $order Order. 215 224 * @param array $overrides Overrides. … … 221 230 : (string) SSGW_Settings::get( 'shipment_remarks', '' ); 222 231 223 if ( ! SSGW_Settings::is_on( 'call_ahead_remark', false ) ) { 224 return $remarks; 225 } 226 227 $phone = (string) $order->get_billing_phone(); 228 229 if ( '' === $phone ) { 230 return $remarks; 231 } 232 233 /** 234 * Filter the instruction asking the rider to call first. 235 * 236 * @param string $line The remark. 237 * @param string $phone The customer's phone number. 238 * @param WC_Order $order Order. 239 */ 240 $line = (string) apply_filters( 241 'tcsg_call_ahead_remark', 242 sprintf( 243 /* translators: %s: customer phone number. */ 244 __( 'Call me before delivery on %s', 'softsquare-shipping-gateway-for-woocommerce' ), 245 $phone 246 ), 247 $phone, 248 $order 249 ); 250 251 return false !== strpos( $remarks, $line ) ? $remarks : trim( $remarks . ' ' . $line ); 232 $parts = '' !== trim( $remarks ) ? array( rtrim( trim( $remarks ), '.' ) . '.' ) : array(); 233 $phone = self::readable_phone( (string) $order->get_billing_phone() ); 234 235 if ( SSGW_Settings::is_on( 'call_ahead_remark', false ) && '' !== $phone ) { 236 /** 237 * Filter the instruction asking the rider to call first. 238 * 239 * @param string $line The remark. 240 * @param string $phone The customer's phone number. 241 * @param WC_Order $order Order. 242 */ 243 $parts[] = (string) apply_filters( 244 'tcsg_call_ahead_remark', 245 sprintf( 246 /* translators: %s: customer phone number. */ 247 __( 'Please call the customer before delivery: %s.', 'softsquare-shipping-gateway-for-woocommerce' ), 248 $phone 249 ), 250 $phone, 251 $order 252 ); 253 } 254 255 if ( self::allow_open() ) { 256 $parts[] = __( 'Allow to open: the customer may open and check the parcel before paying.', 'softsquare-shipping-gateway-for-woocommerce' ); 257 } 258 259 $parts = array_values( array_unique( array_filter( array_map( 'trim', $parts ) ) ) ); 260 261 // The same sentence typed into the settings and switched on is said once. 262 $joined = ''; 263 264 foreach ( $parts as $part ) { 265 if ( '' === $joined || false === stripos( $joined, rtrim( $part, '.' ) ) ) { 266 $joined = trim( $joined . ' ' . $part ); 267 } 268 } 269 270 return $joined; 271 } 272 273 /** 274 * Whether the parcel may be opened before payment. 275 * 276 * @return bool 277 */ 278 public static function allow_open() { 279 return SSGW_Settings::is_on( 'allow_open', false ); 280 } 281 282 /** 283 * A Pakistani mobile number written the way people read it out: 0331-9104217. 284 * Anything else is returned as it was typed. 285 * 286 * @param string $phone Phone number. 287 * @return string 288 */ 289 public static function readable_phone( $phone ) { 290 $phone = trim( (string) $phone ); 291 $digits = preg_replace( '/\D/', '', $phone ); 292 293 if ( 12 === strlen( $digits ) && 0 === strpos( $digits, '923' ) ) { 294 $digits = '0' . substr( $digits, 2 ); 295 } 296 297 if ( 11 === strlen( $digits ) && 0 === strpos( $digits, '03' ) ) { 298 return substr( $digits, 0, 4 ) . '-' . substr( $digits, 4 ); 299 } 300 301 return $phone; 252 302 } 253 303 … … 426 476 } 427 477 428 $parts = array(); 478 $lines = self::item_lines( $order ); 479 $count = 0; 429 480 430 481 foreach ( $order->get_items() as $item ) { 431 $name = self::plain_text( $item->get_name() ); 432 433 if ( '' === $name ) { 434 continue; 435 } 436 437 $quantity = max( 1, (int) $item->get_quantity() ); 438 $parts[] = $quantity > 1 ? $quantity . ' x ' . $name : $name; 439 } 440 441 $description = $parts ? implode( ', ', $parts ) : __( 'Merchandise', 'softsquare-shipping-gateway-for-woocommerce' ); 482 if ( '' !== self::plain_text( $item->get_name() ) ) { 483 $count += max( 1, (int) $item->get_quantity() ); 484 } 485 } 486 487 /* 488 * Written to be read off a printed label: the order number and how many 489 * pieces to expect first, then each product numbered with its quantity, 490 * so a packer or rider can count the contents against the list. 491 */ 492 $description = $lines 493 ? sprintf( 494 /* translators: 1: order number, 2: number of items, 3: the numbered list of products. */ 495 _n( 'Order #%1$s - %2$d item: %3$s', 'Order #%1$s - %2$d items: %3$s', $count, 'softsquare-shipping-gateway-for-woocommerce' ), 496 $order->get_order_number(), 497 $count, 498 implode( ' | ', $lines ) 499 ) 500 : __( 'Merchandise', 'softsquare-shipping-gateway-for-woocommerce' ); 442 501 443 502 /** … … 448 507 */ 449 508 return apply_filters( 'tcsg_content_description', $description, $order ); 509 } 510 511 /** 512 * Address lines longer than TCS accepts, each as a sentence saying so. 513 * 514 * TCS keeps the first 120 characters of a line and drops the rest, so a 515 * long address reaches the rider without its area or city. Caught before 516 * booking rather than discovered as a failed delivery. 517 * 518 * @param array|WC_Order $consignee Consignee block, or the order to build it from. 519 * @return array 520 */ 521 public static function address_problems( $consignee ) { 522 if ( $consignee instanceof WC_Order ) { 523 $consignee = self::consignee( $consignee, SSGW_Order_Manager::saved_overrides( $consignee ) ); 524 } 525 526 $problems = array(); 527 528 foreach ( array( 'address1', 'address2', 'address3' ) as $line ) { 529 $text = trim( (string) $consignee[ $line ] ); 530 $length = function_exists( 'mb_strlen' ) ? mb_strlen( $text, 'UTF-8' ) : strlen( $text ); 531 532 if ( $length > self::ADDRESS_MAX ) { 533 $problems[] = sprintf( 534 /* translators: 1: number of characters, 2: the limit, 3: the address as typed. */ 535 __( 'The delivery address is %1$d characters long, and TCS accepts at most %2$d on one line, so the end would be cut off. Shorten it, or move part of it to the second address line, in the order\'s shipping address: "%3$s"', 'softsquare-shipping-gateway-for-woocommerce' ), 536 $length, 537 self::ADDRESS_MAX, 538 $text 539 ); 540 } 541 } 542 543 return $problems; 544 } 545 546 /** 547 * The order's products, numbered, each with its quantity: "1) 2 x Serum". 548 * 549 * @param WC_Order $order Order. 550 * @return array 551 */ 552 public static function item_lines( $order ) { 553 $lines = array(); 554 555 foreach ( $order->get_items() as $item ) { 556 $name = self::plain_text( $item->get_name() ); 557 558 if ( '' === $name ) { 559 continue; 560 } 561 562 $lines[] = sprintf( '%d) %d x %s', count( $lines ) + 1, max( 1, (int) $item->get_quantity() ), $name ); 563 } 564 565 return $lines; 450 566 } 451 567 … … 538 654 } 539 655 656 $problems = array_merge( $problems, self::address_problems( $consignee ) ); 657 540 658 if ( '' === trim( $consignee['city'] ) ) { 541 659 $problems[] = __( 'The delivery city is empty.', 'softsquare-shipping-gateway-for-woocommerce' ); -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/readme.txt
r3834387 r3837719 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 1. 5.47 Stable tag: 1.6.2 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 262 262 == Changelog == 263 263 264 = 1.6.2 = 265 * New: 4 x 6 inch thermal labels as a PDF, one parcel per page, laid out like TCS's own note: the consignment barcode and QR code, destination, the amount to collect with its barcode, order number, products and sender. Download one from the order screen, or many at once with the bulk action "TCS: download 4 x 6 thermal labels (PDF)". 266 * New: your own logo on the 4 x 6 label. Choose it under Settings → Label printing; the best size is 600 x 130 pixels, dark on a white or transparent background. 267 * New: choose which TCS statuses email the customer and which email the store, from two searchable lists. Sites that had one list keep it for both. 268 * New: "Allow to open" setting. Adds an instruction to the remarks that the customer may open and check the parcel before paying, and prints ALLOW TO OPEN on the 4 x 6 label. 269 * The contents description now starts with the order number and item count, then numbers each product with its quantity, so it is easy to read on a printed label. 270 * Clearer call-first remark: "Please call the customer before delivery: 0300-1234567." 271 * An address line longer than the 120 characters TCS accepts is now caught before booking, with the length and the address shown, instead of TCS silently cutting off the end. 272 * Status checks now run once a day at 1 pm by default. Existing sites are moved to this on update; it can be changed under Settings. 273 * A small, dismissible request for a review, shown only on this plugin's screens after a week of use. 274 264 275 = 1.5.4 = 265 276 * New: Fixed weight, under Settings → Booking. When set, every new booking is sent to TCS at that weight instead of the weight of its products. A weight typed on an order screen still wins for that order, and parcels already booked are not flagged for re-booking. … … 356 367 == Upgrade Notice == 357 368 369 = 1.6.2 = 370 Adds 4 x 6 thermal label PDFs with your logo, separate status email lists for the customer and the store, and an "Allow to open" option. The status check moves to once a day at 1 pm. 371 358 372 = 1.5.4 = 359 373 Adds an optional fixed weight for new bookings. It is off until you set it, so nothing changes on upgrade. -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/softsquare-shipping-gateway.php
r3834387 r3837719 4 4 * Plugin URI: https://softsquare.io/softsquare-shipping-gateway/ 5 5 * Description: Connects WooCommerce to TCS Pakistan for TCS shipment booking, TCS shipping labels, TCS tracking, and COD deliveries, through the SoftSquare service. 6 * Version: 1. 5.46 * Version: 1.6.2 7 7 * Requires at least: 6.0 8 8 * Requires PHP: 7.4 … … 50 50 defined( 'ABSPATH' ) || exit; 51 51 52 define( 'SSGW_VERSION', '1. 5.4' );52 define( 'SSGW_VERSION', '1.6.2' ); 53 53 define( 'SSGW_FILE', __FILE__ ); 54 54 define( 'SSGW_PATH', plugin_dir_path( __FILE__ ) ); … … 98 98 'includes/class-ssg-label-pdf.php', 99 99 'includes/class-ssg-label-print.php', 100 'includes/class-ssg-qr.php', 101 'includes/class-ssg-thermal-label.php', 100 102 'includes/class-ssg-notifier.php', 101 103 'includes/class-ssg-ajax.php', … … 110 112 'admin/class-ssg-admin-email-test.php', 111 113 'admin/class-ssg-admin-logs.php', 114 'admin/class-ssg-admin-review.php', 112 115 'public/class-ssg-public.php', 113 116 ); -
softsquare-shipping-gateway-for-woocommerce/tags/1.6.2/uninstall.php
r3826905 r3837719 24 24 delete_option( 'tcsg_connect_error' ); 25 25 delete_option( 'tcsg_tracking_page_created' ); 26 delete_option( 'tcsg_first_used_at' ); 27 delete_metadata( 'user', 0, 'tcsg_review_request', '', true ); 26 28 delete_option( 'tcsg_last_sync' ); 27 29 delete_option( 'tcsg_financials_since' ); -
softsquare-shipping-gateway-for-woocommerce/trunk/admin/class-ssg-admin-orders.php
r3834387 r3837719 262 262 <h4><?php esc_html_e( 'Booking details', 'softsquare-shipping-gateway-for-woocommerce' ); ?></h4> 263 263 <p class="ssg-muted"><?php esc_html_e( 'Filled in from the order. Change a box only if this parcel is different, then press Book.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 264 <?php foreach ( SSGW_Shipment::address_problems( $order ) as $address_problem ) : ?> 265 <p class="ssg-warn"><?php echo esc_html( $address_problem ); ?></p> 266 <?php endforeach; ?> 264 267 <?php self::booking_fields( $order ); ?> 265 268 <?php if ( SSGW_Features::is_enabled( 'cost_sync' ) ) : ?> … … 304 307 <?php endif; ?> 305 308 <a href="<?php echo esc_url( SSGW_Label_Print::url( $order->get_id() ) ); ?>" target="_blank" rel="noopener" class="ssg-label-link"><?php esc_html_e( 'Print at label size', 'softsquare-shipping-gateway-for-woocommerce' ); ?></a> 309 <a href="<?php echo esc_url( SSGW_Thermal_Label::url( $order->get_id() ) ); ?>" target="_blank" rel="noopener" class="ssg-label-link"><?php esc_html_e( '4 x 6 thermal label (PDF)', 'softsquare-shipping-gateway-for-woocommerce' ); ?></a> 306 310 </p> 307 311 … … 674 678 $actions['tcsg_book'] = __( 'TCS: book shipments', 'softsquare-shipping-gateway-for-woocommerce' ); 675 679 $actions['tcsg_labels'] = __( 'TCS: print labels', 'softsquare-shipping-gateway-for-woocommerce' ); 680 $actions['tcsg_thermal'] = __( 'TCS: download 4 x 6 thermal labels (PDF)', 'softsquare-shipping-gateway-for-woocommerce' ); 676 681 $actions['tcsg_refresh'] = __( 'TCS: refresh tracking status', 'softsquare-shipping-gateway-for-woocommerce' ); 677 682 $actions['tcsg_sheet'] = sprintf( … … 693 698 */ 694 699 public function handle_bulk_actions( $redirect_to, $action, $ids ) { 695 if ( ! in_array( $action, array( 'tcsg_book', 'tcsg_labels', 'tcsg_refresh', 'tcsg_sheet' ), true ) ) {700 if ( ! in_array( $action, array( 'tcsg_book', 'tcsg_labels', 'tcsg_refresh', 'tcsg_sheet', 'tcsg_thermal' ), true ) ) { 696 701 return $redirect_to; 697 702 } … … 702 707 703 708 $ids = array_map( 'absint', (array) $ids ); 709 710 if ( 'tcsg_thermal' === $action ) { 711 return SSGW_Thermal_Label::url( $ids ); 712 } 704 713 705 714 if ( 'tcsg_sheet' === $action ) { -
softsquare-shipping-gateway-for-woocommerce/trunk/admin/class-ssg-admin-settings.php
r3834387 r3837719 115 115 'validate_mobile', 116 116 'call_ahead_remark', 117 'allow_open', 117 118 'cn_in_wc_emails', 118 119 'collect_area_block', … … 277 278 $values['print_extra_params'] = isset( $_POST['print_extra_params'] ) ? sanitize_textarea_field( wp_unslash( $_POST['print_extra_params'] ) ) : ''; 278 279 $values['email_format'] = isset( $_POST['email_format'] ) && 'html' === $_POST['email_format'] ? 'html' : 'plain'; 280 $logo_id = isset( $_POST['label_logo_id'] ) ? absint( wp_unslash( $_POST['label_logo_id'] ) ) : 0; 281 $values['label_logo_id'] = $logo_id && wp_attachment_is_image( $logo_id ) ? $logo_id : 0; 279 282 $values['email_accent'] = isset( $_POST['email_accent'] ) ? (string) sanitize_hex_color( wp_unslash( $_POST['email_accent'] ) ) : ''; 280 283 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- SSGW_Status_Rules::sanitize() cleans each field. … … 283 286 // Nothing ticked means every status change, which is what the empty 284 287 // default means too — see SSGW_Notifier::status_is_selected(). 285 $values['notify_statuses'] = isset( $_POST['notify_statuses'] ) && is_array( $_POST['notify_statuses'] ) 286 ? array_map( 'sanitize_text_field', wp_unslash( $_POST['notify_statuses'] ) ) 287 : array(); 288 foreach ( array( 'notify_customer_statuses', 'notify_admin_statuses' ) as $list_key ) { 289 $values[ $list_key ] = isset( $_POST[ $list_key ] ) && is_array( $_POST[ $list_key ] ) 290 ? array_values( array_intersect( array_map( 'sanitize_key', wp_unslash( $_POST[ $list_key ] ) ), array_keys( SSGW_Notifier::selectable_statuses() ) ) ) 291 : array(); 292 } 288 293 // phpcs:enable 289 294 … … 897 902 $extra = array( 898 903 'cn_in_wc_emails' => array( __( 'Add the consignment number and tracking link to WooCommerce order emails', 'softsquare-shipping-gateway-for-woocommerce' ), true ), 899 'call_ahead_remark' => array( __( 'Ask the rider to call first: adds "Call me before delivery on" and the customer\'s number to the consignment note', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 904 'call_ahead_remark' => array( __( 'Ask the rider to call first: adds "Please call the customer before delivery:" and the customer\'s number to the remarks', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 905 'allow_open' => array( __( 'Allow to open: the customer may open and check the parcel before paying. Added to the remarks, and printed on the 4 x 6 label.', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 900 906 'validate_mobile' => array( __( 'At checkout, require a valid Pakistani mobile number (03XXXXXXXXX)', 'softsquare-shipping-gateway-for-woocommerce' ), false ), 901 907 'collect_area_block' => array( __( 'At checkout, ask for the area and block as well as the city. Each new city or area a customer picks is looked up through the SoftSquare service.', 'softsquare-shipping-gateway-for-woocommerce' ), false ), … … 917 923 <h2 class="title"><?php esc_html_e( 'Label printing', 'softsquare-shipping-gateway-for-woocommerce' ); ?></h2> 918 924 <table class="form-table" role="presentation"> 925 <tr> 926 <th scope="row"><?php esc_html_e( 'Logo on labels', 'softsquare-shipping-gateway-for-woocommerce' ); ?></th> 927 <td> 928 <?php 929 $logo_id = (int) SSGW_Settings::get( 'label_logo_id', 0 ); 930 $logo_src = $logo_id ? wp_get_attachment_image_url( $logo_id, 'medium' ) : ''; 931 ?> 932 <div class="ssg-logo-field"> 933 <input type="hidden" name="label_logo_id" id="label_logo_id" value="<?php echo esc_attr( $logo_src ? $logo_id : 0 ); ?>"> 934 <div class="ssg-logo-preview"<?php echo $logo_src ? '' : ' hidden'; ?>> 935 <img src="<?php echo esc_url( (string) $logo_src ); ?>" alt=""> 936 </div> 937 <button type="button" class="button ssg-logo-pick" 938 data-title="<?php esc_attr_e( 'Logo for labels', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" 939 data-button="<?php esc_attr_e( 'Use this logo', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"><?php esc_html_e( 'Choose logo', 'softsquare-shipping-gateway-for-woocommerce' ); ?></button> 940 <button type="button" class="button-link ssg-logo-remove"<?php echo $logo_src ? '' : ' hidden'; ?>><?php esc_html_e( 'Remove', 'softsquare-shipping-gateway-for-woocommerce' ); ?></button> 941 </div> 942 <p class="description"> 943 <?php esc_html_e( 'Printed at the top left of the 4 x 6 thermal label PDF, in a space 50 x 11 mm (about 2 x 0.4 inches). TCS\'s own A4 labels are TCS\'s artwork and are not changed.', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 944 </p> 945 <p class="description"> 946 <strong><?php esc_html_e( 'Best size: 600 x 130 pixels', 'softsquare-shipping-gateway-for-woocommerce' ); ?></strong> 947 <?php esc_html_e( '(a wide logo, about 4.5 : 1), PNG or JPG, black or dark on a white or transparent background. A square logo still works but prints only 11 mm tall. Thermal printers print in black only, so light colours fade.', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 948 </p> 949 </td> 950 </tr> 919 951 <tr> 920 952 <th scope="row"><label for="label_size"><?php esc_html_e( 'Label size', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> … … 1199 1231 </tr> 1200 1232 <tr> 1201 <th scope="row"><?php esc_html_e( 'Which changes', 'softsquare-shipping-gateway-for-woocommerce' ); ?></th> 1202 <td> 1203 <?php 1204 $chosen_statuses = (array) SSGW_Settings::get( 'notify_statuses', array() ); 1205 1206 foreach ( SSGW_Notifier::selectable_statuses() as $key => $label ) : 1207 ?> 1208 <label class="ssg-check"> 1209 <input type="checkbox" name="notify_statuses[]" value="<?php echo esc_attr( $key ); ?>" 1210 <?php checked( in_array( $key, $chosen_statuses, true ) ); ?>> 1211 <?php echo esc_html( $label ); ?> 1212 </label><br> 1213 <?php endforeach; ?> 1214 <p class="description"> 1215 <?php esc_html_e( 'Tick nothing to be told about every change. TCS wording varies by account, so these are matched loosely — "Delivered" also catches "Delivered to consignee".', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 1216 </p> 1233 <th scope="row"><label for="notify_customer_statuses"><?php esc_html_e( 'Customer email for', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> 1234 <td> 1235 <?php $chosen_statuses = SSGW_Notifier::chosen( 'customer' ); ?> 1236 <select name="notify_customer_statuses[]" id="notify_customer_statuses" class="ssg-searchable ssg-multi" multiple="multiple" data-no-results="<?php esc_attr_e( 'No such status', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" data-placeholder="<?php esc_attr_e( 'Every status change', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"> 1237 <?php foreach ( SSGW_Notifier::selectable_statuses() as $key => $status_label ) : ?> 1238 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key, $chosen_statuses, true ) ); ?>><?php echo esc_html( $status_label ); ?></option> 1239 <?php endforeach; ?> 1240 </select> 1241 <p class="description"><?php esc_html_e( 'Statuses that email the customer. Leave empty for every change.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 1242 </td> 1243 </tr> 1244 <tr> 1245 <th scope="row"><label for="notify_admin_statuses"><?php esc_html_e( 'Store email for', 'softsquare-shipping-gateway-for-woocommerce' ); ?></label></th> 1246 <td> 1247 <?php $chosen_statuses = SSGW_Notifier::chosen( 'admin' ); ?> 1248 <select name="notify_admin_statuses[]" id="notify_admin_statuses" class="ssg-searchable ssg-multi" multiple="multiple" data-no-results="<?php esc_attr_e( 'No such status', 'softsquare-shipping-gateway-for-woocommerce' ); ?>" data-placeholder="<?php esc_attr_e( 'Every status change', 'softsquare-shipping-gateway-for-woocommerce' ); ?>"> 1249 <?php foreach ( SSGW_Notifier::selectable_statuses() as $key => $status_label ) : ?> 1250 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key, $chosen_statuses, true ) ); ?>><?php echo esc_html( $status_label ); ?></option> 1251 <?php endforeach; ?> 1252 </select> 1253 <p class="description"><?php esc_html_e( 'Statuses that email the store address above. Leave empty for every change.', 'softsquare-shipping-gateway-for-woocommerce' ); ?></p> 1254 </td> 1255 </tr> 1256 <tr> 1257 <td colspan="2" class="ssg-muted"> 1258 <?php esc_html_e( 'TCS wording varies by account, so statuses are matched loosely: "Delivered" also catches "Delivered to consignee".', 'softsquare-shipping-gateway-for-woocommerce' ); ?> 1217 1259 </td> 1218 1260 </tr> -
softsquare-shipping-gateway-for-woocommerce/trunk/admin/class-ssg-admin.php
r3826921 r3837719 80 80 */ 81 81 public $print; 82 83 /** 84 * Review request. 85 * 86 * @var SSGW_Admin_Review 87 */ 88 public $review; 89 90 /** 91 * 4 x 6 thermal labels. 92 * 93 * @var SSGW_Thermal_Label 94 */ 95 public $thermal; 82 96 83 97 /** … … 94 108 $this->email_test = new SSGW_Admin_Email_Test(); 95 109 $this->print = new SSGW_Label_Print(); 110 $this->review = new SSGW_Admin_Review(); 111 $this->thermal = new SSGW_Thermal_Label(); 96 112 97 113 add_action( 'admin_menu', array( $this, 'register_menu' ) ); … … 259 275 if ( wp_style_is( 'woocommerce_admin_styles', 'registered' ) ) { 260 276 wp_enqueue_style( 'woocommerce_admin_styles' ); 277 } 278 279 // The logo picker on the settings screen. 280 if ( 'toplevel_page_' . self::SLUG === $hook && function_exists( 'wp_enqueue_media' ) ) { 281 wp_enqueue_media(); 261 282 } 262 283 -
softsquare-shipping-gateway-for-woocommerce/trunk/assets/css/admin.css
r3826905 r3837719 1077 1077 margin: .4em 0; 1078 1078 } 1079 1080 /* Label logo */ 1081 .ssg-logo-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } 1082 .ssg-logo-preview { width: 236px; height: 52px; border: 1px dashed #c3c4c7; background: #fff; display: flex; align-items: center; justify-content: flex-start; padding: 4px; box-sizing: border-box; } 1083 .ssg-logo-preview[hidden] { display: none; } 1084 .ssg-logo-preview img { max-width: 100%; max-height: 100%; } -
softsquare-shipping-gateway-for-woocommerce/trunk/assets/js/admin.js
r3834301 r3837719 250 250 width: '100%', 251 251 placeholder: $select.data( 'placeholder' ) || '', 252 language: { noResults: function () { return i18n.noCity || 'No city found'; } }252 language: { noResults: function () { return $select.data( 'no-results' ) || i18n.noCity || 'No city found'; } } 253 253 } ); 254 254 } ); … … 256 256 257 257 $( enhanceSelects ); 258 259 /* --------------------------------------------------------------------- 260 * Label logo 261 * ------------------------------------------------------------------ */ 262 263 $( document ).on( 'click', '.ssg-logo-pick', function ( event ) { 264 event.preventDefault(); 265 266 if ( ! window.wp || ! wp.media ) { 267 return; 268 } 269 270 var $field = $( this ).closest( '.ssg-logo-field' ); 271 var frame = wp.media( { 272 title: $( this ).data( 'title' ), 273 button: { text: $( this ).data( 'button' ) }, 274 library: { type: 'image' }, 275 multiple: false 276 } ); 277 278 frame.on( 'select', function () { 279 var image = frame.state().get( 'selection' ).first().toJSON(); 280 var src = image.sizes && image.sizes.medium ? image.sizes.medium.url : image.url; 281 282 $field.find( '#label_logo_id' ).val( image.id ); 283 $field.find( '.ssg-logo-preview' ).prop( 'hidden', false ).find( 'img' ).attr( 'src', src ); 284 $field.find( '.ssg-logo-remove' ).prop( 'hidden', false ); 285 } ); 286 287 frame.open(); 288 } ); 289 290 $( document ).on( 'click', '.ssg-logo-remove', function ( event ) { 291 event.preventDefault(); 292 293 var $field = $( this ).closest( '.ssg-logo-field' ); 294 295 $field.find( '#label_logo_id' ).val( 0 ); 296 $field.find( '.ssg-logo-preview' ).prop( 'hidden', true ).find( 'img' ).attr( 'src', '' ); 297 $( this ).prop( 'hidden', true ); 298 } ); 258 299 259 300 // The order box is redrawn after every action. -
softsquare-shipping-gateway-for-woocommerce/trunk/includes/class-ssg-install.php
r3826905 r3837719 246 246 247 247 /** 248 * One-off changes to an existing site's settings, made when it updates. 249 * 250 * 1.6.0: the status check moves to once a day at 1 pm, site time. Checking 251 * every hour called TCS 24 times a day for parcels that move once or twice. 252 * 253 * @return void 254 */ 255 public static function migrate_settings() { 256 $from = (string) get_option( 'tcsg_version', '' ); 257 258 if ( SSGW_VERSION === $from ) { 259 return; 260 } 261 262 if ( '' !== $from && version_compare( $from, '1.6.0', '<' ) ) { 263 SSGW_Settings::update( 264 array( 265 'sync_schedule' => 'daily', 266 'sync_time' => '13:00', 267 ) 268 ); 269 } 270 271 update_option( 'tcsg_version', SSGW_VERSION ); 272 } 273 274 /** 248 275 * Run pending upgrades on load. 249 276 * … … 251 278 */ 252 279 public static function maybe_upgrade() { 280 self::migrate_settings(); 281 253 282 if ( get_option( 'tcsg_db_version' ) === self::DB_VERSION ) { 254 283 return; -
softsquare-shipping-gateway-for-woocommerce/trunk/includes/class-ssg-notifier.php
r3826905 r3837719 45 45 } 46 46 47 if ( ! $this->status_is_selected( $status ) ) {48 return;49 }50 51 47 // A status rule that emails has already told the customer about this. 52 if ( SSGW_Settings::is_on( 'notify_customer', true ) && ! SSGW_Status_Rules::emails_for( $status, (string) $order->get_meta( SSGW_Order_Manager::META_STATUS_CODE ) ) ) { 48 if ( SSGW_Settings::is_on( 'notify_customer', true ) 49 && $this->status_is_selected( $status, self::chosen( 'customer' ) ) 50 && ! SSGW_Status_Rules::emails_for( $status, (string) $order->get_meta( SSGW_Order_Manager::META_STATUS_CODE ) ) ) { 53 51 $this->mail_customer( $order, $status ); 54 52 } 55 53 56 if ( SSGW_Settings::is_on( 'notify_admin', false ) ) {54 if ( SSGW_Settings::is_on( 'notify_admin', false ) && $this->status_is_selected( $status, self::chosen( 'admin' ) ) ) { 57 55 $this->mail_admin( $order, $status, $previous ); 58 56 } … … 67 65 * 68 66 * @param string $status Courier status. 67 * @param array $wanted Keywords chosen for this email. 69 68 * @return bool 70 69 */ 71 protected function status_is_selected( $status ) { 72 $wanted = SSGW_Settings::get( 'notify_statuses', array() ); 73 70 protected function status_is_selected( $status, $wanted ) { 74 71 if ( ! is_array( $wanted ) || array() === $wanted ) { 75 72 return true; … … 121 118 return false !== strpos( $status, $candidate ); 122 119 } 120 } 121 122 /** 123 * The statuses chosen for one email. 124 * 125 * Before 1.6.0 one list served both emails, so a site that has not chosen 126 * separately yet keeps what it had for both. 127 * 128 * @param string $who customer or admin. 129 * @return array Keywords; empty means every change. 130 */ 131 public static function chosen( $who ) { 132 $all = SSGW_Settings::all(); 133 $key = 'admin' === $who ? 'notify_admin_statuses' : 'notify_customer_statuses'; 134 $list = array_key_exists( $key, $all ) && is_array( $all[ $key ] ) ? $all[ $key ] : null; 135 136 if ( null === $list ) { 137 $list = isset( $all['notify_statuses'] ) && is_array( $all['notify_statuses'] ) ? $all['notify_statuses'] : array(); 138 } 139 140 return array_values( array_intersect( array_map( 'strval', $list ), array_keys( self::selectable_statuses() ) ) ); 123 141 } 124 142 -
softsquare-shipping-gateway-for-woocommerce/trunk/includes/class-ssg-settings.php
r3834387 r3837719 164 164 'store_labels' => 'yes', 165 165 'auto_sync_status' => 'yes', 166 'sync_schedule' => ' hourly',166 'sync_schedule' => 'daily', 167 167 'sync_time' => '13:00', 168 168 'shipper_city_id' => 0, … … 180 180 'validate_mobile' => 'no', 181 181 'call_ahead_remark' => 'no', 182 'allow_open' => 'no', 182 183 'cn_in_wc_emails' => 'yes', 183 184 'validate_city' => 'yes', … … 204 205 // Label printing. 205 206 'label_size' => '6x4', 207 'label_logo_id' => 0, 206 208 'label_page' => 1, 207 209 'label_zoom' => 100, -
softsquare-shipping-gateway-for-woocommerce/trunk/includes/class-ssg-shipment.php
r3834387 r3837719 16 16 */ 17 17 class SSGW_Shipment { 18 19 /** 20 * The most TCS accepts in one address line. 21 */ 22 const ADDRESS_MAX = 120; 18 23 19 24 /** … … 212 217 * The remarks printed on the consignment note. 213 218 * 219 * Short instructions for the rider, each its own sentence, in a fixed order: 220 * what was typed for this order or in the settings, then "call first", then 221 * "allow to open". 222 * 214 223 * @param WC_Order $order Order. 215 224 * @param array $overrides Overrides. … … 221 230 : (string) SSGW_Settings::get( 'shipment_remarks', '' ); 222 231 223 if ( ! SSGW_Settings::is_on( 'call_ahead_remark', false ) ) { 224 return $remarks; 225 } 226 227 $phone = (string) $order->get_billing_phone(); 228 229 if ( '' === $phone ) { 230 return $remarks; 231 } 232 233 /** 234 * Filter the instruction asking the rider to call first. 235 * 236 * @param string $line The remark. 237 * @param string $phone The customer's phone number. 238 * @param WC_Order $order Order. 239 */ 240 $line = (string) apply_filters( 241 'tcsg_call_ahead_remark', 242 sprintf( 243 /* translators: %s: customer phone number. */ 244 __( 'Call me before delivery on %s', 'softsquare-shipping-gateway-for-woocommerce' ), 245 $phone 246 ), 247 $phone, 248 $order 249 ); 250 251 return false !== strpos( $remarks, $line ) ? $remarks : trim( $remarks . ' ' . $line ); 232 $parts = '' !== trim( $remarks ) ? array( rtrim( trim( $remarks ), '.' ) . '.' ) : array(); 233 $phone = self::readable_phone( (string) $order->get_billing_phone() ); 234 235 if ( SSGW_Settings::is_on( 'call_ahead_remark', false ) && '' !== $phone ) { 236 /** 237 * Filter the instruction asking the rider to call first. 238 * 239 * @param string $line The remark. 240 * @param string $phone The customer's phone number. 241 * @param WC_Order $order Order. 242 */ 243 $parts[] = (string) apply_filters( 244 'tcsg_call_ahead_remark', 245 sprintf( 246 /* translators: %s: customer phone number. */ 247 __( 'Please call the customer before delivery: %s.', 'softsquare-shipping-gateway-for-woocommerce' ), 248 $phone 249 ), 250 $phone, 251 $order 252 ); 253 } 254 255 if ( self::allow_open() ) { 256 $parts[] = __( 'Allow to open: the customer may open and check the parcel before paying.', 'softsquare-shipping-gateway-for-woocommerce' ); 257 } 258 259 $parts = array_values( array_unique( array_filter( array_map( 'trim', $parts ) ) ) ); 260 261 // The same sentence typed into the settings and switched on is said once. 262 $joined = ''; 263 264 foreach ( $parts as $part ) { 265 if ( '' === $joined || false === stripos( $joined, rtrim( $part, '.' ) ) ) { 266 $joined = trim( $joined . ' ' . $part ); 267 } 268 } 269 270 return $joined; 271 } 272 273 /** 274 * Whether the parcel may be opened before payment. 275 * 276 * @return bool 277 */ 278 public static function allow_open() { 279 return SSGW_Settings::is_on( 'allow_open', false ); 280 } 281 282 /** 283 * A Pakistani mobile number written the way people read it out: 0331-9104217. 284 * Anything else is returned as it was typed. 285 * 286 * @param string $phone Phone number. 287 * @return string 288 */ 289 public static function readable_phone( $phone ) { 290 $phone = trim( (string) $phone ); 291 $digits = preg_replace( '/\D/', '', $phone ); 292 293 if ( 12 === strlen( $digits ) && 0 === strpos( $digits, '923' ) ) { 294 $digits = '0' . substr( $digits, 2 ); 295 } 296 297 if ( 11 === strlen( $digits ) && 0 === strpos( $digits, '03' ) ) { 298 return substr( $digits, 0, 4 ) . '-' . substr( $digits, 4 ); 299 } 300 301 return $phone; 252 302 } 253 303 … … 426 476 } 427 477 428 $parts = array(); 478 $lines = self::item_lines( $order ); 479 $count = 0; 429 480 430 481 foreach ( $order->get_items() as $item ) { 431 $name = self::plain_text( $item->get_name() ); 432 433 if ( '' === $name ) { 434 continue; 435 } 436 437 $quantity = max( 1, (int) $item->get_quantity() ); 438 $parts[] = $quantity > 1 ? $quantity . ' x ' . $name : $name; 439 } 440 441 $description = $parts ? implode( ', ', $parts ) : __( 'Merchandise', 'softsquare-shipping-gateway-for-woocommerce' ); 482 if ( '' !== self::plain_text( $item->get_name() ) ) { 483 $count += max( 1, (int) $item->get_quantity() ); 484 } 485 } 486 487 /* 488 * Written to be read off a printed label: the order number and how many 489 * pieces to expect first, then each product numbered with its quantity, 490 * so a packer or rider can count the contents against the list. 491 */ 492 $description = $lines 493 ? sprintf( 494 /* translators: 1: order number, 2: number of items, 3: the numbered list of products. */ 495 _n( 'Order #%1$s - %2$d item: %3$s', 'Order #%1$s - %2$d items: %3$s', $count, 'softsquare-shipping-gateway-for-woocommerce' ), 496 $order->get_order_number(), 497 $count, 498 implode( ' | ', $lines ) 499 ) 500 : __( 'Merchandise', 'softsquare-shipping-gateway-for-woocommerce' ); 442 501 443 502 /** … … 448 507 */ 449 508 return apply_filters( 'tcsg_content_description', $description, $order ); 509 } 510 511 /** 512 * Address lines longer than TCS accepts, each as a sentence saying so. 513 * 514 * TCS keeps the first 120 characters of a line and drops the rest, so a 515 * long address reaches the rider without its area or city. Caught before 516 * booking rather than discovered as a failed delivery. 517 * 518 * @param array|WC_Order $consignee Consignee block, or the order to build it from. 519 * @return array 520 */ 521 public static function address_problems( $consignee ) { 522 if ( $consignee instanceof WC_Order ) { 523 $consignee = self::consignee( $consignee, SSGW_Order_Manager::saved_overrides( $consignee ) ); 524 } 525 526 $problems = array(); 527 528 foreach ( array( 'address1', 'address2', 'address3' ) as $line ) { 529 $text = trim( (string) $consignee[ $line ] ); 530 $length = function_exists( 'mb_strlen' ) ? mb_strlen( $text, 'UTF-8' ) : strlen( $text ); 531 532 if ( $length > self::ADDRESS_MAX ) { 533 $problems[] = sprintf( 534 /* translators: 1: number of characters, 2: the limit, 3: the address as typed. */ 535 __( 'The delivery address is %1$d characters long, and TCS accepts at most %2$d on one line, so the end would be cut off. Shorten it, or move part of it to the second address line, in the order\'s shipping address: "%3$s"', 'softsquare-shipping-gateway-for-woocommerce' ), 536 $length, 537 self::ADDRESS_MAX, 538 $text 539 ); 540 } 541 } 542 543 return $problems; 544 } 545 546 /** 547 * The order's products, numbered, each with its quantity: "1) 2 x Serum". 548 * 549 * @param WC_Order $order Order. 550 * @return array 551 */ 552 public static function item_lines( $order ) { 553 $lines = array(); 554 555 foreach ( $order->get_items() as $item ) { 556 $name = self::plain_text( $item->get_name() ); 557 558 if ( '' === $name ) { 559 continue; 560 } 561 562 $lines[] = sprintf( '%d) %d x %s', count( $lines ) + 1, max( 1, (int) $item->get_quantity() ), $name ); 563 } 564 565 return $lines; 450 566 } 451 567 … … 538 654 } 539 655 656 $problems = array_merge( $problems, self::address_problems( $consignee ) ); 657 540 658 if ( '' === trim( $consignee['city'] ) ) { 541 659 $problems[] = __( 'The delivery city is empty.', 'softsquare-shipping-gateway-for-woocommerce' ); -
softsquare-shipping-gateway-for-woocommerce/trunk/readme.txt
r3834387 r3837719 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 1. 5.47 Stable tag: 1.6.2 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 262 262 == Changelog == 263 263 264 = 1.6.2 = 265 * New: 4 x 6 inch thermal labels as a PDF, one parcel per page, laid out like TCS's own note: the consignment barcode and QR code, destination, the amount to collect with its barcode, order number, products and sender. Download one from the order screen, or many at once with the bulk action "TCS: download 4 x 6 thermal labels (PDF)". 266 * New: your own logo on the 4 x 6 label. Choose it under Settings → Label printing; the best size is 600 x 130 pixels, dark on a white or transparent background. 267 * New: choose which TCS statuses email the customer and which email the store, from two searchable lists. Sites that had one list keep it for both. 268 * New: "Allow to open" setting. Adds an instruction to the remarks that the customer may open and check the parcel before paying, and prints ALLOW TO OPEN on the 4 x 6 label. 269 * The contents description now starts with the order number and item count, then numbers each product with its quantity, so it is easy to read on a printed label. 270 * Clearer call-first remark: "Please call the customer before delivery: 0300-1234567." 271 * An address line longer than the 120 characters TCS accepts is now caught before booking, with the length and the address shown, instead of TCS silently cutting off the end. 272 * Status checks now run once a day at 1 pm by default. Existing sites are moved to this on update; it can be changed under Settings. 273 * A small, dismissible request for a review, shown only on this plugin's screens after a week of use. 274 264 275 = 1.5.4 = 265 276 * New: Fixed weight, under Settings → Booking. When set, every new booking is sent to TCS at that weight instead of the weight of its products. A weight typed on an order screen still wins for that order, and parcels already booked are not flagged for re-booking. … … 356 367 == Upgrade Notice == 357 368 369 = 1.6.2 = 370 Adds 4 x 6 thermal label PDFs with your logo, separate status email lists for the customer and the store, and an "Allow to open" option. The status check moves to once a day at 1 pm. 371 358 372 = 1.5.4 = 359 373 Adds an optional fixed weight for new bookings. It is off until you set it, so nothing changes on upgrade. -
softsquare-shipping-gateway-for-woocommerce/trunk/softsquare-shipping-gateway.php
r3834387 r3837719 4 4 * Plugin URI: https://softsquare.io/softsquare-shipping-gateway/ 5 5 * Description: Connects WooCommerce to TCS Pakistan for TCS shipment booking, TCS shipping labels, TCS tracking, and COD deliveries, through the SoftSquare service. 6 * Version: 1. 5.46 * Version: 1.6.2 7 7 * Requires at least: 6.0 8 8 * Requires PHP: 7.4 … … 50 50 defined( 'ABSPATH' ) || exit; 51 51 52 define( 'SSGW_VERSION', '1. 5.4' );52 define( 'SSGW_VERSION', '1.6.2' ); 53 53 define( 'SSGW_FILE', __FILE__ ); 54 54 define( 'SSGW_PATH', plugin_dir_path( __FILE__ ) ); … … 98 98 'includes/class-ssg-label-pdf.php', 99 99 'includes/class-ssg-label-print.php', 100 'includes/class-ssg-qr.php', 101 'includes/class-ssg-thermal-label.php', 100 102 'includes/class-ssg-notifier.php', 101 103 'includes/class-ssg-ajax.php', … … 110 112 'admin/class-ssg-admin-email-test.php', 111 113 'admin/class-ssg-admin-logs.php', 114 'admin/class-ssg-admin-review.php', 112 115 'public/class-ssg-public.php', 113 116 ); -
softsquare-shipping-gateway-for-woocommerce/trunk/uninstall.php
r3826905 r3837719 24 24 delete_option( 'tcsg_connect_error' ); 25 25 delete_option( 'tcsg_tracking_page_created' ); 26 delete_option( 'tcsg_first_used_at' ); 27 delete_metadata( 'user', 0, 'tcsg_review_request', '', true ); 26 28 delete_option( 'tcsg_last_sync' ); 27 29 delete_option( 'tcsg_financials_since' );
Note:
See TracChangeset
for help on using the changeset viewer.