| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\Templating\Bricks; |
| 4 |
|
| 5 |
use Bricks\Frontend; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class BricksHelper |
| 9 |
{ |
| 10 |
|
| 11 |
static public $forcedPost = null; |
| 12 |
|
| 13 |
public static function getFormCurrentPost() |
| 14 |
{ |
| 15 |
return self::$forcedPost; |
| 16 |
} |
| 17 |
|
| 18 |
public static function setFormCurrentPost($post) |
| 19 |
{ |
| 20 |
self::$forcedPost = $post; |
| 21 |
} |
| 22 |
|
| 23 |
public static function getCategoriesOptions() |
| 24 |
{ |
| 25 |
$categories = get_terms(array( |
| 26 |
'taxonomy' => 'product-categories', |
| 27 |
'hide_empty' => false, |
| 28 |
'orderby' => 'name' |
| 29 |
)); |
| 30 |
|
| 31 |
$options = []; |
| 32 |
if (!is_wp_error($categories) && !empty($categories)) { |
| 33 |
foreach ($categories as $category) { |
| 34 |
$options[$category->term_id] = $category->name; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
return $options; |
| 39 |
} |
| 40 |
|
| 41 |
public static function renderCollectionCard($settings, $post, $post_index = 1, $uid = '') |
| 42 |
{ |
| 43 |
$content = Frontend::get_content_wrapper($settings, Arr::get($settings, 'fields', []), $post); |
| 44 |
|
| 45 |
if ($post_index === 1) { |
| 46 |
echo "<div data-fluent-client-id='" . esc_attr($uid) . "' data-template-provider='bricks' data-fct-product-card class='fct-product-card repeater-item'>"; |
| 47 |
} else { |
| 48 |
echo "<div data-fct-product-card class='fct-product-card repeater-item'>"; |
| 49 |
} |
| 50 |
|
| 51 |
$linkedProduct = isset($settings['linkProduct']) ? $settings['linkProduct'] : false; |
| 52 |
|
| 53 |
if ($linkedProduct && strpos($content, '<a ') === false) { |
| 54 |
echo '<a href="' . esc_attr(get_the_permalink($post)) . '">'; |
| 55 |
} |
| 56 |
|
| 57 |
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 58 |
|
| 59 |
if ($linkedProduct && strpos($content, '<a ') === false) { |
| 60 |
echo '</a>'; |
| 61 |
} |
| 62 |
|
| 63 |
echo '</div>'; |
| 64 |
} |
| 65 |
} |
| 66 |
|