| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Api\Cookie; |
| 4 |
|
| 5 |
class Cookie |
| 6 |
{ |
| 7 |
private static string $key = 'fct_cart_hash'; |
| 8 |
|
| 9 |
public static function getCartHash(string $default = ''): string |
| 10 |
{ |
| 11 |
$hash = \FluentCart\Framework\Http\Cookie::get(static::getCartHashKey(), $default); |
| 12 |
return trim($hash); |
| 13 |
} |
| 14 |
|
| 15 |
public static function getCartHashKey(): string |
| 16 |
{ |
| 17 |
return self::$key; |
| 18 |
} |
| 19 |
|
| 20 |
public static function setCartHash(string $cartHash): void |
| 21 |
{ |
| 22 |
$expireTime = apply_filters('fluent_cart/cart_cookie_minutes', time() + 24 * 60 * 30); |
| 23 |
setcookie(static::getCartHashKey(), $cartHash, [ |
| 24 |
'expires' => $expireTime, |
| 25 |
'path' => COOKIEPATH, |
| 26 |
'domain' => COOKIE_DOMAIN, |
| 27 |
'secure' => is_ssl(), |
| 28 |
'httponly' => false, |
| 29 |
'samesite' => 'Lax', |
| 30 |
]); |
| 31 |
} |
| 32 |
|
| 33 |
public static function deleteCartHash(): void |
| 34 |
{ |
| 35 |
\FluentCart\Framework\Http\Cookie::delete( |
| 36 |
static::getCartHashKey(), |
| 37 |
COOKIEPATH, |
| 38 |
COOKIE_DOMAIN |
| 39 |
); |
| 40 |
//setcookie(static::getCartHashKey(), false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN); |
| 41 |
} |
| 42 |
} |
| 43 |
|