-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShopDiscountCouponWidget.php
101 lines (80 loc) · 2.27 KB
/
ShopDiscountCouponWidget.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 14.10.2016
*/
namespace skeeks\cms\shopDiscountCoupon;
use skeeks\cms\shop\models\shopUser;
use yii\base\Widget;
use yii\helpers\ArrayHelper;
/**
* Class ShopDiscountCouponWidget
*
* @package skeeks\cms\shopDiscountCoupon
*/
class ShopDiscountCouponWidget extends Widget
{
public static $autoIdPrefix = 'ShopDiscountCouponWidget';
public $viewFile = 'default';
public $options = [];
public $clientOptions = [];
public $btnSubmitName = '';
/**
* @var array
*/
public $couponInputOptions = [
];
/**
* @var ShopUser
*/
public $shopUser = null;
public $btnSubmitOptions = [
'class' => 'btn btn-secondary btn-block',
'type' => 'submit',
];
public function init()
{
parent::init();
static::registerTranslations();
$this->options['id'] = $this->id;
if (!$this->shopUser) {
$this->shopUser = \Yii::$app->shop->getCart();
$this->shopUser->loadDefaultValues();
}
$this->clientOptions = ArrayHelper::merge($this->clientOptions, [
'id' => $this->id,
'formid' => $this->formId,
]);
if (!$this->btnSubmitName) {
$this->btnSubmitName = \Yii::t('skeeks/shop-dicount-coupon', 'Get a discount');
}
}
public function run()
{
return $this->render($this->viewFile);
}
/**
* @return string
*/
public function getFormId()
{
return $this->id."-form";
}
static public $isRegisteredTranslations = false;
static public function registerTranslations()
{
if (self::$isRegisteredTranslations === false) {
\Yii::$app->i18n->translations['skeeks/shop-dicount-coupon'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@skeeks/cms/shopDiscountCoupon/messages',
'fileMap' => [
'skeeks/shop-dicount-coupon' => 'main.php',
],
];
self::$isRegisteredTranslations = true;
}
}
}