From 7c514320101ae98e0f10c73c20eacdaaa482e77c Mon Sep 17 00:00:00 2001 From: Yarik Date: Mon, 12 Jun 2017 14:00:43 +0300 Subject: [PATCH] Share basket --- common/mail/shareBasket.php | 9 +++++++++ composer.json | 3 ++- composer.lock | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------ frontend/controllers/SiteController.php | 41 +++++++++++++++++++++++++++++++++++++---- frontend/models/ShareBasket.php | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/checkout/index.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- frontend/views/layouts/_basket_modal.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/web/js/script.js | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------- 8 files changed, 555 insertions(+), 158 deletions(-) create mode 100644 common/mail/shareBasket.php create mode 100644 frontend/models/ShareBasket.php diff --git a/common/mail/shareBasket.php b/common/mail/shareBasket.php new file mode 100644 index 0000000..7e27b24 --- /dev/null +++ b/common/mail/shareBasket.php @@ -0,0 +1,9 @@ +=5.0.0" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "*", + "phpunit/phpunit": "4.0.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "class.phpmailer.php", + "class.pop3.php", + "class.smtp.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "name": "Andy Prevost", + "email": "codeworxtech@users.sourceforge.net" + }, + { + "name": "Brent R. Matzelle" + } + ], + "description": "PHPMailer is a full-featured email creation and transfer class for PHP", + "time": "2014-05-14T07:04:18+00:00" + }, + { "name": "phpoffice/phpexcel", "version": "1.8.1", "source": { @@ -2851,29 +2898,34 @@ }, { "name": "tubalmartin/cssmin", - "version": "v2.4.8-p10", + "version": "v4.1.0", "source": { "type": "git", "url": "https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port.git", - "reference": "9c640e5d2d6fe1eac2167ff138b8b0ce39475d03" + "reference": "1c7ae93cf6b392d4dae5c4ae18979918413af16e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tubalmartin/YUI-CSS-compressor-PHP-port/zipball/9c640e5d2d6fe1eac2167ff138b8b0ce39475d03", - "reference": "9c640e5d2d6fe1eac2167ff138b8b0ce39475d03", + "url": "https://api.github.com/repos/tubalmartin/YUI-CSS-compressor-PHP-port/zipball/1c7ae93cf6b392d4dae5c4ae18979918413af16e", + "reference": "1c7ae93cf6b392d4dae5c4ae18979918413af16e", "shasum": "" }, "require": { - "php": ">=5.0.0" + "ext-pcre": "*", + "php": ">=5.3.2" }, "require-dev": { - "cogpowered/finediff": "0.3.*" + "cogpowered/finediff": "0.3.*", + "phpunit/phpunit": "4.8.*" }, + "bin": [ + "cssmin" + ], "type": "library", "autoload": { - "classmap": [ - "cssmin.php" - ] + "psr-4": { + "tubalmartin\\CssMin\\": "src" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2895,7 +2947,7 @@ "minify", "yui" ], - "time": "2017-04-04T14:38:03+00:00" + "time": "2017-05-16T13:45:26+00:00" }, { "name": "yii2tech/filedb", @@ -3300,6 +3352,50 @@ "yii2" ], "time": "2017-05-22T11:24:30+00:00" + }, + { + "name": "zyx/zyx-phpmailer", + "version": "0.9.2", + "source": { + "type": "git", + "url": "https://github.com/SDKiller/zyx-phpmailer.git", + "reference": "2032706c35a345f875c4acf310600098a37ca469" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SDKiller/zyx-phpmailer/zipball/2032706c35a345f875c4acf310600098a37ca469", + "reference": "2032706c35a345f875c4acf310600098a37ca469", + "shasum": "" + }, + "require": { + "phpmailer/phpmailer": "v5.2.8", + "yiisoft/yii2": "*" + }, + "type": "yii2-extension", + "autoload": { + "psr-4": { + "zyx\\phpmailer\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Serge Postrash aka SDKiller", + "email": "jexy.ru@gmail.com" + } + ], + "description": "PHPMailer integration for Yii 2 framework", + "keywords": [ + "email", + "mail", + "mailer", + "phpmailer", + "yii2" + ], + "time": "2014-05-14T20:30:24+00:00" } ], "packages-dev": [ @@ -5412,16 +5508,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + "reference": "f29dca382a6485c3cbe6379f0c61230167681937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f29dca382a6485c3cbe6379f0c61230167681937", + "reference": "f29dca382a6485c3cbe6379f0c61230167681937", "shasum": "" }, "require": { @@ -5433,7 +5529,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -5467,7 +5563,7 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2017-06-09T14:24:12+00:00" }, { "name": "symfony/yaml", @@ -5769,7 +5865,8 @@ "kartik-v/yii2-widget-select2": 20, "bower-asset/amcharts": 20, "bower-asset/pnotify": 20, - "kartik-v/yii2-widget-datepicker": 20 + "kartik-v/yii2-widget-datepicker": 20, + "zyx/zyx-phpmailer": 0 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 9f723a4..a11cf5d 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -14,11 +14,14 @@ use artbox\order\models\SignupForm; use artbox\weblog\models\Article; use common\models\Settings; + use frontend\models\ShareBasket; use nodge\eauth\ErrorException; use nodge\eauth\openid\ControllerBehavior; use Yii; use yii\base\InvalidParamException; use yii\bootstrap\Html; + use yii\helpers\Json; + use yii\helpers\Url; use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\filters\VerbFilter; @@ -50,7 +53,8 @@ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ - 'feedback' => [ 'post' ], + 'feedback' => [ 'post' ], + 'share-basket' => [ 'post' ], ], ], 'eauth' => [ @@ -298,14 +302,14 @@ Yii::$app->getUrlManager() ->createAbsoluteUrl('site/login') ); - + try { if ($eauth->authenticate()) { // var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit; $identity = Customer::findByEAuth($eauth); Yii::$app->getUser() ->login($identity); - + // special redirect with closing popup window $eauth->redirect(); } else { @@ -316,7 +320,7 @@ // save error to show it later Yii::$app->getSession() ->setFlash('error', 'EAuthException: ' . $e->getMessage()); - + // close popup window and redirect to cancelUrl // $eauth->cancel(); $eauth->redirect($eauth->getCancelUrl()); @@ -418,4 +422,33 @@ ] ); } + + public function actionShareBasket() + { + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + $model = new ShareBasket(); + if ($model->load(\Yii::$app->request->post()) && $model->validate()) { + $result = $model->send(); + return $result; + } else { + return [ + 'success' => false, + 'msg' => \Yii::t('app', 'Email is not set.'), + ]; + } + } + + public function actionGetBasket($items) + { + /** + * @var \artbox\order\models\Basket $basket + */ + $basket = \Yii::$app->get('basket'); + $itemArray = Json::decode($items); + foreach ($itemArray as $variantId => $count) { + $basket->set($variantId, $count); + } + return $this->redirect('/checkout/index'); + } } diff --git a/frontend/models/ShareBasket.php b/frontend/models/ShareBasket.php new file mode 100644 index 0000000..45f8ac7 --- /dev/null +++ b/frontend/models/ShareBasket.php @@ -0,0 +1,97 @@ + \Yii::t('app', 'Поделиться корзиной'), + ]; + } + + public function send() + { + /** + * @var \artbox\order\models\Basket $basket + */ + $basket = \Yii::$app->get('basket'); + $data = $basket->getData(); + if (empty($data)) { + return [ + 'success' => false, + 'msg' => \Yii::t('app', 'Basket is empty'), + ]; + } + $dataArray = []; + foreach ($data as $variantId => $item) { + $dataArray[ $variantId ] = $item[ 'count' ]; + } + $dataString = Json::encode($dataArray); + $url = Url::to( + [ + $this->url, + 'items' => $dataString, + ], + true + ); + if (\Yii::$app->mailer->compose( + [ 'html' => 'shareBasket' ], + [ + 'url' => $url, + ] + ) + ->setFrom($this->from) + ->setTo($this->email) + ->setSubject(\Yii::t('app', 'Shared basket')) + ->send() + ) { + return [ + 'success' => true, + 'msg' => \Yii::t('app', 'Email successfully sent.'), + ]; + } else { + return [ + 'success' => false, + 'msg' => \Yii::t('app', 'Email cannot be send.'), + + ]; + } + } + } \ No newline at end of file diff --git a/frontend/views/checkout/index.php b/frontend/views/checkout/index.php index aa9b8bc..243500e 100755 --- a/frontend/views/checkout/index.php +++ b/frontend/views/checkout/index.php @@ -6,6 +6,8 @@ * @var \artbox\catalog\models\Product[] $topItems */ use artbox\core\helpers\ImageHelper; + use frontend\models\ShareBasket; + use yii\bootstrap\ActiveForm; use yii\bootstrap\Html; $formatter = \Yii::$app->formatter; @@ -136,33 +138,86 @@