add subscriber
This commit is contained in:
@@ -18,6 +18,7 @@ use common\models\Log;
|
||||
use common\models\Customer;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use frontend\models\SubscribeForm;
|
||||
use common\models\Subscriber;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
@@ -185,9 +186,9 @@ class SiteController extends Controller
|
||||
|
||||
$this->layout = "main-nologin";
|
||||
|
||||
$customer = Customer::find()
|
||||
->andWhere(['id_customer' => $id ])
|
||||
->andWhere(['newsletter_token' => $token])
|
||||
$customer = Subscriber::find()
|
||||
->andWhere(['id_subscriber' => $id ])
|
||||
->andWhere(['token' => $token])
|
||||
->one();
|
||||
|
||||
|
||||
@@ -195,51 +196,32 @@ class SiteController extends Controller
|
||||
throw new NotFoundHttpException("Az oldal nem található");
|
||||
}
|
||||
|
||||
$customer->newsletter = 0;
|
||||
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
$customer->status = 0;
|
||||
$customer->token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
$customer->save();
|
||||
|
||||
Log::logC([
|
||||
'id_customer' => $customer->id_customer,
|
||||
'type' => Log::$TYPE_NEWSLETTER_UNSUBSCRIBE,
|
||||
"message" => "Hírlevél feliratkozás: ". $customer->name
|
||||
"message" => "Hírlevél leiratkozás: ". $customer->name
|
||||
]);
|
||||
|
||||
|
||||
return $this->render("unsubscribe");
|
||||
return $this->render("unsubscribe",['subscriber' => $customer]);
|
||||
}
|
||||
|
||||
public function actionNewsletterSubscribe($id,$token)
|
||||
public function actionNewsletterSubscribe()
|
||||
{
|
||||
$this->layout = "main-nologin";
|
||||
|
||||
$model = new Subscriber(['scenario' => 'subscribe']);
|
||||
|
||||
|
||||
|
||||
$customer = Customer::find()
|
||||
->andWhere(['id_customer' => $id ])
|
||||
->andWhere(['newsletter_token' => $token])
|
||||
->one();
|
||||
|
||||
if ( !isset($customer)){
|
||||
throw new NotFoundHttpException("Az oldal nem található");
|
||||
}
|
||||
$model = new SubscribeForm([
|
||||
'customer' => $customer
|
||||
]);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
|
||||
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save() ) {
|
||||
|
||||
$customer->newsletter = 1;
|
||||
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
$customer->save();
|
||||
|
||||
|
||||
Log::logC([
|
||||
'id_customer' => $customer->id_customer,
|
||||
'type' => Log::$TYPE_NEWSLETTER_SUBSCRIBE,
|
||||
"message" => "Hírlevél feliratkozás: ". $customer->name ." - " . $customer->email
|
||||
"message" => "Hírlevél feliratkozás: ". $model->name ." - " . $model->email
|
||||
]);
|
||||
|
||||
return $this->redirect(["newsletter-subscribe-success"]);
|
||||
|
||||
@@ -4,18 +4,6 @@ use yii\helpers\Html;
|
||||
use common\components\Helper;
|
||||
?>
|
||||
<div class="key-form">
|
||||
<p>
|
||||
Kedves <?php echo $model->customer->name ?>!
|
||||
</p>
|
||||
<?php if ( empty($model->customer->email)) {?>
|
||||
<p>
|
||||
Ön nem adott meg e-mail címet. Ha szeretne feliratkozni a hírlevelünkre,
|
||||
kérjük keressen bennünket személyesen valamilyik termünkben.
|
||||
</p>
|
||||
<p>
|
||||
Köszönettel: <?php echo Helper::getCompanyName()?>
|
||||
</p>
|
||||
<?php }else{?>
|
||||
|
||||
<p>
|
||||
Ha Ön is szeretné megkapni a <?php echo Helper::getCompanyName() ?> hírleveleit,
|
||||
@@ -26,7 +14,9 @@ Kedves <?php echo $model->customer->name ?>!
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
|
||||
<?= $form->field($model, 'subscribe')->checkbox([])?>
|
||||
<?= $form->field($model, 'email')->textInput([])?>
|
||||
<?= $form->field($model, 'name')->textInput([])?>
|
||||
<?= $form->field($model, 'status')->checkbox([ 'label' => false ])->label("Szeretnék hírlevelet kapni")?>
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +25,5 @@ Kedves <?php echo $model->customer->name ?>!
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
<?php }?>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<?php
|
||||
use common\components\Helper;
|
||||
?>
|
||||
<p>
|
||||
Kedves <?php echo $subscriber->name ?>!
|
||||
</p>
|
||||
<p>
|
||||
Ön sikeresen leiratkozott a hírlevelünkről!
|
||||
A leiratkozott e-mail cím : <?php echo $subscriber->email?>
|
||||
</p>
|
||||
<p>
|
||||
Köszönettel:
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user