Receive a single product variant

@link   https://help.shopify.com/api/reference/product_variant#show
@param  integer $productVariantId
@param  array   $fields
@return ProductVariant
772954
public function get($productVariantId, array $fields = array())
    {
        $params = array();
        if (!empty($fields)) {
            $params['fields'] = $fields;
        }
        $endpoint = '/admin/variants/'.$productVariantId.'.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createObject(ProductVariant::class, $response['variant']);
    }
271259
protected function buildProductVariation(
        array &$productData,
        $sku,
        $qty,
        $ean,
        array $images = [],
        array $specifications = []
    ) {
        $transformer = new Create($sku, $qty, $ean, $images, $specifications);
        $output      = $transformer->output();

        $productData['variations'][] = $output['variation'];

        return $productData;
    }
423163
protected function getMergedFields(array $fields)
    {
        if (0 === \count($fields)) {
            // If we didn't specify the fields (filtered), we get all variation fields possible values
            $fields = $this->getVariationFields();
        } else {
            foreach ($fields as $field) {
                if (!\in_array($field, $this->getVariationFields(), true)) {
                    throw new \RuntimeException("The field '".$field."' is not among the variation fields");
                }
            }
        }

        return $fields;
    }
1188412
protected function getProductFields(FieldList $fields)
    {
        //Requirements::javascript('dynamic/foxystripe: client/dist/javascript/scripts.min.js');
        $hiddenTitle = ($this->product->ReceiptTitle) ?
            htmlspecialchars($this->product->ReceiptTitle) :
            htmlspecialchars($this->product->Title);
        $code = $this->product->Code;

        if ($this->getProduct()->getIsAvailable()) {
            $fields->push(
                HiddenField::create('name')
                    ->setValue(
                        ProductPage::getGeneratedValue($code, 'name', $hiddenTitle, 'value')
                    )
            );
            $fields->push(
                HiddenField::create('category')
                    ->setValue(
                        ProductPage::getGeneratedValue($code, 'category', $this->product->Category()->Code, 'value')
                    )
            );
            $fields->push(
                HiddenField::create('code')
                    ->setValue(
                        ProductPage::getGeneratedValue($code, 'code', $this->product->Code, 'value')
                    )
            );
            $fields->push(
                HiddenField::create(
                    'product_id'
                )->setValue(
                    ProductPage::getGeneratedValue($code, 'product_id', $this->product->ID, 'value')
                )
            );
            $fields->push(
                HiddenField::create('price')
                    ->setValue(
                        ProductPage::getGeneratedValue($code, 'price', $this->product->Price, 'value')
                    )
            );//can't override id
            if ($this->product->Weight > 0) {
                $fields->push(
                    HiddenField::create('weight')
                        ->setValue(
                            ProductPage::getGeneratedValue($code, 'weight', $this->product->Weight, 'value')
                        )
                );
            }

            $image = null;
            if ($this->product->Image() || ProductPage::has_extension(ProductPageLegacy::class)) {
                if ($this->product->Image()) {
                    $image = $this->product->Image()->Pad(80, 80)->absoluteURL;
                } elseif (ProductPage::has_extension(ProductPageLegacy::class) &&
                    $this->product->PreviewImage()->exists()) {
                    $image = $this->product->PreviewImage()->Pad(80, 80)->absoluteURL;
                }

                if ($image) {
                    $fields->push(
                        HiddenField::create('image')
                            ->setValue(
                                ProductPage::getGeneratedValue($code, 'image', $image, 'value')
                            )
                    );
                }
            }

            $optionsSet = $this->getProductOptionSet();
            $fields->push($optionsSet);

            $quantityMax = ($this->site_config->MaxQuantity) ? $this->site_config->MaxQuantity : 10;

            $fields->push(QuantityField::create('x:visibleQuantity')->setTitle('Quantity')->setValue(1));
            $fields->push(
                HiddenField::create('quantity')
                    ->setValue(
                        ProductPage::getGeneratedValue($code, 'quantity', 1, 'value')
                    )
            );

            $fields->push(
                HeaderField::create('submitPrice', '$' . $this->product->Price, 4)
                    ->addExtraClass('submit-price')
            );
            $fields->push(
                $unavailable = HeaderField::create('unavailableText', 'Selection unavailable', 4)
                    ->addExtraClass('unavailable-text')
            );

            if (!empty(trim($this->getSiteConfig()->StoreName)) && $this->getProduct()->getIsAvailable()) {
                $unavailable->addExtraClass('hidden');
            }

            $this->extend('updatePurchaseFormFields', $fields);
        } else {
            $fields->push(HeaderField::create('unavailableText', 'Currently Out of Stock', 4));
        }

        $this->extend('updateFoxyStripePurchaseFormFields', $fields);

        return $fields;
    }
863085
public function getVariantSelections()
    {
        $article = $this->getProduct();
        $variantSelectionListId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("varselid");
        if (($articleParent = $this->_getParentProduct($article->oxarticles__oxparentid->value))) {
            return $articleParent->getVariantSelections($variantSelectionListId, $article->getId());
        }

        return $article->getVariantSelections($variantSelectionListId);
    }
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;
    }
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;
        }
    }
1013358
public function loadById($productId)
    {
        return $this->productRepository->getById($productId, false, $this->storeManager->getStore()->getId(), true);
    }
52596
public function addDisabledVariant(VariantInterface $variant): ProductInterface
    {
        if (!$this->disabledVariants->contains($variant)) {
            $this->disabledVariants->add($variant);
        }

        return $this;
    }
1308947
public function getProductAllAttributes($variation = null)
    {
        if (null === $variation) {
            $variations = $this->productVariations()->get();
        }

        $collection = Collection::make([]);

        if (null === $variations || $variations->count() <= 0) {
            return $collection;
        }

        foreach ($variations as $variation) {
            $variationModel = self::findorfail($variation->variation_id);

            foreach ($variationModel->productVarcharAttributes as $item) {
                $collection->push($item);
            }
            foreach ($variationModel->productBooleanAttributes as $item) {
                $collection->push($item);
            }

            foreach ($variationModel->productTextAttributes as $item) {
                $collection->push($item);
            }
            foreach ($variationModel->productDecimalAttributes as $item) {
                $collection->push($item);
            }
            foreach ($variationModel->productDecimalAttributes as $item) {
                $collection->push($item);
            }
            foreach ($variationModel->productIntegerAttributes as $item) {
                $collection->push($item);
            }

            foreach ($variationModel->productDatetimeAttributes as $item) {
                $collection->push($item);
            }
        }

        return $collection;
    }
565109
public static function generate($productVariant)
    {
        if (!$product = $productVariant->getProduct()) {
            throw new InvalidEntityCodeException('librinfo.error.missing_product');
        }
        if (!$productCode = $product->getCode()) {
            throw new InvalidEntityCodeException('librinfo.error.missing_product_code');
        }
        // TODO: improve this (use productVariant name or optionValues...) and handle code unicity
        return sprintf('%s-%s', $productCode, strtoupper($productVariant->getName()));
    }
183263
public function retrieveAppliedProducts(Varien_Event_Observer $observer)
    {
        $this->_productIds = $this->_getResource()->getAffectedProductIds(
            $observer->getEvent()->getProductCondition()
        );
    }
265212
public function post(\WC_Product $WC_Product)
    {
        if (!$WC_Product->exists()) {
            return null; // Not possible.
        }
        if ($WC_Product->is_type('variation')) {
            $WP_Post = get_post($WC_Product->get_parent_id());
        } else {
            $WP_Post = get_post($WC_Product->get_id());
        }
        return $WP_Post instanceof \WP_Post && $WP_Post->ID ? $WP_Post : null;
    }
144762
public function getVariation(
        Field $field,
        VersionInfo $versionInfo,
        $variationName,
        array $parameters = []
    ) {
        /** @var \eZ\Publish\SPI\Variation\Values\ImageVariation $variation */
        $variation = $this->aliasGenerator->getVariation(
            $field,
            $versionInfo,
            $variationName,
            $parameters
        );

        if (null === $variation->width || null === $variation->height) {
            $variationBinaryFile = $this->getVariationBinaryFile($field->value->id, $variationName);
            $image = $this->imagine->load($this->ioService->getFileContents($variationBinaryFile));
            $dimensions = $image->getSize();

            return new ImageVariation(
                [
                    'name' => $variation->name,
                    'fileName' => $variation->fileName,
                    'dirPath' => $variation->dirPath,
                    'uri' => $variation->uri,
                    'imageId' => $variation->imageId,
                    'width' => $dimensions->getWidth(),
                    'height' => $dimensions->getHeight(),
                    'fileSize' => $variationBinaryFile->size,
                    'mimeType' => $this->ioService->getMimeType($variationBinaryFile->id),
                    'lastModified' => $variationBinaryFile->mtime,
                ]
            );
        }

        return $variation;
    }
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);
    }
909687
public function getCreateVariant($product_id)
    {
        $product = Product::find($product_id);
        // No such id
        if ($product == null) {
            $errors = new MessageBag;
            $errors->add('errorNoSuchProduct', Lang::get('redminportal::messages.error_no_such_product'));
            return redirect($this->pageRoute)->withErrors($errors);
        }
        
        $data = array(
            'product' => $product,
            'product_id' => $product_id,
            'weight_units' => $this->weight_units,
            'volume_units' => $this->volume_units
        );

        return view('redminportal::products/create-variant', $data);
    }
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);
    }