Skip to content

Commit

Permalink
Implement API status connection check.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Jul 23, 2024
1 parent 90424ba commit c2b7b31
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
29 changes: 20 additions & 9 deletions assets/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,31 @@ a.woocommerce-gzd-input-toggle-trigger {
}
}

.wc-gzd-admin-settings-shipping_provider {
.wc-gzd-shipment-api-connection-status {
padding: .2em .5em;
border-radius: 3px;
display: inline-flex;
white-space: nowrap;
border: 1px solid #CCC;
.wc-gzd-shipment-api-connection-status {
white-space: nowrap;
border: 1px solid #CCC;

&.connection-status-error {
&.page-title-action {
margin-left: 1em;
position: inherit;
}

&.connection-status-error {
border-color: #761919;
color: #761919;
cursor: help;

&:hover {
border-color: #761919;
color: #761919;
}
}

&.connection-status-success {
border-color: #5b841b;
color: #5b841b;

&.connection-status-success {
&:hover {
border-color: #5b841b;
color: #5b841b;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Admin/ProviderSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ protected static function get_breadcrumb_label( $label, $current_section = '' )
if ( ! empty( $provider->get_signup_link() ) ) {
$label = $label . '<a class="page-title-action" href="' . esc_url( $provider->get_signup_link() ) . '" target="_blank">' . _x( 'Not yet a customer?', 'shipments', 'woocommerce-germanized-shipments' ) . '</a>';
}

if ( is_a( $provider, 'Vendidero\Germanized\Shipments\ShippingProvider\Auto' ) ) {
$connection_test_result = $provider->test_connection();

if ( $provider->is_activated() && null !== $connection_test_result ) {
$is_error = is_wp_error( $connection_test_result ) || false === $connection_test_result;
$error_message = is_wp_error( $connection_test_result ) ? $connection_test_result->get_error_message() : '';
$error_message = empty( $error_message ) ? _x( 'Not connected', 'shipments', 'woocommerce-germanized-shipments' ) : $error_message;

$label = $label . '<span class="page-title-action wc-gzd-shipment-api-connection-status ' . ( $is_error ? 'connection-status-error help_tip' : 'connection-status-success' ) . '" data-tip="' . esc_html( $is_error ? $error_message : '' ) . '">' . esc_html( $is_error ? _x( 'Status: Not Connected', 'shipments', 'woocommerce-germanized-shipments' ) : _x( 'Status: Connected', 'shipments', 'woocommerce-germanized-shipments' ) ) . '</span>';
}
}
} elseif ( ! $provider ) {
$label = $label . '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=germanized-shipping_provider&provider=new' ) ) . '" class="page-title-action">' . _x( 'Add provider', 'shipments', 'woocommerce-germanized-shipments' ) . '</a>';

Expand Down
7 changes: 7 additions & 0 deletions src/ShippingProvider/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ public function supports_labels( $label_type, $shipment = false ) {
return true;
}

/**
* @return null|\WP_Error|true
*/
public function test_connection() {
return null;
}

/**
* @param \Vendidero\Germanized\Shipments\Shipment $shipment
*
Expand Down

0 comments on commit c2b7b31

Please sign in to comment.