Submit
Path:
~
/
home
/
getwphos
/
public_html
/
perfumehousedhaka
/
wp-content
/
plugins
/
woocommerce
/
src
/
StoreApi
/
Schemas
/
V1
/
File Content:
ProductBrandSchema.php
<?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; } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
AI
---
0755
Agentic
---
0755
AbstractAddressSchema.php
10838 bytes
0644
AbstractSchema.php
13143 bytes
0644
BatchSchema.php
427 bytes
0644
BillingAddressSchema.php
4569 bytes
0644
CartCouponSchema.php
3047 bytes
0644
CartExtensionsSchema.php
2259 bytes
0644
CartFeeSchema.php
2169 bytes
0644
CartItemSchema.php
7734 bytes
0644
CartSchema.php
16203 bytes
0644
CartShippingRateSchema.php
11642 bytes
0644
CheckoutOrderSchema.php
752 bytes
0644
CheckoutSchema.php
15407 bytes
0644
ErrorSchema.php
1151 bytes
0644
ImageAttachmentSchema.php
2616 bytes
0644
ItemSchema.php
11538 bytes
0644
OrderCouponSchema.php
2468 bytes
0644
OrderFeeSchema.php
2253 bytes
0644
OrderItemSchema.php
4776 bytes
0644
OrderSchema.php
13047 bytes
0644
PatternsSchema.php
673 bytes
0644
ProductAttributeSchema.php
2555 bytes
0644
ProductBrandSchema.php
3575 bytes
0644
ProductCategorySchema.php
3579 bytes
0644
ProductCollectionDataSchema.php
5066 bytes
0644
ProductReviewSchema.php
6269 bytes
0644
ProductSchema.php
33579 bytes
0644
ShippingAddressSchema.php
2906 bytes
0644
TermSchema.php
2205 bytes
0644
N4ST4R_ID | Naxtarrr