] * : table (missing products) or json (whole result). * --- * default: table * --- * * ## EXAMPLES * * wp proofpass scan * * @param array $args Positional. * @param array $assoc_args Named. */ public function scan( $args, $assoc_args ) { if ( ! class_exists( 'WooCommerce' ) ) { WP_CLI::error( __( 'WooCommerce is not active.', 'proofpass' ) ); } $r = ProofPass_Scan::scan(); if ( empty( $r['ok'] ) ) { WP_CLI::error( isset( $r['error'] ) ? (string) $r['error'] : 'scan failed' ); } if ( 'json' === WP_CLI\Utils\get_flag_value( $assoc_args, 'format', 'table' ) ) { WP_CLI::log( (string) wp_json_encode( $r ) ); return; } $rows = array(); foreach ( $r['rows'] as $row ) { $rows[] = array( 'id' => $row['wc'], 'name' => $row['name'], 'sku' => $row['sku'], 'gtin' => $row['gtin'], 'matched' => $row['matched'] ? 'yes' : 'no', 'gaps' => implode( ',', $row['gaps'] ), ); } if ( $rows ) { WP_CLI\Utils\format_items( 'table', $rows, array( 'id', 'name', 'sku', 'gtin', 'matched', 'gaps' ) ); } /* translators: 1: scanned, 2: found, 3: not found, 4: with gaps */ WP_CLI::success( sprintf( __( '%1$d scanned, %2$d found, %3$d not in ProofPass, %4$d with missing documents.', 'proofpass' ), $r['totals']['items'], $r['totals']['matched'], $r['totals']['unmatched'] - $r['totals']['mapped'], $r['totals']['withGaps'] ) ); if ( ! empty( $r['over'] ) ) { /* translators: 1: plan name, 2: product limit, 3: products needed */ WP_CLI::warning( sprintf( __( 'Your ProofPass plan %1$s holds %2$d products; the whole catalogue needs %3$d.', 'proofpass' ), $r['plan'], $r['limit'], $r['needed'] ) . ( '' !== $r['upgrade'] ? ' ' . $r['upgrade'] : '' ) ); } } /** * Map products the scan did not find, by name. * * ## OPTIONS * * [--min=] * : Minimum match score (0–100). * --- * default: 80 * --- * * [--apply] * : Save the suggestions as "ProofPass product". Without it, only list them. * * ## EXAMPLES * * wp proofpass map * wp proofpass map --min=90 --apply * * @param array $args Positional. * @param array $assoc_args Named. */ public function map( $args, $assoc_args ) { if ( ! class_exists( 'WooCommerce' ) ) { WP_CLI::error( __( 'WooCommerce is not active.', 'proofpass' ) ); } if ( '' === ProofPass_Settings::api_key() ) { WP_CLI::error( __( 'Suggestions by name need an API key with the permission "Lesen" (plans from Start). The scan key of the Basis plan finds products by GTIN and SKU only.', 'proofpass' ) ); } $min = max( 0, min( 100, (int) WP_CLI\Utils\get_flag_value( $assoc_args, 'min', 80 ) ) ); $apply = (bool) WP_CLI\Utils\get_flag_value( $assoc_args, 'apply', false ); $rows = ProofPass_Mapping::auto_map( $min, $apply ); $out = array(); foreach ( $rows as $r ) { $out[] = array( 'id' => $r[0], 'name' => $r[1], 'proofpass' => $r[2] . ' ' . $r[3], 'score' => $r[4], 'saved' => $r[5] ? 'yes' : 'no', ); } if ( $out ) { WP_CLI\Utils\format_items( 'table', $out, array( 'id', 'name', 'proofpass', 'score', 'saved' ) ); } /* translators: %d: number of products */ WP_CLI::success( sprintf( __( '%d suggestions.', 'proofpass' ), count( $rows ) ) . ( $apply || ! $rows ? '' : ' --apply' ) ); } /** * Cache commands. * * ## OPTIONS * * * : flush * * ## EXAMPLES * * wp proofpass cache flush * * @param array $args Positional. * @param array $assoc_args Named. */ public function cache( $args, $assoc_args ) { if ( ! isset( $args[0] ) || 'flush' !== $args[0] ) { WP_CLI::error( 'usage: wp proofpass cache flush' ); } ProofPass_API::clear_cache(); WP_CLI::success( __( 'The cache is empty. Product pages ask ProofPass again on their next view.', 'proofpass' ) ); } }