Commit dac616aa5b3ba9a4fb44e41f68e2df8540c06079
1 parent
22a34996
add variantSku
Showing
2 changed files
with
66 additions
and
197 deletions
Show diff stats
models/Stock.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | - namespace artweb\artbox\ecommerce\models; | ||
4 | - | ||
5 | - use artweb\artbox\language\behaviors\LanguageBehavior; | ||
6 | - use Yii; | ||
7 | - use yii\db\ActiveQuery; | ||
8 | - use yii\db\ActiveRecord; | ||
9 | - use yii\web\Request; | ||
10 | - | 2 | + |
3 | +namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "stock". | ||
9 | + * | ||
10 | + * @property integer $id | ||
11 | + * @property string $title | ||
12 | + * | ||
13 | + * @property ProductStock[] $productStocks | ||
14 | + */ | ||
15 | +class Stock extends \yii\db\ActiveRecord | ||
16 | +{ | ||
17 | + | ||
11 | /** | 18 | /** |
12 | - * This is the model class for table "stock". | ||
13 | - * | ||
14 | - * @property integer $id | ||
15 | - * @property ProductStock[] $productStocks | ||
16 | - * @property ProductVariant[] $productVariants | ||
17 | - * @property Product[] $products | ||
18 | - * * From language behavior * | ||
19 | - * @property StockLang $lang | ||
20 | - * @property StockLang[] $langs | ||
21 | - * @property StockLang $objectLang | ||
22 | - * @property string $ownerKey | ||
23 | - * @property string $langKey | ||
24 | - * @property StockLang[] $modelLangs | ||
25 | - * @property bool $transactionStatus | ||
26 | - * @method string getOwnerKey() | ||
27 | - * @method void setOwnerKey( string $value ) | ||
28 | - * @method string getLangKey() | ||
29 | - * @method void setLangKey( string $value ) | ||
30 | - * @method ActiveQuery getLangs() | ||
31 | - * @method ActiveQuery getLang( integer $language_id ) | ||
32 | - * @method StockLang[] generateLangs() | ||
33 | - * @method void loadLangs( Request $request ) | ||
34 | - * @method bool linkLangs() | ||
35 | - * @method bool saveLangs() | ||
36 | - * @method bool getTransactionStatus() | ||
37 | - * * End language behavior * | 19 | + * @inheritdoc |
38 | */ | 20 | */ |
39 | - class Stock extends ActiveRecord | 21 | + public static function tableName() |
40 | { | 22 | { |
41 | - /** | ||
42 | - * @inheritdoc | ||
43 | - */ | ||
44 | - public static function tableName() | ||
45 | - { | ||
46 | - return 'stock'; | ||
47 | - } | ||
48 | - | ||
49 | - public function behaviors() | ||
50 | - { | ||
51 | - return [ | ||
52 | - 'language' => [ | ||
53 | - 'class' => LanguageBehavior::className(), | ||
54 | - ], | ||
55 | - ]; | ||
56 | - } | ||
57 | - | ||
58 | - /** | ||
59 | - * @inheritdoc | ||
60 | - */ | ||
61 | - public function attributeLabels() | ||
62 | - { | ||
63 | - return [ | ||
64 | - 'id' => Yii::t('product', 'Stock ID'), | ||
65 | - ]; | ||
66 | - } | ||
67 | - | ||
68 | - /** | ||
69 | - * @return \yii\db\ActiveQuery | ||
70 | - */ | ||
71 | - public function getProductStocks() | ||
72 | - { | ||
73 | - return $this->hasMany(ProductStock::className(), [ 'stock_id' => 'id' ]); | ||
74 | - } | ||
75 | - | ||
76 | - /** | ||
77 | - * @return ActiveQuery | ||
78 | - */ | ||
79 | - public function getProductVariants() | ||
80 | - { | ||
81 | - return $this->hasMany(ProductVariant::className(), [ 'id' => 'product_variant_id' ]) | ||
82 | - ->via('productStocks'); | ||
83 | - } | ||
84 | - | ||
85 | - /** | ||
86 | - * @return ActiveQuery | ||
87 | - */ | ||
88 | - public function getProducts() | ||
89 | - { | ||
90 | - return $this->hasMany(Product::className(), [ 'id' => 'product_id' ]) | ||
91 | - ->via('productVariants'); | 23 | + return 'stock'; |
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * @inheritdoc | ||
28 | + */ | ||
29 | + public function rules() | ||
30 | + { | ||
31 | + return [ | ||
32 | + [['title'], 'string', 'max' => 150], | ||
33 | + [['title'], 'required'], | ||
34 | + ]; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + public function getSiteName(){ | ||
39 | + switch(mb_strtolower($this->title)){ | ||
40 | + case "ั ะฐััะบะพะฒ ัะฒะตั": | ||
41 | + return 'ะะะะะะะ ะฅะะ ะฌะะะ'; | ||
42 | + break; | ||
43 | + case "ะพัะพะบะพัะบะธ": | ||
44 | + return 'ะะะะะะะ "ะะกะะะะ ะะ"'; | ||
45 | + break; | ||
46 | + case "ะพะปะธะผะฟ": | ||
47 | + return 'ะขะฆ "ะะะะะะะะกะะะ"'; | ||
48 | + break; | ||
49 | + case "ะผะฐะณะฐะทะธะฝ": | ||
50 | + return "ะะะะะะะ ะะะฃะะะงะะฆะะะฏ"; | ||
51 | + break; | ||
52 | + default: | ||
53 | + //return "ะะฐ ัะบะปะฐะดะต"; | ||
54 | + break; | ||
92 | } | 55 | } |
93 | } | 56 | } |
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + /** | ||
62 | + * @inheritdoc | ||
63 | + */ | ||
64 | + public function attributeLabels() | ||
65 | + { | ||
66 | + return [ | ||
67 | + 'stock_id' => Yii::t('product', 'Stock ID'), | ||
68 | + 'name' => Yii::t('product', 'Name'), | ||
69 | + ]; | ||
70 | + } | ||
71 | + | ||
72 | +} |
models/StockLang.php deleted
1 | -<?php | ||
2 | - | ||
3 | - namespace artweb\artbox\ecommerce\models; | ||
4 | - | ||
5 | - use artweb\artbox\language\models\Language; | ||
6 | - use Yii; | ||
7 | - use yii\db\ActiveRecord; | ||
8 | - | ||
9 | - /** | ||
10 | - * This is the model class for table "brand_lang". | ||
11 | - * | ||
12 | - * @property integer $stock_id | ||
13 | - * @property integer $language_id | ||
14 | - * @property string $title | ||
15 | - * @property Stock $stock | ||
16 | - * @property Language $language | ||
17 | - */ | ||
18 | - class StockLang extends ActiveRecord | ||
19 | - { | ||
20 | - | ||
21 | - public static function primaryKey() | ||
22 | - { | ||
23 | - return [ | ||
24 | - 'stock_id', | ||
25 | - 'language_id', | ||
26 | - ]; | ||
27 | - } | ||
28 | - | ||
29 | - /** | ||
30 | - * @inheritdoc | ||
31 | - */ | ||
32 | - public static function tableName() | ||
33 | - { | ||
34 | - return 'stock_lang'; | ||
35 | - } | ||
36 | - | ||
37 | - /** | ||
38 | - * @inheritdoc | ||
39 | - */ | ||
40 | - public function rules() | ||
41 | - { | ||
42 | - return [ | ||
43 | - [ | ||
44 | - [ 'title' ], | ||
45 | - 'required', | ||
46 | - ], | ||
47 | - [ | ||
48 | - [ | ||
49 | - 'title', | ||
50 | - ], | ||
51 | - 'string', | ||
52 | - 'max' => 255, | ||
53 | - ], | ||
54 | - [ | ||
55 | - [ | ||
56 | - 'stock_id', | ||
57 | - 'language_id', | ||
58 | - ], | ||
59 | - 'unique', | ||
60 | - 'targetAttribute' => [ | ||
61 | - 'stock_id', | ||
62 | - 'language_id', | ||
63 | - ], | ||
64 | - 'message' => 'The combination of Stock ID and Language ID has already been taken.', | ||
65 | - ], | ||
66 | - [ | ||
67 | - [ 'stock_id' ], | ||
68 | - 'exist', | ||
69 | - 'skipOnError' => true, | ||
70 | - 'targetClass' => Stock::className(), | ||
71 | - 'targetAttribute' => [ 'stock_id' => 'id' ], | ||
72 | - ], | ||
73 | - [ | ||
74 | - [ 'language_id' ], | ||
75 | - 'exist', | ||
76 | - 'skipOnError' => true, | ||
77 | - 'targetClass' => Language::className(), | ||
78 | - 'targetAttribute' => [ 'language_id' => 'id' ], | ||
79 | - ], | ||
80 | - ]; | ||
81 | - } | ||
82 | - | ||
83 | - /** | ||
84 | - * @inheritdoc | ||
85 | - */ | ||
86 | - public function attributeLabels() | ||
87 | - { | ||
88 | - return [ | ||
89 | - 'stock_id' => Yii::t('app', 'Stock ID'), | ||
90 | - 'language_id' => Yii::t('app', 'Language ID'), | ||
91 | - 'title' => Yii::t('app', 'Name'), | ||
92 | - ]; | ||
93 | - } | ||
94 | - | ||
95 | - /** | ||
96 | - * @return \yii\db\ActiveQuery | ||
97 | - */ | ||
98 | - public function getStock() | ||
99 | - { | ||
100 | - return $this->hasOne(Stock::className(), [ 'id' => 'stock_id' ]); | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * @return \yii\db\ActiveQuery | ||
105 | - */ | ||
106 | - public function getLanguage() | ||
107 | - { | ||
108 | - return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
109 | - } | ||
110 | - } |