PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Handlers / CartCookieHandler.php

CartCookieHandler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.3, at app/Hooks/Handlers/CartCookieHandler.php

41 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers;
4
5 use FluentCart\Api\Hasher\Hash;
6 use FluentCart\App\App;
7
8 class CartCookieHandler
9 {
10 public static function handle()
11 {
12 $app = App::getInstance();
13 //Set up the cookie before any header info is sent to a client
14 $app->addAction('init', function () use ($app) {
15
16 if (App::doingRestRequest()) {
17 return;
18 }
19
20 $cartCookie = \FluentCart\Api\Cookie\Cookie::getCartHash();
21 if (!$cartCookie) {
22 \FluentCart\Api\Cookie\Cookie::setCartHash(
23 md5(time() . wp_generate_uuid4())
24 );
25 }
26 });
27
28
29 add_filter('rest_request_before_callbacks', function ($response, $handler, $request) {
30 // Only set cookie if not already present
31 $cartCookie = \FluentCart\Api\Cookie\Cookie::getCartHash();
32 if (!$cartCookie) {
33 \FluentCart\Api\Cookie\Cookie::setCartHash(
34 md5(time() . wp_generate_uuid4())
35 );
36 }
37 // Return null to let the normal REST flow continue
38 return null;
39 }, 10, 3);
40 }
41 }