-
Notifications
You must be signed in to change notification settings - Fork 21
/
SessionStorage.php
48 lines (43 loc) · 1010 Bytes
/
SessionStorage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @link https://www.github.com/hscstudio/yii2-cart
* @copyright Copyright (c) 2016 HafidMukhlasin.com
* @license http://www.yiiframework.com/license/
*/
namespace hscstudio\cart;
/**
* SessionStorage is extended from Storage Class
*
* It's specialty for handling read and write cart data into session
*
* Usage:
* Configuration in block component look like this
* 'cart' => [
* 'class' => 'hscstudio\cart\Cart',
* 'storage' => [
* 'class' => 'hscstudio\cart\SessionStorage',
* ]
* ],
*
* @author Hafid Mukhlasin <hafidmukhlasin@gmail.com>
* @since 1.0
*
*/
class SessionStorage extends Storage
{
public function read(Cart $cart)
{
$session = \Yii::$app->session;
if (isset($session[$cart->id]))
$this->unserialize($session[$cart->id],$cart);
}
public function write(Cart $cart)
{
$session = \Yii::$app->session;
$session[$cart->id] = $this->serialize($cart);
}
public function lock($drop, Cart $cart)
{
// not implemented, only for db
}
}