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
| @@ -27,8 +27,6 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -27,8 +27,6 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 27 | 'seo_id', | 27 | 'seo_id', |
| 28 | 'url:url', | 28 | 'url:url', |
| 29 | 'meta', | 29 | 'meta', |
| 30 | - 'title', | ||
| 31 | - 'description', | ||
| 32 | 'h1', | 30 | 'h1', |
| 33 | // 'seo_text:ntext', | 31 | // 'seo_text:ntext', |
| 34 | 32 |
common/modules/product/models/Category.php
| @@ -8,7 +8,6 @@ use common\components\artboxtree\ArtboxTreeHelper; | @@ -8,7 +8,6 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
| 8 | use common\modules\relation\relationBehavior; | 8 | use common\modules\relation\relationBehavior; |
| 9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | 9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
| 10 | use Yii; | 10 | use Yii; |
| 11 | -use yii\base\ErrorException; | ||
| 12 | 11 | ||
| 13 | /** | 12 | /** |
| 14 | * This is the model class for table "category". | 13 | * This is the model class for table "category". |
| @@ -29,7 +28,6 @@ use yii\base\ErrorException; | @@ -29,7 +28,6 @@ use yii\base\ErrorException; | ||
| 29 | * @property boolean $populary | 28 | * @property boolean $populary |
| 30 | * | 29 | * |
| 31 | * @property CategoryName $categoryName | 30 | * @property CategoryName $categoryName |
| 32 | - * @property Product[] $products | ||
| 33 | * @property ProductUnit $productUnit | 31 | * @property ProductUnit $productUnit |
| 34 | * @property CategoryName[] $categoryNames | 32 | * @property CategoryName[] $categoryNames |
| 35 | * @property ProductCategory[] $productCategories | 33 | * @property ProductCategory[] $productCategories |
| @@ -205,12 +203,4 @@ class Category extends \yii\db\ActiveRecord | @@ -205,12 +203,4 @@ class Category extends \yii\db\ActiveRecord | ||
| 205 | } | 203 | } |
| 206 | return false; | 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,20 +233,7 @@ class Product extends \yii\db\ActiveRecord | ||
| 233 | 233 | ||
| 234 | public function getOptions() { | 234 | public function getOptions() { |
| 235 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); | 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 | public function getStocks() { | 239 | public function getStocks() { |
| @@ -387,4 +374,18 @@ class Product extends \yii\db\ActiveRecord | @@ -387,4 +374,18 @@ class Product extends \yii\db\ActiveRecord | ||
| 387 | } | 374 | } |
| 388 | return $op; | 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
| @@ -41,7 +41,7 @@ class Mailer extends Widget{ | @@ -41,7 +41,7 @@ class Mailer extends Widget{ | ||
| 41 | return 'Mailer Error: ' . $mail->ErrorInfo; | 41 | return 'Mailer Error: ' . $mail->ErrorInfo; |
| 42 | } else { | 42 | } else { |
| 43 | 43 | ||
| 44 | - \Yii::$app->getSession()->setFlash('success', 'Мастер-приемщик свяжется с вами в ближайшее время'); | 44 | + |
| 45 | return 'Message has been sent'; | 45 | return 'Message has been sent'; |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
frontend/controllers/BasketController.php
| @@ -40,20 +40,48 @@ class BasketController extends Controller | @@ -40,20 +40,48 @@ class BasketController extends Controller | ||
| 40 | } | 40 | } |
| 41 | $body .= "\n\r"; | 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 | $productV = $_POST['ProductVariant']; | 44 | $productV = $_POST['ProductVariant']; |
| 45 | 45 | ||
| 46 | foreach ($productV as $index=>$row) { | 46 | foreach ($productV as $index=>$row) { |
| 47 | $modelOrdersProducts = new OrdersProducts(); | 47 | $modelOrdersProducts = new OrdersProducts(); |
| 48 | $mod_id = $row['id']; | 48 | $mod_id = $row['id']; |
| 49 | - unset($row['id']); | 49 | + |
| 50 | $data['OrdersProducts'] = $row; | 50 | $data['OrdersProducts'] = $row; |
| 51 | $data['OrdersProducts']['mod_id'] = $mod_id; | 51 | $data['OrdersProducts']['mod_id'] = $mod_id; |
| 52 | $data['OrdersProducts']['order_id'] = $modelOrder->id; | 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 | if(!Yii::$app->user->id && !empty($modelOrder->email)){ | 85 | if(!Yii::$app->user->id && !empty($modelOrder->email)){ |
| 58 | $modelUser = new Customer(); | 86 | $modelUser = new Customer(); |
| 59 | $modelUser->role = 'person'; | 87 | $modelUser->role = 'person'; |
| @@ -65,6 +93,10 @@ class BasketController extends Controller | @@ -65,6 +93,10 @@ class BasketController extends Controller | ||
| 65 | $modelUser->save(); | 93 | $modelUser->save(); |
| 66 | } | 94 | } |
| 67 | $order = clone $modelOrder; | 95 | $order = clone $modelOrder; |
| 96 | + /** | ||
| 97 | + * Чистим сессию корзины | ||
| 98 | + */ | ||
| 99 | + | ||
| 68 | $modelOrder->clearBasket(); | 100 | $modelOrder->clearBasket(); |
| 69 | 101 | ||
| 70 | Mailer::widget( | 102 | Mailer::widget( |
frontend/views/basket/index.php
| @@ -41,7 +41,12 @@ $('#orders-delivery input[type=\"radio\"]').click(function(){ | @@ -41,7 +41,12 @@ $('#orders-delivery input[type=\"radio\"]').click(function(){ | ||
| 41 | 41 | ||
| 42 | <h1 class="basket_title_">Корзина</h1> | 42 | <h1 class="basket_title_">Корзина</h1> |
| 43 | <div class="ten"></div> | 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 | <?php $form = ActiveForm::begin(['enableClientScript' => false]); ?> | 50 | <?php $form = ActiveForm::begin(['enableClientScript' => false]); ?> |
| 46 | <div class="rightbar basket_rightbar"> | 51 | <div class="rightbar basket_rightbar"> |
| 47 | <div class="form-order"> | 52 | <div class="form-order"> |
frontend/views/iam/share.php
| @@ -46,6 +46,7 @@ $this->registerJs(" | @@ -46,6 +46,7 @@ $this->registerJs(" | ||
| 46 | 46 | ||
| 47 | <div class="orders_view"> | 47 | <div class="orders_view"> |
| 48 | <?foreach($_items as $item_p):if(!empty($item_p->product)):?> | 48 | <?foreach($_items as $item_p):if(!empty($item_p->product)):?> |
| 49 | + <?= print_r($item_p->product); die(); ?> | ||
| 49 | <div class="order"> | 50 | <div class="order"> |
| 50 | <div><a href="<?=Url::to(['iam/share','deleteID'=>$item_p->id])?>" class="delete_button"></a></div> | 51 | <div><a href="<?=Url::to(['iam/share','deleteID'=>$item_p->id])?>" class="delete_button"></a></div> |
| 51 | <div class="pixbox"><a href="<?=Url::to(['catalog/product', 'product' => $item_p->product])?>"> | 52 | <div class="pixbox"><a href="<?=Url::to(['catalog/product', 'product' => $item_p->product])?>"> |