Commit 72ce46f7c1bc96b81400ec9142bfad6686783d1b

Authored by Anastasia
1 parent 5fb852db

options in basket

Showing 1 changed file with 43 additions and 0 deletions   Show diff stats
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 4
5 use artbox\catalog\models\Variant; 5 use artbox\catalog\models\Variant;
6 use yii\base\Component; 6 use yii\base\Component;
  7 + use yii\db\ActiveQuery;
7 use yii\helpers\Json; 8 use yii\helpers\Json;
8 use yii\web\Cookie; 9 use yii\web\Cookie;
9 use yii\web\NotFoundHttpException; 10 use yii\web\NotFoundHttpException;
@@ -263,6 +264,48 @@ @@ -263,6 +264,48 @@
263 ->indexBy('id') 264 ->indexBy('id')
264 ->all(); 265 ->all();
265 } 266 }
  267 +
  268 + public function findModelsWithOptions(array $variant_ids)
  269 + {
  270 + if (empty($variant_ids)) {
  271 + return [];
  272 + }
  273 + return Variant::find()
  274 + ->where([ 'variant.id' => $variant_ids ])
  275 + ->joinWith(
  276 + [
  277 + 'variantOptionExcls' => function (ActiveQuery $query) {
  278 + $query->with(
  279 + [
  280 + 'group',
  281 + 'lang',
  282 + ]
  283 + );
  284 + },
  285 + ]
  286 + )
  287 + ->joinWith('lang')
  288 + ->joinWith(
  289 + [
  290 + 'product' => function ($query) {
  291 + /**
  292 + * @var \yii\db\ActiveQuery $query
  293 + */
  294 + $query->with(
  295 + [
  296 + 'lang',
  297 + 'image',
  298 + ]
  299 + );
  300 + },
  301 + ]
  302 + )
  303 + ->with(
  304 + 'image'
  305 + )
  306 + ->indexBy('id')
  307 + ->all();
  308 + }
266 309
267 /** 310 /**
268 * Clear basket 311 * Clear basket