@param array|JsonSerializable|Product $data
@param null $productId

@return Product
484155
public function create($data, $productId = null)
    {
        if (isset($productId)) {
            return $this->client()->put($data, 'products/{productId}', ['productId' => $productId]);
        }

        return $this->client()->post($data, 'products');
    }
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
            ]
        ]);
    }
269517
public function getAction(Request $request, $productId)
    {
        $locale = $request->get('locale');
        $product = $this->fetchProduct($productId);

        $content = $this->getProductContentMapper()->get($product, $locale);

        $view = $this->view($content, Response::HTTP_OK);

        return $this->handleView($view);
    }
1218313
public function putAction(Request $request, $productId)
    {
        $locale = $request->get('locale');
        $parameters = $request->request->all();

        $product = $this->fetchProduct($productId);

        $content = $this->getProductContentMapper()->map($product, $parameters, $locale);
        $this->getEntityManager()->flush();

        $view = $this->view($content, Response::HTTP_OK);

        return $this->handleView($view);
    }
1264680
public function postAction(Request $request, $productId)
    {
        $locale = $this->getLocale($request);
        $mediaId = $request->get('mediaId', '');

        try {
            $em = $this->getDoctrine()->getManager();
            /** @var Product $product */
            $product = $this->getProductManager()->findByIdAndLocale($productId, $locale);
            $media = $this->getMediaManager()->getById($mediaId, $locale);

            if (!$product) {
                throw new EntityNotFoundException($this->getProductEntityName(), $productId);
            }

            if (!$media) {
                throw new EntityNotFoundException($this->getMediaEntityName(), $mediaId);
            }

            if ($product->containsMedia($media)) {
                throw new RestException('Relation already exists');
            }

            //FIXME this is just a temporary solution
            // issue https://github.com/massiveart/POOL-ALPIN/issues/1467
            $this->removeDefaultPrices($product);
            $product->addMedia($media);
            $em->flush();

            $view = $this->view($media, 200);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        } catch (\Exception $e) {
            $view = $this->view($e->getMessage(), 400);
        }

        return $this->handleView($view);
    }
1264541
public function getProductName($productId): ?string
    {
        $product = $this->productRepository->find($productId);
        if (!$product instanceof ProductInterface) {
            return null;
        }

        return $product->getName();
    }
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;
    }
148547
public function create($data, $cardId = null)
    {
        if (isset($cardId)) {
            return $this->client()->put($data, 'payment-cards/{cardId}', ['cardId' => $cardId]);
        }

        return $this->client()->post($data, 'payment-cards');
    }
56226
protected function addListItems( $productId, array $productIds )
	{
		if( empty( $productIds ) ) {
			return;
		}

		$manager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' );
		$item = $manager->createItem();

		foreach( $productIds as $pos => $refid )
		{
			$item->setId( null );
			$item->setParentId( $productId );
			$item->setDomain( 'product' );
			$item->setType( 'bought-together' );
			$item->setPosition( $pos );
			$item->setRefId( $refid );
			$item->setStatus( 1 );

			$manager->saveItem( $item, false );
		}
	}
162653
private function getSearchableProducts($storeId, $productIds = null, $fromId = 0, $limit = 10000)
    {
        return $this->resourceModel->getSearchableProducts($storeId, $productIds, $fromId, $limit);
    }
1214945
public function rebuildStoreIndex($storeId, $productIds = null)
    {
        $productId = 0;

        // Magento is only sending children ids here. Ensure to reindex also the parents product ids, if any.
        if (!empty($productIds)) {
            $productIds = array_unique(array_merge($productIds, $this->resourceModel->getRelationsByChild($productIds)));
        }

        do {
            $products = $this->getSearchableProducts($storeId, $productIds, $productId);

            foreach ($products as $productData) {
                $productId = (int) $productData['entity_id'];
                $productData['has_options']      = (bool) $productData['has_options'];
                $productData['required_options'] = (bool) $productData['required_options'];
                yield $productId => $productData;
            }
        } while (!empty($products));
    }
695918
public function delete($productId, ProductImage $productImage)
    {
        $endpoint = '/admin/products/'.$productId.'/images/'.$productImage->id.'.json';
        return $this->request($endpoint, 'DELETE');
    }
748503
public function deleteImage($productId)
    {
        $productId = (int) $productId;

        if ($productId == 0 || $productId == '') {
            $message = 'Product ID not correct: ' . $productId;
            $this->log($message);
            die(json_encode([
                'status' => 0,
                'msg' => $message
            ]));
        }

        $product = $this->Product->find('all', [
            'conditions' => [
                'Products.id_product' => $productId
            ],
            'contain' => [
                'Images',
                'Manufacturers'
            ]
        ])->first();
        
        $this->Product->changeImage(
            [
                [$productId => 'no-image']
            ]
        );

        $actionLogMessage = __d('admin', 'Image_ID_{0}_from_manufacturer_{1}_was_deleted_successfully_Product_{1}_Manufacturer_{2}.', [
            $product->image->id_image,
            '<b>' . $product->name . '</b>',
            '<b>' . $product->manufacturer->name . '</b>'
        ]);

        $this->Flash->success($actionLogMessage);
        $this->ActionLog->customSave('product_image_deleted', $this->AppAuth->getUserId(), $productId, 'products', $actionLogMessage);

        $this->getRequest()->getSession()->write('highlightedRowId', $productId);

        $this->redirect($this->referer());
    }
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);
    }
1026101
public function findByAttributeIdAndProductId($attributeId, $productId)
    {
        try {
            $queryBuilder = $this->createQueryBuilder('productAttribute')
                ->leftJoin('productAttribute.attribute', 'attribute')
                ->leftJoin('productAttribute.product', 'product')
                ->andWhere('attribute.id = :attributeId')
                ->andWhere('product.id = :productId')
                ->setParameter('attributeId', $attributeId)
                ->setParameter('productId', $productId);

            return $queryBuilder->getQuery()->getSingleResult();
        } catch (NoResultException $exc) {
            return null;
        }
    }
248318
protected function getCategoryProductSelect($productIds, $storeId)
    {
        $select = $this->getConnection()->select()
            ->from(['cpi' => $this->getTable($this->getCategoryProductIndexTable($storeId))])
            ->where('cpi.store_id = ?', $storeId)
            ->where('cpi.product_id IN(?)', $productIds);

        return $select;
    }
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;
    }