| 1 |
<?php |
| 2 |
|
| 3 |
namespace ReviewX\Shortcodes\Products; |
| 4 |
|
| 5 |
use ReviewX\Utilities\Auth\Client; |
| 6 |
use ReviewX\Utilities\Helper; |
| 7 |
use ReviewX\WPDrill\Contracts\ShortcodeContract; |
| 8 |
use ReviewX\WPDrill\Facades\View; |
| 9 |
class ReviewShowWIthIdsShortcode implements ShortcodeContract |
| 10 |
{ |
| 11 |
public function render(array $attrs, ?string $content = null) : string |
| 12 |
{ |
| 13 |
$attrs = shortcode_atts(['title' => 'false', 'review_ids' => null], $attrs); |
| 14 |
// Check if both product_id and post_id are provided. |
| 15 |
if (!Client::getSync()) { |
| 16 |
return '<div class="warning">Error: Please complete the synchronization process of ReviewX.</div>'; |
| 17 |
} |
| 18 |
// If review_ids is not provided, return an error. |
| 19 |
if (empty($attrs['review_ids'])) { |
| 20 |
return '<div class="warning">Error: Please provide "review_ids" in the shortcode.</div>'; |
| 21 |
} |
| 22 |
$reviewsIds = $attrs['review_ids']; |
| 23 |
$productIdArray = []; |
| 24 |
// If review_ids is not null, process it |
| 25 |
if ($reviewsIds) { |
| 26 |
// Split review_ids by commas and trim whitespace |
| 27 |
$productIdArray = \array_map('trim', \explode(',', $reviewsIds)); |
| 28 |
// Send multiple product IDs to the JavaScript variable |
| 29 |
$data = $this->reviewsWiseReviewShow($productIdArray); |
| 30 |
// Return the view (empty or simplified, as no review data is required) |
| 31 |
return View::render('storefront/shortcode/reviewShowWIthIds', ['title' => $attrs['title'], 'data' => \json_encode($data)]); |
| 32 |
} |
| 33 |
return ''; |
| 34 |
} |
| 35 |
public function reviewsWiseReviewShow($reviewsIds) : array |
| 36 |
{ |
| 37 |
$attributes = ['ids' => $reviewsIds, 'domain' => ['baseDomain' => Helper::domainSupport(), 'baseRestUrl' => Helper::getRestAPIurl()]]; |
| 38 |
return $attributes; |
| 39 |
} |
| 40 |
} |
| 41 |
|