protected function get_flat_rate_packages_groups() { $service_id = 'usps'; //TODO: remove hardcoding $predefined_packages_schema = $this->service_schemas_store->get_predefined_packages_schema_for_service($service_id); $groups = array(); foreach ($predefined_packages_schema as $group_id => $group) { $groups[$group_id] = $group->title; } return $groups; }
public function get_package_lookup_for_service($service_id) { $lookup = array(); $custom_packages = $this->get_packages(); foreach ($custom_packages as $custom_package) { $lookup[$custom_package['name']] = $custom_package; } $predefined_packages_schema = $this->service_schemas_store->get_predefined_packages_schema_for_service($service_id); if (is_null($predefined_packages_schema)) { return $lookup; } foreach ($predefined_packages_schema as $group) { foreach ($group->definitions as $predefined) { $lookup[$predefined->id] = (array) $predefined; } } return $lookup; }
protected function get_health_items() { $health_items = array(); // WooCommerce // Only one of the following should present // Check that WooCommerce is at least 2.6 or higher (feature-plugin only) // Check that WooCommerce base_country is set $base_country = WC()->countries->get_base_country(); if (version_compare(WC()->version, WOOCOMMERCE_CONNECT_MINIMUM_WOOCOMMERCE_VERSION, "<")) { $health_item = $this->build_indicator('woocommerce_indicator', 'notice', 'indicator-error', sprintf(__('WooCommerce %s or higher is required (You are running %s)', 'connectforwoocommerce'), WOOCOMMERCE_CONNECT_MINIMUM_WOOCOMMERCE_VERSION, WC()->version), ''); } else { if (empty($base_country)) { $health_item = $this->build_indicator('woocommerce_indicator', 'notice', 'indicator-error', __('Please set Base Location in WooCommerce Settings > General', 'connectforwoocommerce'), ''); } else { $health_item = $this->build_indicator('woocommerce_indicator', 'checkmark-circle', 'indicator-success', sprintf(__('WooCommerce %s is configured correctly', 'connectforwoocommerce'), WC()->version), ''); } } $health_items[] = (object) array('key' => 'woocommerce_health_items', 'title' => __('WooCommerce', 'connectforwoocommerce'), 'type' => 'indicators', 'items' => array('woocommerce_indicator' => $health_item)); // Jetpack // Only one of the following should present // Check that Jetpack is active // Check that Jetpack is connected include_once ABSPATH . 'wp-admin/includes/plugin.php'; // required for is_plugin_active if (method_exists('Jetpack', 'is_development_mode') && method_exists('Jetpack', 'is_active')) { $is_connected = Jetpack::is_development_mode() ? true : Jetpack::is_active(); } else { $is_connected = false; } if (!is_plugin_active('jetpack/jetpack.php')) { $health_item = $this->build_indicator('jetpack_indicator', 'notice', 'indicator-error', sprintf(__('Please install and activate the Jetpack plugin, version %s or higher', 'connectforwoocommerce'), WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION), ''); } else { if (version_compare(JETPACK__VERSION, WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION, "<")) { $health_item = $this->build_indicator('jetpack_indicator', 'notice', 'indicator-error', sprintf(__('Jetpack %s or higher is required (You are running %s)', 'connectforwoocommerce'), WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION, JETPACK__VERSION), ''); } else { if (!$is_connected) { $health_item = $this->build_indicator('jetpack_indicator', 'notice', 'indicator-error', __('Jetpack is not connected to WordPress.com. Make sure the Jetpack plugin is installed, activated, and connected.', 'connectforwoocommerce'), ''); } else { if (Jetpack::is_staging_site()) { $health_item = $this->build_indicator('jetpack_indicator', 'notice', 'indicator-warning', __('This is a Jetpack staging site', 'connectforwoocommerce'), ''); } else { $health_item = $this->build_indicator('jetpack_indicator', 'checkmark-circle', 'indicator-success', sprintf(__('Jetpack %s is connected and working correctly', 'connectforwoocommerce'), JETPACK__VERSION), ''); } } } } $health_items[] = (object) array('key' => 'jetpack_health_items', 'title' => __('Jetpack', 'connectforwoocommerce'), 'type' => 'indicators', 'items' => array('jetpack_indicator' => $health_item)); // Lastly, do the Connect for WooCommerce health check // Check that we have schema // Check that we are able to talk to the Connect for WooCommerce server $schemas = $this->service_schemas_store->get_service_schemas(); $last_fetch_timestamp = $this->service_schemas_store->get_last_fetch_timestamp(); if (!is_null($last_fetch_timestamp)) { $last_fetch_timestamp_formatted = sprintf(_x('Last updated %s ago', '%s = human-readable time difference', 'connectforwoocommerce'), human_time_diff($last_fetch_timestamp)); } else { $last_fetch_timestamp = ''; } if (is_null($schemas)) { $health_item = $this->build_indicator('wcc_indicator', 'notice', 'indicator-error', __('No service data available', 'connectforwoocommerce'), ''); } else { if (is_null($last_fetch_timestamp)) { $health_item = $this->build_indicator('wcc_indicator', 'notice', 'indicator-warning', __('Service data was found, but may be out of date', 'connectforwoocommerce'), ''); } else { if ($last_fetch_timestamp < time() - WOOCOMMERCE_CONNECT_SCHEMA_AGE_ERROR_THRESHOLD) { $health_item = $this->build_indicator('wcc_indicator', 'notice', 'indicator-error', __('Service data was found, but is more than three days old', 'connectforwoocommerce'), $last_fetch_timestamp_formatted); } else { if ($last_fetch_timestamp < time() - WOOCOMMERCE_CONNECT_SCHEMA_AGE_WARNING_THRESHOLD) { $health_item = $this->build_indicator('wcc_indicator', 'notice', 'indicator-warning', __('Service data was found, but is more than one day old', 'connectforwoocommerce'), $last_fetch_timestamp_formatted); } else { $health_item = $this->build_indicator('wcc_indicator', 'checkmark-circle', 'indicator-success', __('Service data is up-to-date', 'connectforwoocommerce'), $last_fetch_timestamp_formatted); } } } } $health_items[] = (object) array('key' => 'wcc_health_items', 'title' => __('Connect for WooCommerce Service Data', 'connectforwoocommerce'), 'type' => 'indicators', 'items' => array('wcc_indicator' => $health_item)); return $health_items; }
public function get_packages_form_schema() { return array('custom' => $this->service_schemas_store->get_packages_schema(), 'predefined' => $this->service_schemas_store->get_predefined_packages_schema()); }