| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace FluentCart\App\Services\Renderer; |
| 3 | 3 | |
| 4 | 4 | use FluentCart\Api\StoreSettings; |
| 5 | +use FluentCart\Api\Resource\ShopResource; | |
| 5 | 6 | use FluentCart\App\Models\Product; |
| 6 | 7 | |
| 7 | 8 | class ProductModalRenderer |
| 8 | 9 | { |
| @@ -45,13 +46,15 @@ | ||
| 45 | 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"/> |
| 46 | 47 | </svg> |
| 47 | 48 | </button> |
| 48 | 49 | |
| 49 | - <?php | |
| 50 | + <?php | |
| 50 | 51 | (new ProductRenderer($this->product, [ |
| 51 | 52 | 'view_type' => $this->storeSettings->get('variation_view', 'both'), |
| 52 | 53 | 'column_type' => $this->storeSettings->get('variation_columns', 'masonry') |
| 53 | 54 | ]))->render(); |
| 55 | + | |
| 56 | + $this->renderRelevantProducts(); | |
| 54 | 57 | ?> |
| 55 | 58 | </div> |
| 56 | 59 | </div> |
| 57 | 60 | <?php |
| @@ -57,5 +60,38 @@ | ||
| 57 | 60 | <?php |
| 58 | 61 | |
| 59 | 62 | } |
| 60 | 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 | + } | |
| 61 | 97 | } |