| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Glossy Grid Template Class |
| 5 |
* |
| 6 |
* Handles rendering of product items in the Glossy Grid layout |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
namespace UltimateStoreKit\Templates; |
| 11 |
|
| 12 |
use UltimateStoreKit\Traits\Global_Widget_Template; |
| 13 |
use UltimateStoreKit\Classes\Utils; |
| 14 |
|
| 15 |
|
| 16 |
class USK_Glossy_Grid_Template |
| 17 |
{ |
| 18 |
use Global_Widget_Template; |
| 19 |
/** |
| 20 |
* Target widget settings |
| 21 |
* |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
protected $target_widget_settings = []; |
| 25 |
protected $target_widget_name = ''; |
| 26 |
/** |
| 27 |
* Constructor |
| 28 |
* |
| 29 |
* @param array $settings Widget settings |
| 30 |
* @param string $widget_name Widget name |
| 31 |
*/ |
| 32 |
public function __construct($settings = [], $widget_name = '') |
| 33 |
{ |
| 34 |
$this->target_widget_settings = $settings; |
| 35 |
$this->target_widget_name = $widget_name; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Render a single product item specifically for the Glossy Grid widget |
| 40 |
* |
| 41 |
* @param WC_Product $product The product object to render |
| 42 |
* @param array $settings The widget settings |
| 43 |
*/ |
| 44 |
public function render_glossy_grid_item($product, $settings) |
| 45 |
{ |
| 46 |
if (!$product) { |
| 47 |
return; |
| 48 |
} |
| 49 |
$product_id = $product->get_id(); |
| 50 |
$rating_count = $product->get_rating_count(); |
| 51 |
$average = $product->get_average_rating(); |
| 52 |
// Get product categories |
| 53 |
$tooltip_position = isset($settings['tooltip_position']) ? $settings['tooltip_position'] : 'right'; |
| 54 |
// get the class based on the widget |
| 55 |
$show_rating = isset($settings['show_rating']) ? $settings['show_rating'] : true; |
| 56 |
$classes = $this->target_widget_name === 'glossy-grid' ? 'usk-item' : 'usk-item swiper-slide'; |
| 57 |
$classes .= $show_rating ? ' usk-have-rating' : ''; |
| 58 |
$title_tags = isset($settings['title_tags']) ? $settings['title_tags'] : 'h3'; |
| 59 |
|
| 60 |
?> |
| 61 |
<div class="<?php echo esc_attr($classes); ?>" data-product-id="<?php echo esc_attr($product_id); ?>"> |
| 62 |
<div class="usk-item-box"> |
| 63 |
<?php $this->render_product_image($product, $settings); ?> |
| 64 |
<div class="usk-content"> |
| 65 |
<div class="usk-content-inner"> |
| 66 |
<?php if (isset($settings['show_title']) ? $settings['show_title'] : true): |
| 67 |
printf( |
| 68 |
'<%1$s class="title"><a href="%2$s" class="usk-title" aria-label="%4$s">%3$s</a></%1$s>', |
| 69 |
esc_attr( Utils::get_valid_html_tag( $title_tags ) ), |
| 70 |
esc_url( $product->get_permalink() ), |
| 71 |
esc_html( $product->get_title() ), |
| 72 |
esc_attr( sprintf( 'View details for %s', $product->get_title() ) ) |
| 73 |
); |
| 74 |
endif; ?> |
| 75 |
<?php if (isset($settings['show_price']) ? $settings['show_price'] : true && $product->get_price_html()): ?> |
| 76 |
<div class="usk-price"> |
| 77 |
<?php $this->print_price_output($product->get_price_html()); ?> |
| 78 |
</div> |
| 79 |
<?php endif; ?> |
| 80 |
<?php if (isset($settings['show_rating']) ? $settings['show_rating'] : true): ?> |
| 81 |
<div class="usk-rating"> |
| 82 |
<?php echo wp_kses_post($this->register_global_template_wc_rating($average, $rating_count)); ?></span> |
| 83 |
</div> |
| 84 |
<?php endif; ?> |
| 85 |
</div> |
| 86 |
</div> |
| 87 |
<div class="usk-shoping"> |
| 88 |
<?php |
| 89 |
$this->register_global_template_add_to_wishlist($tooltip_position, $settings); |
| 90 |
$this->register_global_template_add_to_compare($tooltip_position, $settings); |
| 91 |
$this->register_global_template_quick_view($product->get_id(), $tooltip_position, $settings); |
| 92 |
$this->register_global_template_add_to_cart($tooltip_position, $settings); |
| 93 |
|
| 94 |
?> |
| 95 |
</div> |
| 96 |
</div> |
| 97 |
</div> |
| 98 |
<?php |
| 99 |
} |
| 100 |
/** |
| 101 |
* Render product image with hover effect and action buttons |
| 102 |
* |
| 103 |
* @param WC_Product $product The product object |
| 104 |
*/ |
| 105 |
public function render_product_image($product, $settings) |
| 106 |
{ |
| 107 |
if (!$product) { |
| 108 |
return; |
| 109 |
} |
| 110 |
$gallery_thumbs = $product->get_gallery_image_ids(); |
| 111 |
$product_image = wp_get_attachment_image_url(get_post_thumbnail_id(), isset($settings['image_size']) ? $settings['image_size'] : 'full'); |
| 112 |
if ($gallery_thumbs) { |
| 113 |
foreach ($gallery_thumbs as $key => $gallery_thumb) { |
| 114 |
if ($key == 0): |
| 115 |
$gallery_image_link = wp_get_attachment_image_url($gallery_thumb, isset($settings['image_size']) ? $settings['image_size'] : 'full'); |
| 116 |
endif; |
| 117 |
} |
| 118 |
} else { |
| 119 |
$gallery_image_link = wp_get_attachment_image_url(get_post_thumbnail_id(), isset($settings['image_size']) ? $settings['image_size'] : 'full'); |
| 120 |
} |
| 121 |
?> |
| 122 |
<div class="usk-image"> |
| 123 |
<a href="<?php echo esc_url(get_permalink()); ?>"> |
| 124 |
<img class="img image-default" src="<?php echo esc_url($product_image); ?>" |
| 125 |
alt="<?php echo esc_html(get_the_title()); ?>"> |
| 126 |
<img class="img image-hover" src="<?php echo esc_url($gallery_image_link); ?>" |
| 127 |
alt="<?php echo esc_html(get_the_title()); ?>"> |
| 128 |
</a> |
| 129 |
<div class="usk-badge-label-wrapper"> |
| 130 |
<div class="usk-badge-label-content usk-flex usk-flex-column usk-flex-bottom"> |
| 131 |
<?php $this->register_global_template_badge_label($settings); ?> |
| 132 |
</div> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
<?php |
| 136 |
} |
| 137 |
|
| 138 |
public function print_price_output($output) |
| 139 |
{ |
| 140 |
$tags = [ |
| 141 |
'del' => ['aria-hidden' => []], |
| 142 |
'span' => ['class' => []], |
| 143 |
'bdi' => [], |
| 144 |
'ins' => [], |
| 145 |
]; |
| 146 |
|
| 147 |
if (isset($output)) { |
| 148 |
echo wp_kses($output, $tags); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|