plugin = $plugin; } /** * The select value that stands for a rule ("skip", "fixed", "ask", "field:brand", "attr:pa_color"). * * @param AttributeRule $rule Rule. */ public static function source_value( AttributeRule $rule ): string { switch ( $rule->type ) { case AttributeRule::FIELD: return 'field:' . $rule->key; case AttributeRule::WC_ATTRIBUTE: return 'attr:' . $rule->key; case AttributeRule::FIXED: return 'fixed'; case AttributeRule::ASK: return 'ask'; } return 'skip'; } /** * The rule type and key for a select value. * * @param string $value Select value. * @return array{type:string, key:string} */ public static function parse_source( string $value ): array { if ( 0 === strpos( $value, 'field:' ) && in_array( substr( $value, 6 ), AttributeRule::FIELDS, true ) ) { return array( 'type' => AttributeRule::FIELD, 'key' => substr( $value, 6 ), ); } if ( 0 === strpos( $value, 'attr:' ) && strlen( $value ) > 5 ) { return array( 'type' => AttributeRule::WC_ATTRIBUTE, 'key' => substr( $value, 5 ), ); } if ( 'fixed' === $value || 'ask' === $value ) { return array( 'type' => $value, 'key' => '', ); } return array( 'type' => AttributeRule::SKIP, 'key' => '', ); } /** * Renders the page. */ public function render(): void { if ( ! current_user_can( Plugin::CAPABILITY ) ) { return; } $channel = $this->plugin->requested_channel(); $channel_label = $channel->label(); $map_cats = array_values( array_unique( array_map( 'intval', array_values( $this->plugin->category_map( $channel->id() )->all() ) ) ) ); sort( $map_cats ); $tree = $channel->taxonomy()->index(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a read-only choice of what to show. $wanted = isset( $_GET['remote_cat'] ) ? absint( $_GET['remote_cat'] ) : 0; $cat = in_array( $wanted, $map_cats, true ) ? $wanted : ( $map_cats ? $map_cats[0] : 0 ); ?>
' . esc_html( Text::channel( __( 'The attributes of this category could not be read from {channel}. Connect the {channel} application (Connect page) and reload.', 'tidelist' ), $channel_label ) ) . '
'; return; } usort( $definitions, static function ( $a, $b ) { return (int) ! empty( $b['validation']['required'] ) <=> (int) ! empty( $a['validation']['required'] ); } ); $values = new ProductValues(); $wc_attrs = $values->attribute_labels(); $saved = $this->plugin->attribute_map( $channel->id() )->rules_for( $cat ); ?>