diff --git a/helpers/ProductHelper.php b/helpers/ProductHelper.php index 0e7a79a..754fb50 100755 --- a/helpers/ProductHelper.php +++ b/helpers/ProductHelper.php @@ -4,6 +4,7 @@ use artweb\artbox\ecommerce\models\Category; use artweb\artbox\ecommerce\models\Product; + use artweb\artbox\ecommerce\models\ProductVariant; use yii\base\InvalidConfigException; use yii\base\InvalidParamException; use yii\base\Object; @@ -179,6 +180,23 @@ $product->id, ] ); + + + $query->andWhere([ + '>=', + ProductVariant::tableName() . '.price', + ($product->variant->price * 0.8), + ]); + + + $query->andWhere([ + '<=', + ProductVariant::tableName() . '.price', + ($product->variant->price * 1.2), + ]); + + + $query->groupBy('product.id'); $query->limit($count); return $query; diff --git a/widgets/similarProducts.php b/widgets/similarProducts.php index fbcc712..67ce843 100755 --- a/widgets/similarProducts.php +++ b/widgets/similarProducts.php @@ -22,8 +22,9 @@ public function run() { - $products = ProductHelper::getSimilarProducts($this->product, $this->count); - + $products = ProductHelper::getSimilarProducts($this->product, $this->count)->all(); + + if (!$this->title) { $this->title = Yii::t('product', 'Similar products'); } diff --git a/widgets/views/product_smart.php b/widgets/views/product_smart.php index a4064a3..340993a 100755 --- a/widgets/views/product_smart.php +++ b/widgets/views/product_smart.php @@ -1,111 +1,260 @@ -