Commit 49c47c761821dd1e298a6e90d448913621dc2861

Authored by Karnovsky A
1 parent 486e5dea

-

common/modules/product/controllers/ManageController.php
... ... @@ -40,54 +40,12 @@ class ManageController extends Controller
40 40 ];
41 41 }
42 42  
43   - public function actionTest() {
44   - return;
45   - foreach(Product::find()->all() as $product) {
46   - if (!$product->variant) {
47   - $product->save();
48   - $variantModel = new ProductVariant();
49   - $variantModel->product_id = $product->product_id;
50   - $variantModel->name = 'test-'. uniqid();
51   - $variantModel->sku = $variantModel->name;
52   - $variantModel->price = rand(5, 200000);
53   - $variantModel->price_old = rand(0, 5) > 3 ? $variantModel->price* (1+rand(0, 10) / 10) : $variantModel->price;
54   - $variantModel->product_unit_id = rand(1, 5);
55   - $variantModel->stock = rand(0, 50);
56   - $variantModel->save();
57   - }
58   - }
59   -
60   - return;
61   -
62   - $categories = Category::find()->where(['depth' => 2])->all();
63   - $cats_ids = [];
64   - foreach($categories as $cat) {
65   - $cats_ids[] = $cat->category_id;
66   - }
67   -
68   - $brands = ProductHelper::getBrands()->all();
69   - $brands_ids = [];
70   - foreach($brands as $brand) {
71   - $brands_ids[] = $brand->brand_id;
72   - }
73   -
74   - for($i=1;$i<=1000;$i++) {
75   - $uniqid = uniqid();
76   - $model = new Product();
77   - $model->name = 'Test '. $uniqid;
78   - $model->brand_id = $brands_ids[array_rand($brands_ids, 1)];
79   - $model->categories = [$cats_ids[array_rand($cats_ids, 1)]];
80   - $model->save();
81   -
82   - $variantModel = new ProductVariant();
83   - $variantModel->product_id = $model->product_id;
84   - $variantModel->name = 'test-'. $uniqid;
85   - $variantModel->sku = $variantModel->name;
86   - $variantModel->price = rand(5, 200000);
87   - $variantModel->price_old = rand(0, 5) > 3 ? $variantModel->price* (1+rand(0, 10) / 10) : $variantModel->price;
88   - $variantModel->product_unit_id = rand(1, 5);
89   - $variantModel->save();
  43 + public function actionDev() {
  44 + foreach (ProductVariant::find()->where(['>', 'price_old', 0])->all() as $item) {
  45 + if ($item->price >= $item->price_old || $item->price == 0)
  46 + print $item->price .' | '. $item->price_old ."<br>\n";
90 47 }
  48 + print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
91 49 }
92 50  
93 51 /**
... ...
common/modules/product/models/ProductVariant.php
... ... @@ -34,7 +34,7 @@ class ProductVariant extends \yii\db\ActiveRecord
34 34 public $translit;
35 35 public $translit_rubric;
36 36 private $data;
37   - public $stocks = [];
  37 + public $stocks;
38 38  
39 39 /** @var array $_images */
40 40 // public $imagesUpload = [];
... ... @@ -171,7 +171,7 @@ class ProductVariant extends \yii\db\ActiveRecord
171 171  
172 172 public function afterSave($insert, $changedAttributes)
173 173 {
174   - if (!empty($this->stocks)) {
  174 + if (!is_null($this->stocks)) {
175 175 ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]);
176 176 $values = [];
177 177 foreach ($this->stocks as $id => $quantity) {
... ...
common/modules/product/models/import.php
... ... @@ -92,7 +92,7 @@ class Import extends Model {
92 92 $product_title = @$data[5];
93 93  
94 94 if (empty ($modification_code)) {
95   - CONTINUE;
  95 + continue;
96 96 }
97 97 // товары в пути
98 98 if (empty ($city_name))
... ... @@ -104,10 +104,10 @@ class Import extends Model {
104 104  
105 105 $this->output[] = 'Товар '. $product_title . ' в пути';
106 106  
107   - CONTINUE;
  107 + continue;
108 108 }
109 109  
110   - if ( ($productVariant = ProductVariant::find()->filterWhere(['ilike', 'sku', trim($modification_code)])->one()) === null ) {
  110 + if ( ($productVariant = ProductVariant::find()->filterWhere(['sku' => trim($modification_code)])->one()) === null ) {
111 111 // 'Нет даной модификации в базе';
112 112 $this->saveNotFoundRecord (
113 113 [$modification_code, $product_title],
... ... @@ -116,7 +116,7 @@ class Import extends Model {
116 116  
117 117 $this->output[] = 'Для товара '. $product_title . ' не найдено соотвествие';
118 118  
119   - CONTINUE;
  119 + continue;
120 120 }
121 121  
122 122 $quantity = 0;
... ... @@ -134,8 +134,14 @@ class Import extends Model {
134 134 $quantity = $quantity + $count;
135 135 }
136 136  
137   - $productVariant->price = $price;
138   - $productVariant->price_old = $price_promo;
  137 + if ($price_promo) {
  138 + $productVariant->price_old = $price;
  139 + $productVariant->price = $price_promo;
  140 + } else {
  141 + $productVariant->price = $price;
  142 + $productVariant->price_old = $price_promo;
  143 + }
  144 +
139 145 $productVariant->stock = $quantity;
140 146  
141 147 $productVariant->save();
... ... @@ -155,6 +161,7 @@ class Import extends Model {
155 161  
156 162 if ($result['end']) {
157 163 unlink(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFilePrices'));
  164 + $this->output[] = '<font style="color:green; font-weight: bold">Импорт цен успешно завершен!</font>';
158 165 }
159 166  
160 167 return $result;
... ... @@ -205,7 +212,7 @@ class Import extends Model {
205 212 if (empty ($catalog_name))
206 213 {
207 214 $result_items[] = "Не указана категория (строка $j)";
208   - CONTINUE;
  215 + continue;
209 216 }
210 217  
211 218 // 2 Бренд
... ... @@ -213,7 +220,7 @@ class Import extends Model {
213 220 if (empty ($brand_name))
214 221 {
215 222 $result_items[] = "Не указан бренд (строка $j)";
216   - CONTINUE;
  223 + continue;
217 224 }
218 225  
219 226 // 3 Название товара
... ... @@ -221,7 +228,7 @@ class Import extends Model {
221 228 if (empty ($product_name))
222 229 {
223 230 $result_items[] = "Не указано наименование товара (строка $j)";
224   - CONTINUE;
  231 + continue;
225 232 }
226 233  
227 234 // 4 Описание Укр
... ... @@ -242,11 +249,14 @@ class Import extends Model {
242 249 // 9 Год
243 250 $years = explode (',', $data[8]);
244 251  
245   - // 10 Цена старая
246   - $product_cost_old = $data[10];
  252 + // 11 Цена акция
  253 + $product_cost_old = floatval($data[10]);
247 254  
248   - // 11 Цена
249   - $product_cost = $data[9];
  255 + // 10 Цена
  256 + if ($product_cost_old) {
  257 + $product_cost_old = floatval($data[9]);
  258 + $product_cost = floatval($data[10]);
  259 + }
250 260  
251 261 // 12 Акция
252 262 $product_akciya = (bool)$data[11];
... ...
frontend/controllers/LoginController.php
... ... @@ -7,8 +7,6 @@ use yii\web\Controller;
7 7 use frontend\models\LoginForm;
8 8 use common\models\Customer;
9 9  
10   -use common\widgets\Mailer;
11   -
12 10 class LoginController extends Controller
13 11 {
14 12 //public $layout='layout';
... ... @@ -36,15 +34,10 @@ class LoginController extends Controller
36 34 }
37 35  
38 36 public function actionForgot(){
  37 +
39 38 $model = new Customer;
40   - if(!empty($_POST['Customer']['username'])){
41   - if($user = Customer::find()->where(['username'=>$_POST['Customer']['username']])->one())
42   - Mailer::widget(
43   - ['type' => 'password',
44   - 'subject'=> 'Ваш пароль',
45   - 'email' => $user->username,
46   - 'params' => $user,
47   - ]);
  39 + if(!empty($_POST['User']['username'])){
  40 + if($user = Customer::find()->where(['username'=>$_POST['User']['username']])->one())
48 41 $user->sendMsg();
49 42 Yii::$app->getSession()->setFlash('success', 'На указанный Вами эмейл отправленно письмо с паролем!');
50 43 return $this->refresh();
... ...
frontend/controllers/SiteController.php
... ... @@ -189,12 +189,5 @@ class SiteController extends Controller
189 189  
190 190 }
191 191  
192   - public function actionSms()
193   - {
194   -
195   - $resp = Yii::$app->smssender->send('+380633930736','test Rukzak');
196   - var_dump($resp);
197   -
198   - }
199 192  
200 193 }
201 194 \ No newline at end of file
... ...
frontend/models/ProductFrontendSearch.php
... ... @@ -76,7 +76,7 @@ class ProductFrontendSearch extends Product {
76 76 'asc' => [ProductVariant::tableName() .'.price' => SORT_ASC],
77 77 'desc' => [ProductVariant::tableName() .'.price' => SORT_DESC],
78 78 'default' => SORT_DESC,
79   - 'label' => 'цене',
  79 + 'label' => 'по цене',
80 80 ],
81 81 ],
82 82 ]
... ...