| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers\ShortCodes; |
| 4 |
|
| 5 |
|
| 6 |
use FluentCart\Api\StoreSettings; |
| 7 |
use FluentCart\App\App; |
| 8 |
use FluentCart\App\Helpers\CartCheckoutHelper; |
| 9 |
use FluentCart\App\Helpers\Helper; |
| 10 |
|
| 11 |
|
| 12 |
class CustomerLoginHandler extends ShortCode |
| 13 |
{ |
| 14 |
const SHORT_CODE = 'fluent_cart_login_form'; |
| 15 |
protected static string $shortCodeName = 'fluent_cart_login_form'; |
| 16 |
|
| 17 |
|
| 18 |
public static function register() |
| 19 |
{ |
| 20 |
parent::register(); |
| 21 |
|
| 22 |
add_action('wp_enqueue_scripts', function () { |
| 23 |
if (App::request()->get('action') === 'elementor') { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
if (is_page() && is_main_query()) { |
| 28 |
$page_id = get_queried_object_id(); |
| 29 |
$storePageId = null; |
| 30 |
if ($page_id == $storePageId) { |
| 31 |
(new static())->enqueueStyles(); |
| 32 |
} |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
if (has_shortcode(get_the_content(), static::SHORT_CODE) || has_block('fluent-cart/login-form')) { |
| 37 |
(new static())->enqueueStyles(); |
| 38 |
} |
| 39 |
}, 10); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
public function getScripts(): array |
| 44 |
{ |
| 45 |
return [ |
| 46 |
[ |
| 47 |
'source' => 'public/checkout/login.js', |
| 48 |
'dependencies' => [], |
| 49 |
'inFooter' => true |
| 50 |
] |
| 51 |
]; |
| 52 |
} |
| 53 |
|
| 54 |
public function getStyles(): array |
| 55 |
{ |
| 56 |
return [ |
| 57 |
[ |
| 58 |
'source' => 'public/checkout/style/login.scss', |
| 59 |
] |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
public function localizeData(): array |
| 64 |
{ |
| 65 |
return [ |
| 66 |
'fluentcart_checkout_info' => [ |
| 67 |
'rest' => Helper::getRestInfo(), |
| 68 |
] |
| 69 |
]; |
| 70 |
} |
| 71 |
|
| 72 |
public function viewData(): ?array |
| 73 |
{ |
| 74 |
return [ |
| 75 |
'checkout' => CartCheckoutHelper::make() |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
public function render(?array $viewData = null) |
| 80 |
{ |
| 81 |
ob_start(); |
| 82 |
do_action('fluent_cart/views/checkout_page_login_form', $viewData); |
| 83 |
return ob_get_clean(); |
| 84 |
} |
| 85 |
} |
| 86 |
|