1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
7
|
|
|
* @package Client |
8
|
|
|
* @subpackage Html |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Client\Html\Basket; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract class for all basket HTML clients. |
17
|
|
|
* |
18
|
|
|
* @package Client |
19
|
|
|
* @subpackage Html |
20
|
|
|
*/ |
21
|
|
|
abstract class Base |
22
|
|
|
extends \Aimeos\Client\Html\Base |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Removes all cached basket parts from the cache. |
26
|
|
|
*/ |
27
|
|
|
protected function clearCached() |
28
|
|
|
{ |
29
|
|
|
$session = $this->context()->session(); |
30
|
|
|
|
31
|
|
|
foreach( $session->get( 'aimeos/basket/cache', [] ) as $key => $value ) { |
32
|
|
|
$session->set( $key, null ); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the basket cache entry from the cache if available. |
39
|
|
|
* |
40
|
|
|
* @param string $key Path to the requested cache entry |
41
|
|
|
* @param string|null $default Value returned if requested key isn't found |
42
|
|
|
* @return string|null Value associated to the requested key. If no value for the |
43
|
|
|
* key is found in the cache, the given default value is returned |
44
|
|
|
*/ |
45
|
|
|
protected function getBasketCached( string $key, ?string $default = null ) : ?string |
46
|
|
|
{ |
47
|
|
|
return $this->context()->session()->get( $key, $default ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Adds or overwrite a cache entry for the given key and value. |
53
|
|
|
* |
54
|
|
|
* @param string $key Path the cache entry should be stored in |
55
|
|
|
* @param string|null $value Value stored in the cache for the path |
56
|
|
|
* @return string|null Value |
57
|
|
|
*/ |
58
|
|
|
protected function setBasketCached( string $key, ?string $value = null ) : ?string |
59
|
|
|
{ |
60
|
|
|
$context = $this->context(); |
61
|
|
|
|
62
|
|
|
/** client/html/basket/cache/enable |
63
|
|
|
* Enables or disables caching of the basket content |
64
|
|
|
* |
65
|
|
|
* For performance reasons, the content of the small baskets is cached |
66
|
|
|
* in the session of the customer. The cache is updated each time the |
67
|
|
|
* basket content changes either by adding, deleting or editing products. |
68
|
|
|
* |
69
|
|
|
* To ease development, the caching can be disabled but you shouldn't |
70
|
|
|
* disable it in your production environment! |
71
|
|
|
* |
72
|
|
|
* @param boolean True to enable, false to disable basket content caching |
73
|
|
|
* @since 2014.11 |
74
|
|
|
*/ |
75
|
|
|
if( $context->config()->get( 'client/html/basket/cache/enable', true ) != false ) |
76
|
|
|
{ |
77
|
|
|
$session = $context->session(); |
78
|
|
|
|
79
|
|
|
$cached = $session->get( 'aimeos/basket/cache', [] ) + array( $key => true ); |
80
|
|
|
$session->set( 'aimeos/basket/cache', $cached ); |
81
|
|
|
$session->set( $key, $value ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $value; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|