Commit eb74a2bf98aa430d41f276fac8b405a32ee52f5c
1 parent
49c47c76
14.06.16
Showing
7 changed files
with
60 additions
and
33 deletions
Show diff stats
backend/views/seo/index.php
common/modules/product/models/Category.php
... | ... | @@ -8,7 +8,6 @@ use common\components\artboxtree\ArtboxTreeHelper; |
8 | 8 | use common\modules\relation\relationBehavior; |
9 | 9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
10 | 10 | use Yii; |
11 | -use yii\base\ErrorException; | |
12 | 11 | |
13 | 12 | /** |
14 | 13 | * This is the model class for table "category". |
... | ... | @@ -29,7 +28,6 @@ use yii\base\ErrorException; |
29 | 28 | * @property boolean $populary |
30 | 29 | * |
31 | 30 | * @property CategoryName $categoryName |
32 | - * @property Product[] $products | |
33 | 31 | * @property ProductUnit $productUnit |
34 | 32 | * @property CategoryName[] $categoryNames |
35 | 33 | * @property ProductCategory[] $productCategories |
... | ... | @@ -205,12 +203,4 @@ class Category extends \yii\db\ActiveRecord |
205 | 203 | } |
206 | 204 | return false; |
207 | 205 | } |
208 | - | |
209 | - public function beforeDelete() | |
210 | - { | |
211 | - if ( ($count = $this->getProducts()->count()) > 0) { | |
212 | - throw new ErrorException('С категорией "'. $this->name .'" связанно <strong>'. $count .'</strong> товаров. Удаление невозможно.'); | |
213 | - return false; | |
214 | - } | |
215 | - } | |
216 | 206 | } | ... | ... |
common/modules/product/models/Product.php
... | ... | @@ -233,20 +233,7 @@ class Product extends \yii\db\ActiveRecord |
233 | 233 | |
234 | 234 | public function getOptions() { |
235 | 235 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); |
236 | - } | |
237 | - | |
238 | - public function getProperties() { | |
239 | - $groups = $options = []; | |
240 | - foreach ($this->options as $option) { | |
241 | - $options[$option->tax_group_id][] = $option; | |
242 | - } | |
243 | - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | |
244 | - if (!empty($options[$group->tax_group_id])) { | |
245 | - $group->_options = $options[$group->tax_group_id]; | |
246 | - $groups[] = $group; | |
247 | - } | |
248 | - } | |
249 | - return $groups; | |
236 | +// return $this->getRelations('product_option'); | |
250 | 237 | } |
251 | 238 | |
252 | 239 | public function getStocks() { |
... | ... | @@ -387,4 +374,18 @@ class Product extends \yii\db\ActiveRecord |
387 | 374 | } |
388 | 375 | return $op; |
389 | 376 | } |
377 | + | |
378 | + public function getProperties() { | |
379 | + $groups = $options = []; | |
380 | + foreach ($this->options as $option) { | |
381 | + $options[$option->tax_group_id][] = $option; | |
382 | + } | |
383 | + foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | |
384 | + if (!empty($options[$group->tax_group_id])) { | |
385 | + $group->_options = $options[$group->tax_group_id]; | |
386 | + $groups[] = $group; | |
387 | + } | |
388 | + } | |
389 | + return $groups; | |
390 | + } | |
390 | 391 | } | ... | ... |
common/widgets/Mailer.php
frontend/controllers/BasketController.php
... | ... | @@ -40,20 +40,48 @@ class BasketController extends Controller |
40 | 40 | } |
41 | 41 | $body .= "\n\r"; |
42 | 42 | |
43 | - if ($modelOrder->load(Yii::$app->request->post()) && $modelOrder->save()) { | |
43 | + if ($modelOrder->load(Yii::$app->request->post()) && $modelOrder->validate()) { | |
44 | 44 | $productV = $_POST['ProductVariant']; |
45 | 45 | |
46 | 46 | foreach ($productV as $index=>$row) { |
47 | 47 | $modelOrdersProducts = new OrdersProducts(); |
48 | 48 | $mod_id = $row['id']; |
49 | - unset($row['id']); | |
49 | + | |
50 | 50 | $data['OrdersProducts'] = $row; |
51 | 51 | $data['OrdersProducts']['mod_id'] = $mod_id; |
52 | 52 | $data['OrdersProducts']['order_id'] = $modelOrder->id; |
53 | - $productV[$index]['img'] = \common\components\artboximage\ArtboxImageHelper::getImageSrc(ProductVariant::findOne($mod_id)->image->imageUrl, 'list'); | |
54 | - $modelOrdersProducts->load($data); | |
55 | - $modelOrdersProducts->save(); | |
53 | + $product = ProductVariant::findOne($mod_id); | |
54 | + /** | |
55 | + * Проверяем товар на наличие | |
56 | + */ | |
57 | + if(!$product->stock > 0 && !$product->price > 0 ){ | |
58 | + \Yii::$app->getSession()->setFlash('error', 'К сожалению товара '.$product->name . ' нет в наличии'); | |
59 | + | |
60 | + $basket_mods = $modelOrder->getBasketMods(); | |
61 | + return $this->render('index',[ | |
62 | + 'modelMod'=>$modelMod, | |
63 | + 'basket_mods'=>$basket_mods, | |
64 | + 'modelOrder'=>$modelOrder, | |
65 | + ]); | |
66 | + }else { | |
67 | + | |
68 | + /** | |
69 | + * Удаляем товар с массива и сохраняем в заказ | |
70 | + */ | |
71 | + unset($row['id']); | |
72 | + $productV[$index]['img'] = \common\components\artboximage\ArtboxImageHelper::getImageSrc($product->image->imageUrl, 'list'); | |
73 | + $modelOrdersProducts->load($data); | |
74 | + $modelOrdersProducts->save(); | |
75 | + } | |
76 | + | |
56 | 77 | } |
78 | + | |
79 | + /** | |
80 | + * Сохраняем заказ | |
81 | + */ | |
82 | + | |
83 | + $modelOrder->save(); | |
84 | + | |
57 | 85 | if(!Yii::$app->user->id && !empty($modelOrder->email)){ |
58 | 86 | $modelUser = new Customer(); |
59 | 87 | $modelUser->role = 'person'; |
... | ... | @@ -65,6 +93,10 @@ class BasketController extends Controller |
65 | 93 | $modelUser->save(); |
66 | 94 | } |
67 | 95 | $order = clone $modelOrder; |
96 | + /** | |
97 | + * Чистим сессию корзины | |
98 | + */ | |
99 | + | |
68 | 100 | $modelOrder->clearBasket(); |
69 | 101 | |
70 | 102 | Mailer::widget( | ... | ... |
frontend/views/basket/index.php
... | ... | @@ -41,7 +41,12 @@ $('#orders-delivery input[type=\"radio\"]').click(function(){ |
41 | 41 | |
42 | 42 | <h1 class="basket_title_">Корзина</h1> |
43 | 43 | <div class="ten"></div> |
44 | - | |
44 | + <?php if ($flash = Yii::$app->session->getFlash ('success')): ?> | |
45 | + <div class="alert-success"><?= $flash ?></div> | |
46 | + <?php endif; ?> | |
47 | + <?php if ($flash = Yii::$app->session->getFlash ('error')): ?> | |
48 | + <div class="alert-error"><?= $flash ?></div> | |
49 | + <?php endif; ?> | |
45 | 50 | <?php $form = ActiveForm::begin(['enableClientScript' => false]); ?> |
46 | 51 | <div class="rightbar basket_rightbar"> |
47 | 52 | <div class="form-order"> | ... | ... |
frontend/views/iam/share.php
... | ... | @@ -46,6 +46,7 @@ $this->registerJs(" |
46 | 46 | |
47 | 47 | <div class="orders_view"> |
48 | 48 | <?foreach($_items as $item_p):if(!empty($item_p->product)):?> |
49 | + <?= print_r($item_p->product); die(); ?> | |
49 | 50 | <div class="order"> |
50 | 51 | <div><a href="<?=Url::to(['iam/share','deleteID'=>$item_p->id])?>" class="delete_button"></a></div> |
51 | 52 | <div class="pixbox"><a href="<?=Url::to(['catalog/product', 'product' => $item_p->product])?>"> | ... | ... |