From 04c33f0774b9ebba92a361a407d0a7948e6b5994 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 23 Nov 2016 01:53:28 +0200 Subject: [PATCH] add create_item to translate --- helpers/ProductHelper.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/helpers/ProductHelper.php b/helpers/ProductHelper.php index 43c90bd..9de2906 100755 --- a/helpers/ProductHelper.php +++ b/helpers/ProductHelper.php @@ -25,7 +25,7 @@ } /** - * Add $product_id to last products in session. Limit 16 products. + * Add $product_id to last products in session. * * @param int $product_id */ @@ -34,9 +34,6 @@ $last_products = self::getLastProducts(); if (!in_array($product_id, $last_products)) { $last_products[] = intval($product_id); - if (count($last_products) > 16) { - array_shift($last_products); - } Yii::$app->session->set('last_products', $last_products); } } @@ -54,7 +51,17 @@ $last_products = Yii::$app->session->get('last_products', []); if ($as_object) { $last_products = Product::find() - ->joinWith([ 'variant' ]) + ->innerJoinWith( + [ + 'enabledVariants' => function ($query) { + /** + * @var ActiveQuery $query + */ + $query->joinWith('lang') + ->with('images'); + }, + ] + ) ->where([ 'product.id' => $last_products ]) ->andWhere( [ @@ -68,6 +75,19 @@ } return array_reverse($last_products); } + + + public static function trueWordForm($num, $form_for_1, $form_for_2, $form_for_5){ + $num = abs($num) % 100; + $num_x = $num % 10; + if ($num > 10 && $num < 20) + return $form_for_5; + if ($num_x > 1 && $num_x < 5) + return $form_for_2; + if ($num_x == 1) + return $form_for_1; + return $form_for_5; + } /** * Get special Products array with ProductVariants, which are in stock -- libgit2 0.21.4