| 1 |
<?php |
| 2 |
namespace FluentCart\App\Services\Renderer; |
| 3 |
|
| 4 |
use FluentCart\Api\StoreSettings; |
| 5 |
use FluentCart\Api\Resource\ShopResource; |
| 6 |
use FluentCart\App\Models\Product; |
| 7 |
|
| 8 |
class ProductModalRenderer |
| 9 |
{ |
| 10 |
protected $product; |
| 11 |
protected $config = []; |
| 12 |
protected $storeSettings; |
| 13 |
|
| 14 |
public function __construct(Product $product, $config = []) |
| 15 |
{ |
| 16 |
$this->product = $product; |
| 17 |
$this->config = $config; |
| 18 |
$this->storeSettings = new StoreSettings(); |
| 19 |
} |
| 20 |
|
| 21 |
public function render() |
| 22 |
{ |
| 23 |
?> |
| 24 |
<div |
| 25 |
class="fct-product-modal" |
| 26 |
data-fluent-cart-shop-app-single-product-modal |
| 27 |
role="dialog" |
| 28 |
aria-modal="true" |
| 29 |
aria-label="<?php esc_attr($this->product->post_title); ?>" |
| 30 |
> |
| 31 |
<div |
| 32 |
data-fluent-cart-shop-app-single-product-modal-overlay |
| 33 |
class="fct-product-modal-overlay" |
| 34 |
role="presentation" |
| 35 |
aria-hidden="true" |
| 36 |
> |
| 37 |
</div> |
| 38 |
<div class="fct-product-modal-body"> |
| 39 |
<button |
| 40 |
class="fct-product-modal-close" |
| 41 |
data-fluent-cart-shop-app-single-product-modal-close |
| 42 |
type="button" |
| 43 |
aria-label="<?php esc_attr_e('Close product modal', 'fluent-cart'); ?>" |
| 44 |
> |
| 45 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 46 |
<path d="M12.8337 1.16663L1.16699 12.8333M1.16699 1.16663L12.8337 12.8333" stroke="#2F3448" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> |
| 47 |
</svg> |
| 48 |
</button> |
| 49 |
|
| 50 |
<?php |
| 51 |
(new ProductRenderer($this->product, [ |
| 52 |
'view_type' => $this->storeSettings->get('variation_view', 'both'), |
| 53 |
'column_type' => $this->storeSettings->get('variation_columns', 'masonry') |
| 54 |
]))->render(); |
| 55 |
|
| 56 |
$this->renderRelevantProducts(); |
| 57 |
?> |
| 58 |
</div> |
| 59 |
</div> |
| 60 |
<?php |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Related products below the modal's product, when the store asks for |
| 66 |
* them. Off by default, so a quick view stays a quick view unless the |
| 67 |
* setting is turned on. |
| 68 |
* |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
protected function renderRelevantProducts() |
| 72 |
{ |
| 73 |
$showRelevant = $this->storeSettings->get('show_relevant_product_in_modal') == 'yes'; |
| 74 |
$showRelevant = apply_filters( |
| 75 |
'fluent_cart/product_modal/show_relevant_products', |
| 76 |
$showRelevant, |
| 77 |
$this->product->ID |
| 78 |
); |
| 79 |
|
| 80 |
if (!$showRelevant) { |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
$products = ShopResource::getSimilarProducts($this->product->ID, false); |
| 85 |
|
| 86 |
if (empty($products)) { |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
(new ProductListRenderer( |
| 91 |
$products, |
| 92 |
__('Related Products', 'fluent-cart'), |
| 93 |
'fct-similar-product-list-container', |
| 94 |
['rating_context' => 'relevant'] |
| 95 |
))->render(); |
| 96 |
} |
| 97 |
} |
| 98 |
|