Skip to content

Commit

Permalink
Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Serov-RA committed Oct 31, 2019
1 parent 4eb6de1 commit 9784e7c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
24 changes: 13 additions & 11 deletions controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public function actionIndex($url = '')
return $this->addReview();
}

$label = ProductLabel::findOne(['widget' => $url]);

if ($label) {
return $this->actionSearch($label);
}

$url_parts = explode('/', $url);

$models = [];
Expand Down Expand Up @@ -832,7 +838,7 @@ protected function getParentLink($models)
return $url;
}

public function actionSearch()
public function actionSearch($label = false)
{
$searchtext = Yii::$app->request->get('searchtext', false);
$searchtag = Yii::$app->request->get('tag', false);
Expand All @@ -842,7 +848,6 @@ public function actionSearch()
$offset = ($product_page - 1) * $limit;
$product_count = 0;
$products = [];
$label = false;

if ($searchtext) {
$productsQuery = Product::find()->where(
Expand All @@ -857,15 +862,12 @@ public function actionSearch()
);

$product_count = $productsQuery->count();
} elseif ($searchtag) {
$label = ProductLabel::findOne(['widget' => $searchtag]);

if ($label) {
$productsQuery = Product::find()->innerJoin(ProductLabels::tableName(), ProductLabels::tableName().'.product_id='.Product::tableName().'.id')
->where([Product::tableName().'.status' => Product::STATUS_ACTIVE])
->andWhere(['label_id' => $label->id]);
$product_count = $productsQuery->count();
}
} elseif ($label) {

$productsQuery = Product::find()->innerJoin(ProductLabels::tableName(), ProductLabels::tableName().'.product_id='.Product::tableName().'.id')
->where([Product::tableName().'.status' => Product::STATUS_ACTIVE])
->andWhere(['label_id' => $label->id]);
$product_count = $productsQuery->count();
}

if ($product_count) {
Expand Down
2 changes: 1 addition & 1 deletion models/ActiveRecord/ProductLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getContent()
}

return $this->link || $this->widget ?
Html::a(Html::encode($this->label), ($this->link ? $this->link : '/shop/search?tag='.$this->widget), ['style' => implode(';', $styles), 'class' => 'product_label'])
Html::a(Html::encode($this->label), ($this->link ? $this->link : '/shop/'.$this->widget), ['style' => implode(';', $styles), 'class' => 'product_label'])
:
'<span class="product_label"'.($styles ? ' style="'.implode(';', $styles).'"' : '').'>'.
Html::encode($this->label).
Expand Down
9 changes: 8 additions & 1 deletion views/shop/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@
<i class="fa fa-ruble"></i>
</div>
<div class="product_item_button">
<button class="add_shopcart" data-id="<?= $product->id ?>" data-cnt="1">В корзину</button>
<div class="product_item_q">
<div class="product_item_quantity_control" id="product_item_quantity_control_<?= $product->id ?>search">
<span class="product_item_quantity_control_minus" data-id="<?= $product->id ?>" data-widget="search">&ndash;</span>
<span class="product_item_quantity_control_plus" data-id="<?= $product->id ?>" data-widget="search">+</span>
<span class="product_item_quantity_control_count">1</span>
</div>
</div>
<button class="add_shopcart add_shopcart<?= $product->id ?>search" data-id="<?= $product->id ?>" data-cnt="1">В корзину</button>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions web/js/shopcart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var shopcart = {
$('.custom_form_selector').on('click', this.customSelEvent);
$('.custom_checkbox').on('click', this.checkboxEvent);
$('#shoporder-phone').mask("+7(999) 999-99-99");
$('.product_widget .product_item_quantity_control_minus').on('click', this.minusWidgetEvent);
$('.product_widget .product_item_quantity_control_plus').on('click', this.plusWidgetEvent);
$('.product_widget .product_item_quantity_control_minus, .find_products .product_item_quantity_control_minus').on('click', this.minusWidgetEvent);
$('.product_widget .product_item_quantity_control_plus, .find_products .product_item_quantity_control_plus').on('click', this.plusWidgetEvent);
},
getCurrentCount: function(obj) {
var el = $('#product_item_quantity_control_' + $(obj).data('id') + $(obj).data('widget'));
Expand Down

0 comments on commit 9784e7c

Please sign in to comment.