Get a single product image

@link  https://help.shopify.com/api/reference/product_image#show
@param integer $productId
@param integer $productImageId

@return ProductImage
972451
public function get($productId, $productImageId)
    {
        $endpoint = '/admin/products/'.$productId.'/images/'.$productImageId.'.json';
        $response = $this->request($endpoint, 'GET');
        return $this->createObject(ProductImage::class, $response['image']);
    }
302329
public function getPriceStockForQuantityAction($productId)
    {
        $request = $this->getCurrentRequest();
        if (!$request->isXmlHttpRequest() || !($quantity = (int) $request->query->get('quantity'))) {
            throw new BadRequestHttpException('Request needs to be XHR and have a quantity parameter');
        }

        $product = $this->get('sonata.product.set.manager')->findOneBy(['id' => $productId, 'enabled' => true]);

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

        $errors = [];

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

        if ($provider->hasVariations($product)) {
            $errors['variations'] = 'This is a master product, it has no price';
        }

        $stock = $provider->getStockAvailable($product) ?: 0;

        if ($quantity > $stock) {
            $errors['stock'] = $this->get('translator')->trans('product_out_of_stock_quantity', [], 'SonataProductBundle');
        }

        $currency = $this->get('sonata.basket')->getCurrency();

        $price = $provider->calculatePrice($product, $currency, true, $quantity);

        return new JsonResponse([
            'stock' => $stock,
            'price' => $price,
            'price_text' => $this->get('sonata.intl.templating.helper.number')->formatCurrency($price, $currency),
            'errors' => $errors,
        ]);
    }
1205752
public function getAvailableAccessoriesAction($productId, $categoryId)
    {
        $result = array();

        $categories = CategoryQuery::create()->filterById($categoryId)->find();

        if ($categories !== null) {
            $list = ProductQuery::create()
            ->joinWithI18n($this->getCurrentEditionLocale())
            ->filterByCategory($categories, Criteria::IN)
            ->filterById(AccessoryQuery::create()->filterByProductId($productId)->select('accessory')->find(), Criteria::NOT_IN)
            ->find();
            ;

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

        return $this->jsonResponse(json_encode($result));
    }
223300
public function findOneByProductIdAndWebsite($productId, $websiteId)
    {

        // prepare the params
        $params = array(
            MemberNames::PRODUCT_ID => $productId,
            MemberNames::WEBSITE_ID => $websiteId
        );

        // load and return the product with the passed product/website ID
        $this->productWebsiteStmt->execute($params);
        return $this->productWebsiteStmt->fetch(\PDO::FETCH_ASSOC);
    }
588914
private function getStoreData($productId, $storeId, $attributeCode)
    {
        if (array_key_exists($productId, $this->attributeData)
            && array_key_exists($storeId, $this->attributeData[$productId])
            && array_key_exists($attributeCode, $this->attributeData[$productId][$storeId])
        ) {
            return $this->attributeData[$productId][$storeId][$attributeCode];
        }

        return null;
    }
1362186
public function setProductTemplateAction($productId)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        $product = ProductQuery::create()->findPk($productId);

        if ($product != null) {
            $template_id = \intval($this->getRequest()->get('template_id', 0));

            $this->dispatch(
                TheliaEvents::PRODUCT_SET_TEMPLATE,
                new ProductSetTemplateEvent($product, $template_id, $this->getCurrentEditionCurrency()->getId())
            );
        }

        return $this->redirectToEditionTemplate();
    }
978092
public function listAction($productId)
    {
        $this->checkAuth(AdminResources::PRODUCT, [], AccessManager::VIEW);

        if (null !== $response = $this->checkProduct($productId)) {
            return $response;
        }

        $request = $this->getRequest();

        if ($request->query->has('id')) {
            $request->query->remove('id');
        }

        $params = array_merge(
            array(
                "limit" => 10,
                "offset" => 0,
            ),
            $request->query->all(),
            array(
                "product" => $productId,
            )
        );

        return new JsonResponse($this->getProductSaleElements($params));
    }
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');
    }
285132
public function getCombinations(string $productId, Context $context)
    {
        return new JsonResponse(
            $this->combinationLoader->load($productId, $context)
        );
    }
654444
public function getSearchableProducts($storeId, $productIds = null, $fromId = 0, $limit = 1000)
    {
        $select = $this->getConnection()->select()
            ->from(['e' => $this->getTable('catalog_product_entity')]);

        $this->addIsVisibleInStoreFilter($select, $storeId);

        if ($productIds !== null) {
            $select->where('e.entity_id IN (?)', $productIds);
        }

        $select->limit($limit);
        $select->where('e.entity_id > ?', $fromId);
        $select->order('e.entity_id');

        return $this->connection->fetchAll($select);
    }
1234487
public function getPvByProductAndStock($productId, $stockId)
    {
        /* aliases and tables */
        $asStockItem = 'csi';
        $asPv = 'ppsi';
        $tblStockItem = [$asStockItem => $this->resource->getTableName(Cfg::ENTITY_MAGE_CATALOGINVENTORY_STOCK_ITEM)];
        $tblPv = [$asPv => $this->resource->getTableName(Entity::ENTITY_NAME)];
        /* SELECT FROM cataloginventory_stock_item */
        $query = $this->conn->select();
        $cols = [];
        $query->from($tblStockItem, $cols);
        /* LEFT JOIN prxgt_pv_stock_item */
        $on = $asPv . '.' . Entity::A_ITEM_REF . '=' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_ITEM_ID;
        $cols = [Entity::A_PV];
        $query->joinLeft($tblPv, $on, $cols);
        /* WHERE */
        $where = $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_PROD_ID . '=' . (int)$productId;
        $where .= ' AND ' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_STOCK_ID . '=' . (int)$stockId;
        $query->where($where);
        /* fetch data */
        $result = $this->conn->fetchOne($query);
        return $result;
    }
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));
    }
849550
public function fetchProduct($productId)
    {
        /** @var ProductInterface $product */
        $product = $this->getProductRepository()->find($productId);
        if (!$product) {
            throw new EntityNotFoundException($this->getProductRepository()->getClassName(), $productId);
        }

        return $product;
    }
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;
        }
    }
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;
    }
711369
public function all($productId, array $params = array())
    {
        $endpoint = '/admin/products/'.$productId.'/variants.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createCollection(ProductVariant::class, $response['variants']);
    }
1064938
public function postAction(Request $request, $productId)
    {
        $this->getVariantAttributeManager()->createVariantAttributeRelation(
            $productId,
            $request->request->all()
        );

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

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

        return $this->handleView($view);
    }