Commit 04c33f0774b9ebba92a361a407d0a7948e6b5994
1 parent
1f5140e3
add create_item to translate
Showing
1 changed file
with
25 additions
and
5 deletions
Show diff stats
helpers/ProductHelper.php
| @@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | - * Add $product_id to last products in session. Limit 16 products. | 28 | + * Add $product_id to last products in session. |
| 29 | * | 29 | * |
| 30 | * @param int $product_id | 30 | * @param int $product_id |
| 31 | */ | 31 | */ |
| @@ -34,9 +34,6 @@ | @@ -34,9 +34,6 @@ | ||
| 34 | $last_products = self::getLastProducts(); | 34 | $last_products = self::getLastProducts(); |
| 35 | if (!in_array($product_id, $last_products)) { | 35 | if (!in_array($product_id, $last_products)) { |
| 36 | $last_products[] = intval($product_id); | 36 | $last_products[] = intval($product_id); |
| 37 | - if (count($last_products) > 16) { | ||
| 38 | - array_shift($last_products); | ||
| 39 | - } | ||
| 40 | Yii::$app->session->set('last_products', $last_products); | 37 | Yii::$app->session->set('last_products', $last_products); |
| 41 | } | 38 | } |
| 42 | } | 39 | } |
| @@ -54,7 +51,17 @@ | @@ -54,7 +51,17 @@ | ||
| 54 | $last_products = Yii::$app->session->get('last_products', []); | 51 | $last_products = Yii::$app->session->get('last_products', []); |
| 55 | if ($as_object) { | 52 | if ($as_object) { |
| 56 | $last_products = Product::find() | 53 | $last_products = Product::find() |
| 57 | - ->joinWith([ 'variant' ]) | 54 | + ->innerJoinWith( |
| 55 | + [ | ||
| 56 | + 'enabledVariants' => function ($query) { | ||
| 57 | + /** | ||
| 58 | + * @var ActiveQuery $query | ||
| 59 | + */ | ||
| 60 | + $query->joinWith('lang') | ||
| 61 | + ->with('images'); | ||
| 62 | + }, | ||
| 63 | + ] | ||
| 64 | + ) | ||
| 58 | ->where([ 'product.id' => $last_products ]) | 65 | ->where([ 'product.id' => $last_products ]) |
| 59 | ->andWhere( | 66 | ->andWhere( |
| 60 | [ | 67 | [ |
| @@ -68,6 +75,19 @@ | @@ -68,6 +75,19 @@ | ||
| 68 | } | 75 | } |
| 69 | return array_reverse($last_products); | 76 | return array_reverse($last_products); |
| 70 | } | 77 | } |
| 78 | + | ||
| 79 | + | ||
| 80 | + public static function trueWordForm($num, $form_for_1, $form_for_2, $form_for_5){ | ||
| 81 | + $num = abs($num) % 100; | ||
| 82 | + $num_x = $num % 10; | ||
| 83 | + if ($num > 10 && $num < 20) | ||
| 84 | + return $form_for_5; | ||
| 85 | + if ($num_x > 1 && $num_x < 5) | ||
| 86 | + return $form_for_2; | ||
| 87 | + if ($num_x == 1) | ||
| 88 | + return $form_for_1; | ||
| 89 | + return $form_for_5; | ||
| 90 | + } | ||
| 71 | 91 | ||
| 72 | /** | 92 | /** |
| 73 | * Get special Products array with ProductVariants, which are in stock | 93 | * Get special Products array with ProductVariants, which are in stock |