Created
January 17, 2016 15:50
-
-
Save hscstudio/119753a5ac9008778c36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @link https://www.github.com/hscstudio/yii2-cart | |
* @copyright Copyright (c) 2016 HafidMukhlasin.com | |
* @license http://www.yiiframework.com/license/ | |
*/ | |
namespace hscstudio\cart; | |
use Yii; | |
use yii\base\BootstrapInterface; | |
use yii\di\Instance; | |
use yii\web\User; | |
use yii\base\Event; | |
/** | |
* Bootstrap class for checking sync between two storages. | |
* | |
* @author Hafid Mukhlasin <[email protected]> | |
* @since 1.0 | |
* | |
*/ | |
<?php | |
class CartBootstrap implements BootstrapInterface | |
{ | |
/** | |
* @param \yii\base\Application $app | |
*/ | |
public function bootstrap($app) | |
{ | |
Event::on(User::className(), User::EVENT_AFTER_LOGIN, function () { | |
$storage = Instance::ensure(\Yii::$app->cart->storage, MultipleStorage::className()); | |
if (get_class($storage)=='hscstudio\cart\MultipleStorage'){ | |
$cart = Instance::ensure(\Yii::$app->cart, Cart::className()); | |
$storage->sync($cart); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment