@param \TdbShopArticle $product
@param string          $variantNameType
@param string          $languageId

@return string
343171
private function generateNameForLanguage(\TdbShopArticle $product, $variantNameType, $languageId)
    {
        $variantValues = $product->GetFieldShopVariantTypeValueList();
        $variantValues->SetLanguage($languageId);
        $variantValues->GoToStart();
        $nameParts = [];
        while ($variantValue = $variantValues->Next()) {
            if (self::VARIANT_NAME_TYPE_URL === $variantNameType) {
                $nameParts[] = $variantValue->GetURLString();
            } else {
                $nameParts[] = $variantValue->fieldName;
            }
        }
        $variantValues->GoToStart();
        if (self::VARIANT_NAME_TYPE_URL === $variantNameType) {
            $glue = '/';
        } else {
            $glue = ', ';
        }

        return \implode($glue, $nameParts);
    }
1152638
public function setName($contentId, $version, $name, $language)
    {
        try {
            return $this->innerGateway->setName($contentId, $version, $name, $language);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
361175
public function getPage(int $uid, int $languageUid = null) {
    $page   = null;
    $record = $this->pageRepository->getPage($uid);

    if (is_array($record) && !empty($record)) {
      if (in_array($record['doktype'], self::PAGE_DOKTYPES)) {
        $page        = $record;
        $languageUid = isset($languageUid) ? $languageUid : $this->languageService->getLanguageUid();

        if ($languageUid > 0) {
          $page = $this->pageRepository->getPageOverlay($page, $languageUid);
        }
      }
    }

    return $page;
  }
44355
public function actionAddAdditional(int $productId, int $languageId)
    {
        $additionalProductsCategories = Category::find()->with('products')
            ->where(['additional_products' => true])->all();

        $productAdditionalProducts = ProductAdditionalProduct::find()->where(['product_id' => $productId])->all();
        return $this->render('../product/save', [
            'viewName' => '../additional-product/add-additional',
            'selectedLanguage' => Language::findOne($languageId),
            'product' => Product::findOne($productId),
            'languages' => Language::find()->all(),

            'params' => [
                'additionalProductsCategories' => $additionalProductsCategories,
                'productAdditionalProducts' => $productAdditionalProducts,
                'productId' => $productId
            ]
        ]);
    }
1024505
public function deleteTranslationFromVersion($contentId, $versionNo, $languageCode)
    {
        $language = $this->languageHandler->loadByLanguageCode($languageCode);

        $this->connection->beginTransaction();
        try {
            $this->deleteTranslationFromContentVersions($contentId, $language->id, $versionNo);
            $this->deleteTranslationFromContentNames($contentId, $languageCode, $versionNo);

            $this->connection->commit();
        } catch (DBALException $e) {
            $this->connection->rollBack();
            throw $e;
        }
    }
41782
public function references($language, $product)
    {
        return $this->request(sprintf('products/%s/%s/references?page=%d', $language, $this->transform($product), 1));
    }
723083
public function actionList(int $productId, int $languageId)
    {

        $product = Product::findOne($productId);
        $products = Product::find()->joinWith('translations')->orderBy('title')->all();
        $relatedProducts = $product->relatedProducts;
        $newRelatedProduct = new RelatedProduct();

        $selectedLanguage = Language::findOne($languageId);
        $languages = Language::find()->all();

        if (\Yii::$app->request->isPost && $newRelatedProduct->load(\Yii::$app->request->post())) {
            if (empty(RelatedProduct::find()
                ->where(['product_id' => $productId, 'related_product_id' => $newRelatedProduct->related_product_id])->one())
            ) {

                $newRelatedProduct->product_id = $productId;
                if ($newRelatedProduct->validate()) $newRelatedProduct->save();
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Relation product has added successfully'));
            } else {
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Such relation product already exists for this product'));
            }

            return $this->redirect(\Yii::$app->request->referrer);
        }

        return $this->render('../product/save', [
            'viewName' => '../related-product/list',
            'selectedLanguage' => $selectedLanguage,
            'product' => $product,
            'languages' => $languages,

            'params' => [
                'product' => $product,
                'products' => $products,
                'relatedProducts' => $relatedProducts,
                'newRelatedProduct' => $newRelatedProduct,
                'languages' => $languages,
                'selectedLanguage' => $selectedLanguage,
            ]
        ]);
    }
895444
public static function display_name($component, $itemtype) {
        $identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
        if ($component === 'core') {
            $component = 'tag';
        }
        return new lang_string($identifier, $component);
    }
634532
public function viewVariationsAction($productId, $slug)
    {
        $product = \is_object($productId) ? $productId : $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug);

        if (!$product) {
            throw new NotFoundHttpException(sprintf('Unable to find the product with id=%d', $productId));
        }

        $provider = $this->get('sonata.product.pool')->getProvider($product);

        $action = sprintf('%s:viewVariations', $provider->getBaseControllerName());
        $response = $this->forward($action, [
                'product' => $product,
            ]);

        if ($this->get('kernel')->isDebug()) {
            $response->setContent(sprintf("\n<!-- [Sonata] Product code: %s, id: %s, action: %s  -->\n%s\n<!-- [Sonata] end product -->\n",
                $this->get('sonata.product.pool')->getProductCode($product),
                $product->getId(),
                $action,
                $response->getContent()
            ));
        }

        return $response;
    }
513540
public function removeVariantAttributeRelation($productId, $attributeId)
    {
        $variant = $this->retrieveProductById($productId);
        $attribute = $this->retrieveAttributeById($attributeId);

        if (!$variant->getVariantAttributes()->contains($attribute)) {
            throw new ProductException('Variant does not have relation to attribute');
        }

        $variant->removeVariantAttribute($attribute);

        return $variant;
    }
227786
public function findOneLanguageTitleByLanguageId(int $languageId) : string
    {
        $queryBuilder = $this->getQueryBuilder();
        $result = $queryBuilder->select('title')
            ->from($this->table)
            ->where($queryBuilder->expr()->eq('uid', $languageId))
            ->execute()->fetch();

        if ($result == false && $languageId == 0) {
            return 'default';
        }

        return isset($result['title']) ? $result['title'] : '';
    }
621506
public function removeLocalesFromProduct($locales, $product){
		$timeStamp = time();
		$response = $this->getProduct($product);
		if ($response->error->exist) {
			return $response;
		}
		$product = $response->result->set;
		$idsToRemove = array();
		$mModel = new MLSService\MultiLanguageSupportModel($this->kernel, $this->dbConnection, $this->orm);
		foreach ($locales as $locale) {
			$response = $mModel->getLanguage($locale);
			if ($response->error->exist) {
				continue;
			}
			$idsToRemove[] = $response->result->set->getId();
		}
		$in = ' IN (' . implode(',', $idsToRemove) . ')';
		$qStr = 'DELETE FROM ' . $this->entity['apl']['name'] . ' ' . $this->entity['apl']['alias']
			. ' WHERE ' . $this->entity['apl']['alias'] . '.product = ' . $product->getId()
			. ' AND ' . $this->entity['apl']['alias'] . '.locale ' . $in;

		$q = $this->em->createQuery($qStr);
		$result = $q->getResult();

		$deleted = true;
		if (!$result) {
			$deleted = false;
		}
		if ($deleted) {
			return new ModelResponse(null, 0, 0, null, false, 'S:D:001', 'Selected entries have been successfully removed from database.', $timeStamp, time());
		}
		return new ModelResponse(null, 0, 0, null, true, 'E:E:001', 'Unable to delete all or some of the selected entries.', $timeStamp, time());
	}
635438
public function getAction(Request $request, $parentId, $variantId)
    {
        $locale = $this->getLocale($request);
        $view = $this->responseGetById(
            $variantId,
            function ($id) use ($locale, $parentId) {
                $product = $this->getProductManager()->findByIdAndLocale($id, $locale);

                if ($product !== null && $product->getParent() && $product->getParent()->getId() == $parentId) {
                    return $product;
                } else {
                    return null;
                }
            }
        );

        return $this->handleView($view);
    }
995809
public function getVirtualDocumentListAjaxAction($productId, $pseId)
    {
        $this->checkAuth(AdminResources::PRODUCT, array(), AccessManager::VIEW);
        $this->checkXmlHttpRequest();

        $selectedId = \intval(MetaDataQuery::getVal('virtual', MetaData::PSE_KEY, $pseId));

        $documents = ProductDocumentQuery::create()
            ->filterByProductId($productId)
            ->filterByVisible(0)
            ->orderByPosition()
            ->find()
        ;

        $results = [];

        if (null !== $documents) {
            /** @var ProductDocument $document */
            foreach ($documents as $document) {
                $results[] = [
                    'id'       => $document->getId(),
                    'title'    => $document->getTitle(),
                    'file'     => $document->getFile(),
                    'selected' => ($document->getId() == $selectedId)
                ];
            }
        }

        return $this->jsonResponse(json_encode($results));
    }
886753
public function putAction(Request $request, $parentId, $variantId)
    {
        $requestData = $request->request->all();
        $userId = $this->getUser()->getId();
        $locale = $this->getLocale($request);

        $variant = $this->getProductVariantManager()->updateVariant(
            $variantId,
            $requestData,
            $locale,
            $userId
        );

        if ($variant->getParent()->getId() !== (int) $parentId) {
            throw new ProductException('Variant does not exists for given product.');
        }

        $this->getEntityManager()->flush();

        $apiVariant = $this->getProductFactory()->createApiEntity($variant, $locale);

        $view = $this->view($apiVariant, 200);

        return $this->handleView($view);
    }
809201
public function parent(\WC_Product $WC_Product)
    {
        if (!$WC_Product->exists()) {
            return null; // Not possible.
        }
        if ($WC_Product->is_type('variation')) {
            $WC_Parent_Product = wc_get_product($WC_Product->get_parent_id());
        } else {
            $WC_Parent_Product = null; // Not applicable.
        }
        return $WC_Parent_Product instanceof \WC_Product && $WC_Parent_Product->exists() ? $WC_Parent_Product : null;
    }
541845
public function deleteTranslatedFields($languageCode, $contentId, $versionNo = null)
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->delete('ezcontentobject_attribute')
            ->where('contentobject_id = :contentId')
            ->andWhere('language_code = :languageCode')
            ->setParameters(
                [
                    ':contentId' => $contentId,
                    ':languageCode' => $languageCode,
                ]
            )
        ;

        if (null !== $versionNo) {
            $query
                ->andWhere('version = :versionNo')
                ->setParameter(':versionNo', $versionNo)
            ;
        }

        $query->execute();
    }