-- Product combination management ---------------------------------------
485411
public function getAttributeValuesAction(/** @noinspection PhpUnusedParameterInspection */ $productId, $attributeId)
    {
        $result = array();

        // Get attribute for this product
        $attribute = AttributeQuery::create()->findPk($attributeId);

        if ($attribute !== null) {
            $values = AttributeAvQuery::create()
                ->joinWithI18n($this->getCurrentEditionLocale())
                ->filterByAttribute($attribute)
                ->find();
            ;

            if ($values !== null) {
                /** @var AttributeAv $value */
                foreach ($values as $value) {
                    $result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
                }
            }
        }

        return $this->jsonResponse(json_encode($result));
    }
683114
public void combine(SimpleItem other)
    {
        for (Map.Entry<String, Integer> entry : other.labelMap.entrySet())
        {
            addLabel(entry.getKey(), entry.getValue());
        }
    }
207268
def _all_combos(self):
        
        combos = _product(self.dims)
        if not combos:
            return

        calc = [(coalesce(_product(self.dims[i+1:]), 1), mm) for i, mm in enumerate(self.dims)]

        for c in xrange(combos):
            yield tuple(int(c / dd) % mm for dd, mm in calc)
903070
def _combine(self, applied):
        """"""
        applied_example, applied = peek_at(applied)
        coord, dim, positions = self._infer_concat_args(applied_example)
        combined = concat(applied, dim)
        combined = _maybe_reorder(combined, dim, positions)
        if coord is not None:
            combined[coord.name] = coord
        combined = self._maybe_restore_empty_groups(combined)
        combined = self._maybe_unstack(combined)
        return combined
905586
def _add_products(self, tile, show_all=False):
        """"""

        products = tile.products
        unique_id = tile.unique_id
        base_path = tile.output_folder

        for prod_path, prod_type in products.items():
            # We need to handle include_directories and tilebus_definitions
            # specially since those are stored reversed in module_settings.json
            # for historical reasons.  Currently we don't support resolving
            # tilebus_definitions or include_directories in ProductResolver
            if prod_path == 'tilebus_definitions' or prod_path == 'include_directories':
                continue

            if prod_type in self.IGNORED_PRODUCTS:
                continue

            prod_base = os.path.basename(prod_path)
            if prod_type not in self._product_map:
                self._product_map[prod_type] = {}

            prod_map = self._product_map[prod_type]
            if prod_base not in prod_map:
                prod_map[prod_base] = []

            full_path = os.path.normpath(os.path.join(base_path, prod_path))
            info = ProductInfo(prod_base, full_path, unique_id, not show_all and prod_base not in self._product_filter)
            prod_map[prod_base].append(info)
1076095
@Override
    public DecisionType combine(DecisionType op1, DecisionType op2) {
        if (op1 == DecisionType.Permit || op2 == DecisionType.Permit) {
            return DecisionType.Permit;
        }

        if ((op1 == DecisionType.Indeterminate_DP) || (op2 == DecisionType.Indeterminate_DP)) {
            return DecisionType.Indeterminate_DP;
        }

        if (op1 == DecisionType.Indeterminate_P) {
            if (op2 == DecisionType.Deny || op2 == DecisionType.Indeterminate_D) {
                return DecisionType.Indeterminate_DP;
            } else {
                return DecisionType.Indeterminate_P;
            }
        }

        if (op2 == DecisionType.Indeterminate_P) {
            if (op1 == DecisionType.Deny || op1 == DecisionType.Indeterminate_D) {
                return DecisionType.Indeterminate_DP;
            } else {
                return DecisionType.Indeterminate_P;
            }
        }

        if (op1 == DecisionType.Deny || op2 == DecisionType.Deny) {
            return DecisionType.Deny;
        }

        if (op1 == DecisionType.Indeterminate_D || op2 == DecisionType.Indeterminate_D) {
            return DecisionType.Indeterminate_D;
        }

        return DecisionType.NotApplicable;
    }
532115
public function actionGetProductCombination($values, $productId, $currencyFormatting = false) {
        /** @var CartComponent $cart */
        $cart = \Yii::$app->cart;

        $values = Json::decode($values);
        $combination = $cart->getCombination($values, $productId);
        if (!empty($combination)) {
            $oldPrice = $combination->price->oldPrice ?? '';
            $newPrice = $combination->price->discountPrice ?? '';
            if ($currencyFormatting) {
                $oldPrice = Yii::$app->formatter->asCurrency($oldPrice);
                $newPrice = Yii::$app->formatter->asCurrency($newPrice);
            }

            $availability = $combination->combinationAvailability->translation->title
                ?? $combination->product->productAvailability->translation->title ?? '';
            $description = (!empty($combination->translation->description))
                ? $combination->translation->description
                : $combination->product->translation->full_text ?? '';

            $array = [
                'image' => $combination->images[0]->productImage->thumb ?? '',
                'images' => $combination->getImagesArray() ?? '',
                'oldPrice' => $oldPrice,
                'newPrice' => $newPrice,
                'sku' => $combination->sku ?? '',
                'availability' => $availability,
                'description' => $description,
                'prices' => $combination->combinationPrices
            ];
        }
        else return 0;

        return Json::encode($array);
    }
714860
public function isContainsProduct($productId, $combinationId = null)
    {
        if (Yii::$app->user->isGuest) {
            if (!empty(Yii::$app->session[self::SESSION_KEY])) {
                $sessionProducts = Yii::$app->session[self::SESSION_KEY];

                foreach ($sessionProducts as $item) {
                    $condition = (empty($combinationId))
                        ? (ArrayHelper::getValue($item, 'id') == $productId)
                        : (ArrayHelper::getValue($item, 'id') == $productId && ArrayHelper::getValue($item, 'combinationId') == $combinationId);

                    if($condition) {
                        return $condition;
                    }
                }
            }
        } else {
            /** @var Order $order */
            $order = Order::find()
                ->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                ->one();

            if (!empty($order)) {
                $condition = (empty($combinationId))
                    ? ['order_id' => $order->id, 'product_id' => $productId]
                    : ['order_id' => $order->id, 'product_id' => $productId, 'combination_id' => $combinationId];

                $product = OrderProduct::find()
                    ->where($condition)
                    ->one();

                return (!empty($product));
            }
        }

        return false;
    }
260912
function getAllCombinations () {
  var combinations = [];
  date.forEach(function (tf) {
    resolution.forEach(function (rf) {
      dataType.forEach(function (sf) {
        combinations.push(getCombination(tf, rf, sf));
      });
    });
  });

  return combinations;
}
160089
def get_combination_action(combination):
    
    accepted_actions = ('link', 'js')
    for action in accepted_actions:
        if action in combination:
            return {action: combination[action]}
    return {}
160782
def _combine(self, original, loc, tokens):
        """"""
        combined_tokens = super(CombineNode, self).postParse(original, loc, tokens)
        internal_assert(len(combined_tokens) == 1, "Combine produced multiple tokens", combined_tokens)
        return combined_tokens[0]
589695
public function actionRemoveCombination(int $combinationId)
    {
        $combination = Combination::findOne($combinationId);
        if (empty($combination)) throw new NotFoundHttpException('Such combination does not exists');
        $productId = $combination->product_id;

        if (!empty($combination)) {
            $combination->delete();
            if (Combination::find()->where(['product_id' => $productId])->count() == 1) {
                $combination = Combination::find()->where(['product_id' => $productId])->one();
                $combination->default = 1;
                if ($combination->validate()) $combination->save();
            }

            $eventName = self::EVENT_AFTER_EDIT_PRODUCT;
            $this->trigger($eventName, new ProductEvent([
                'id' => $combination->product_id
            ]));

        } else throw new NotFoundHttpException();

        return $this->redirect(\Yii::$app->request->referrer);
    }
307165
protected function validateCombinationSkuProduct($index, &$combination)
    {
        if (!isset($combination['sku'])) {
            return null;
        }

        if ($combination['sku'] === '') {
            return true;
        }

        $updating = $this->getUpdating();

        $product_id = null;

        if (isset($updating['product_id'])) {
            $product_id = $updating['product_id'];
        }

        if (mb_strlen($combination['sku']) > 255) {
            $this->setErrorLengthRange("combination.$index.sku", $this->translation->text('SKU'), 0, 255);
            return false;
        }

        if (isset($this->processed_skus[$combination['sku']])) {
            $error = $this->translation->text('SKU must be unique per store');
            $this->setError("combination.$index.sku", $error);
            return false;
        }

        $store_id = $this->getSubmitted('store_id');
        $existing = $this->sku->get(array('sku' => $combination['sku'], 'store_id' => $store_id));

        if (isset($product_id) && isset($existing['product_id']) && $existing['product_id'] == $product_id) {
            $this->processed_skus[$combination['sku']] = true;
            return true;
        }

        if (!empty($existing)) {
            $error = $this->translation->text('SKU must be unique per store');
            $this->setError("combination.$index.sku", $error);
            return false;
        }

        $this->processed_skus[$combination['sku']] = true;
        return true;
    }
496555
public void setProductViewAggregations(java.util.Map<String, java.util.List<ProductViewAggregationValue>> productViewAggregations) {
        this.productViewAggregations = productViewAggregations;
    }
400287
public function actionEditCombination(int $combinationId, int $languageId)
    {
        $combination = Combination::findOne($combinationId);
        if (empty($combination)) throw new NotFoundHttpException();

        $combinationTranslation = CombinationTranslation::find()->where([
            'combination_id' => $combination->id, 'language_id' => $languageId
        ])->one();
        if (empty($combinationTranslation)) {
            $combinationTranslation = new CombinationTranslation();
            $combinationTranslation->combination_id = $combination->id;
            $combinationTranslation->language_id = $languageId;
        }

        $imageForm = new CombinationImageForm();
        $productImages = ProductImage::find()->where(['product_id' => $combination->product_id])->all();
        $combinationImages = CombinationImage::find()->where(['combination_id' => $combination->id])->all();

        $combinationAttributeForm = new CombinationAttributeForm();
        $combinationAttributes = CombinationAttribute::find()
            ->where(['combination_id' => $combination->id])->all();

        $prices = [];
        $userGroups = UserGroup::find()->all();
        foreach ($userGroups as $userGroup) {
            $price = Price::find()->joinWith('combinationPrice')
                ->where(['combination_id' => $combination->id, 'user_group_id' => $userGroup->id])->one();
            if (empty($price)) {
                $price = new Price();
                if ($price->validate()) $price->save();
                $combinationPrice = new CombinationPrice();
                $combinationPrice->combination_id = $combination->id;
                $combinationPrice->user_group_id = $userGroup->id;
                $combinationPrice->price_id = $price->id;
                if ($combinationPrice->validate()) $combinationPrice->save();

            }
            $prices[$price->id] = $price;
        }

        if (\Yii::$app->request->isPost) {

            $this->trigger(self::EVENT_BEFORE_EDIT_PRODUCT, new ProductEvent([
                'id' => $combination->product_id
            ]));

            $post = \Yii::$app->request->post();
            if ($combination->load($post)) {
                if ($combination->validate()) $combination->save();

                $combination->setDefaultOrNotDefault();

                if ($combinationTranslation->load($post) && $combinationTranslation->validate())
                    $combinationTranslation->save();

                /*Saving prices*/
                if (Model::loadMultiple($prices, Yii::$app->request->post()) && Model::validateMultiple($prices)) {
                    foreach ($prices as $price) {
                        $price->save(false);
                    }
                }

                $this->loadCombinationAttributeForm($combination, $post, $combinationAttributeForm, new CombinationAttribute());
                $this->saveCombinationImages($imageForm, $post, $combinationImages, $combination, false, $productImages);

                $this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent([
                    'id' => $combination->product_id
                ]));

                $this->redirect(['add-combination',
                    'productId' => $combination->product_id,
                    'languageId' => $languageId
                ]);
            }
        }

        return $this->render('../product/save', [
            'viewName' => '../combination/edit-combination',
            'selectedLanguage' => Language::findOne($languageId),
            'product' => Product::findOne($combination->product_id),
            'languages' => Language::find()->all(),

            'params' => [
                'combination' => $combination,
                'combinationTranslation' => $combinationTranslation,
                'product' => Product::findOne($combination->product_id),
                'productImages' => $productImages,

                'image_form' => $imageForm,
                'combinationImagesIds' => ArrayHelper::getColumn($combinationImages, 'product_image_id'),

                'languageId' => $languageId,
                'combinationAttributes' => $combinationAttributes,
                'combinationAttributeForm' => $combinationAttributeForm,
                'prices' => $prices
            ]
        ]);
    }
346787
def _combine_costs(self, Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl,
                       Npol, Hpol, Cpol, fparm_pol, npol, nw):
        
        NN = vstack([n for n in [Npwl, Npol] if n is not None], "csr")

        if (Hpwl is not None) and (Hpol is not None):
            Hpwl = hstack([Hpwl, csr_matrix((any_pwl, npol))])
            Hpol = hstack([csr_matrix((npol, any_pwl)), Hpol])
#        if H is not None:
#            H = hstack([csr_matrix((nw, any_pwl+npol)), H])

        HHw = vstack([h for h in [Hpwl, Hpol] if h is not None], "csr")

        CCw = r_[Cpwl, Cpol]

        ffparm = r_[fparm_pwl, fparm_pol]

        return NN, HHw, CCw, ffparm
633639
public void setProductCodes(java.util.Collection<ProductCode> productCodes) {
        if (productCodes == null) {
            this.productCodes = null;
            return;
        }

        this.productCodes = new java.util.ArrayList<ProductCode>(productCodes);
    }