Review_Cache::update_cache( int $product_id )

Summary

No summary available.

Parameters

$product_id

(int) (Required)


Return

(void)


Source

File: src/BigCommerce/Reviews/Review_Cache.php

	public function update_cache( $product_id ) {
		$post_ids = $this->get_matching_imported_products( $product_id );
		if ( empty( $post_ids ) ) {
			return;
		}

		/**
		 * Filter the number of product reviews to cache
		 *
		 * @param int $count      The max number of reviews that will be cached
		 * @param int $product_id The BigCommerce ID of the product;
		 */
		$count = apply_filters( 'bigcommerce/reviews/cache/per_page', 12, $product_id );
		$data  = $this->fetcher->fetch( $product_id, 1, $count );
		$total = $data['total'];

		$reviews = array_map( function ( ProductReview $review ) use ( $product_id ) {
			$builder = new Review_Builder( $review );

			return $builder->build_review_array( $product_id );
		}, $data['reviews'] );

		foreach ( $post_ids as $p ) {
			update_post_meta( $p, Product::REVIEW_CACHE, $reviews );
			update_post_meta( $p, Product::REVIEWS_APPROVED_META_KEY, $total );
		}
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.