Skip to content

Instantly share code, notes, and snippets.

@andku83
Created December 18, 2018 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andku83/636d68a2b2f87e6fdc94f85119764f85 to your computer and use it in GitHub Desktop.
Save andku83/636d68a2b2f87e6fdc94f85119764f85 to your computer and use it in GitHub Desktop.
<?php
namespace frontend\modules\user\controllers;
use common\base\MultiModel;
use frontend\models\search\OrderSearch;
use frontend\modules\user\models\AccountForm;
use frontend\modules\user\models\SignupOauthForm;
use Yii;
use yii\authclient\clients\Facebook;
use yii\authclient\clients\Google;
use yii\helpers\Url;
use yii\web\Controller;
use common\models\User;
use common\models\UserToken;
use frontend\modules\user\models\LoginForm;
use frontend\modules\user\models\PasswordResetRequestForm;
use frontend\modules\user\models\ResetPasswordForm;
use frontend\modules\user\models\SignupForm;
use yii\base\Exception;
use yii\base\InvalidParamException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;
/**
* Class UserController
* @package frontend\modules\user\controllers
*/
class UserController extends Controller
{
...
/**
* @return array|string|Response
*/
public function actionLogin()
{
$request = Yii::$app->request;
$model = new LoginForm();
if ($request->isAjax) {
$model->setFormName('-modal');
}
$oldCartItems = Yii::$app->cart->items;
if ($request->isPost
&& ($model->load($request->post()) || $model->load($request->post(), $model->formName() . '-modal'))
&& $model->login()) {
$this->syncCartItems($oldCartItems);
return $this->redirect($request->referrer);
}
if ($request->isAjax) {
return $this->renderAjax('login', ['model' => $model]);
}
return $this->render('login', ['model' => $model]);
}
...
/**
* @param $oldCartItems
*/
protected function syncCartItems($oldCartItems){
$cart = Yii::$app->cart;
if($oldCartItems){
$cart->storage = 'hscstudio\cart\DatabaseStorage';
$cart->init();
foreach ($oldCartItems as $item){
$cart->create($item, $item->getQuantity());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment