@param $productId
@param $slug

@throws NotFoundHttpException

@return Response
336200
public function viewAction($productId, $slug)
    {
        $product = $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug);

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

        /** @var \Sonata\Component\Product\Pool $productPool */
        $productPool = $this->get('sonata.product.pool');
        $provider = $productPool->getProvider($product);

        if ($provider->hasVariations($product)) {
            if (!$provider->hasEnabledVariations($product)) {
                throw new NotFoundHttpException('Product has no activated variation');
            }
            // We display the cheapest variation
            $product = $provider->getCheapestEnabledVariation($product);
        }

        $action = sprintf('%s:view', $provider->getBaseControllerName());
        $response = $this->forward($action, [
            'provider' => $provider,
            '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;
    }
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
            ]
        ]);
    }
689142
public function actionIndex($slug = 'product')
    {
        if (!is_product_type_slug($slug)) {
            throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
        }
        $product_type = ProductType::find()
            ->where(['slug' => $slug])
            ->one();
        $searchModel = new ProductSearch();
        $queryParams = request()->queryParams;
        $queryParams['ProductSearch']['product_type'] = $product_type->name;
        $dataProvider = $searchModel->search($queryParams);
        $dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
        view()->title = t('app', $product_type->name);

        return $this->render('index', [
            'searchModel'  => $searchModel,
            'dataProvider' => $dataProvider,
            'product_type' => $product_type,
        ]);
    }
238934
public function getProductAddonsAction(Request $request, $productId)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        if ($request->get('flat') == 'true') {
            $fieldDescriptors = $this->getFieldDescriptors($locale);
            $listBuilder = $this->getListBuilder(self::$entityName, $fieldDescriptors);
            $listBuilder->where($fieldDescriptors['productId'], $productId);

            $list = new ListRepresentation(
                $listBuilder->execute(),
                'addons',
                'get_product_addons',
                array_merge($request->query->all(), ['productId' => $productId]),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $addons = $this->getManager()->findAddonsByProductIdAndLocale($productId, $locale);
            $list = new CollectionRepresentation(
                $addons,
                'addons'
            );
        }

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

        return $this->handleView($view);
    }
695918
public function delete($productId, ProductImage $productImage)
    {
        $endpoint = '/admin/products/'.$productId.'/images/'.$productImage->id.'.json';
        return $this->request($endpoint, 'DELETE');
    }
1013358
public function loadById($productId)
    {
        return $this->productRepository->getById($productId, false, $this->storeManager->getStore()->getId(), true);
    }
1241493
public function assignProduct($categoryId, $productId, $position = null, $identifierType = null)
    {
        return $this->__createAction('catalog_category.assignProduct', func_get_args());
    }
992818
public function actionShow($id, $slug)
    {
        $model = $this->model->node($id);
        if (empty($model) || !$model->is_visible || $model->slug != $slug) {
            throw new NotFoundHttpException(Yii::t($this->tcModule, 'Content not found'));
        }
        
        return $this->actionView($id, true, null, true, false, true);
    }
285132
public function getCombinations(string $productId, Context $context)
    {
        return new JsonResponse(
            $this->combinationLoader->load($productId, $context)
        );
    }
508738
public function actionCreate($slug = 'product')
    {
        if (!is_product_type_slug($slug)) {
            throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
        }
        $product_type = ProductType::find()
            ->where(['slug' => $slug])
            ->one();
        $model = new Product();
        $model->author = get_current_user_id();
        $model->status = STATUS_PUBLIC;
        $model->language = get_primary_language();
        $model->comment_status = STATUS_ENABLE;
        $model->rating_status = STATUS_ENABLE;
        $model->product_type = $slug;
        $model->unit = Product::UNIT_1_PRODUCT;
        $model->currency_unit = 'USD';
        $model->id = 0;
        $model->product_type = $slug;
        if ($model->loadAll(request()->post())) {
            if ($model->saveAll()) {
                set_flash_has_been_saved();
                create_all_term_relationships_of_all_term_type_of_product_type($model->product_type, $model->primaryKey);
                create_all_meta_of_all_product_type_meta($model->product_type, $model->primaryKey);

                return $this->redirect([
                    'update',
                    'id' => $model->id,
                ]);
            } else {
                set_flash_has_not_been_saved();
            }
        }

        return $this->render('create', [
            'model' => $model,
            'product_type' => $product_type
        ]);
    }
703977
public function delete($productId, $force = null)
    {
        $options = (object)[];
        $options->qs = [ "force" => ($force ? "true" : "false") ];

        return $this->client->delete("/products/" . rawurlencode($productId), null, $options);
    }
1297968
public function getRatingsByProductId($productId)
    {
        $queryBuilder = $this->queryBuilderFactory->create();
        $queryBuilder
            ->select('r.*')
            ->from('oxratings', 'r')
            ->where('r.oxobjectid = :productId')
            ->andWhere('r.oxtype = :productType')
            ->orderBy('r.oxtimestamp', 'DESC')
            ->setParameters(
                [
                    'productId'     => $productId,
                    'productType'   => 'oxarticle',
                ]
            );

        return $this->mapRatings($queryBuilder->execute()->fetchAll());
    }
1174884
public function deleteAction($productId, $attributeId)
    {
        $this->getVariantAttributeManager()->removeVariantAttributeRelation(
            $productId,
            $attributeId
        );

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

        $view = $this->view(null, Response::HTTP_NO_CONTENT);

        return $this->handleView($view);
    }
1037707
public function updateSku($productId, $sku)
    {
        $skuId = "";

        if (is_array($sku)) {
            $skuId = $sku["id"];
            unset($sku["id"]);
        }
        elseif (is_object($sku)) {
            $skuId = $sku->id;
            unset($sku->id);
        }

        return $this->client->put("/products/" . rawurlencode($productId) . "/skus/" . rawurlencode($skuId), $sku);
    }
1006555
public function uploadAction(Product $product)
    {
        if (!$product) {
            throw $this->createNotFoundException('Unable to find Product entity.');
        }

        $productService = $this->get('amulen.shop.product');
        $response = $productService->uploadImage($product);

        $httpResponse = Response::HTTP_BAD_REQUEST;

        if ($response['upload_ok'] != 0) {
            $path = $response['target_file'];
            $em = $this->getDoctrine()->getManager();
            $mediaTypeRepository = $em->getRepository(MediaType::class);

            $mediaType = $mediaTypeRepository->findOneBy([
                'name' => 'image'
            ]);

            $media = new Media();
            $name = basename($_FILES["file"]["name"]);
            $slugName = strtolower(str_replace(' ','-',$name));
            $media->setName($slugName);
            $media->setPath($path);
            $media->setMediaType($mediaType);
            $em->persist($media);

            $galleryItem = new GalleryItem();
            $gallery = $product->getMediaGallery();
            $gallery->addGalleryItem($galleryItem);
            $galleryItem->setGallery($gallery);
            $galleryItem->setMedia($media);
            $position = $gallery->getGalleryItems()->count() + 1;
            $galleryItem->setPosition($position);

            $em->persist($galleryItem);
            $em->flush();
            $httpResponse = Response::HTTP_OK;
        }

        if ($response['upload_ok'] == 2) {
            $httpResponse = Response::HTTP_BAD_REQUEST;
        }

        return new JsonResponse($response['message'], $httpResponse);
    }
345351
public function count($productId, array $params = array())
    {
        $endpoint = '/admin/products/'.$productId.'/images/count.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $response['count'];
    }
471029
protected function updateProduct($product_id)
    {
        if (!$this->isError() && !$this->product->update($product_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }