Return the cheapest variation price of the product (or itself if none).

@param ProductInterface $product

@return ProductInterface
493250
public function getCheapestEnabledVariationPrice(ProductInterface $product)
    {
        return $this->productPool->getProvider($product)->getCheapestEnabledVariation($product)->getPrice();
    }
581560
public function singleOptionBuilderSingleUom($product)
    {
        if (!$product->has('options')) {
            return false;
        }
        if (!$product->has('builders')) {
            return false;
        }
        $builderOptionCount = 0;
        $choices = array();
        foreach ($product->getOptions() as $option) {
            if ($option->getBuilder() == true) {
                $builderOptionCount++;
                //add the choices to a flat array
                foreach ($option->getChoices() as $choice) {
                    $choices[$choice->getChoiceId()] = $choice;
                }
            }
            if ($builderOptionCount > 1) {
                return false;
            }
        }
        $allUoms = array();
        foreach ($product->getBuilders() as $builder) {
            $uoms = $builder->getProduct()->getUoms();
            if (count($uoms) > 1) {
                return false;
            }
            foreach ($uoms as $uom) {
                $str = $uom->getUomCode() . $uom->getQuantity();
                $allUoms[$str] = $str;
            }
        }
        if (count($allUoms) > 1) {
            return false;
        }

        //test is true, set the add price on the choices
        foreach ($product->getBuilders() as $builder) {
            foreach ($builder->getSelected() as $optionId => $choiceId) {
                    $addPrice = $builder->getProduct()->getPrice() - $product->getPrice();
                $choices[$choiceId]->setAddPrice($addPrice);
            }
        }
        return true;
    }
33856
public function addProduct(Product $product)
    {
        $this->products->add($product);

        $this->setOwningSideRelation($product);

        return $this;
    }
363967
public function variationToProductAction($productId, $slug)
    {
        $request = $this->getCurrentRequest();
        $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));
        }

        if (null !== $product->getParent()) {
            // We need the master product
            $product = $product->getParent();
        }

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

        $data = $request->query->get('sonata_product_variation_choices');

        $choices = $provider->getVariationsChoices($product, array_keys($data));

        $accessor = PropertyAccess::createPropertyAccessor();
        $currentValues = [];

        foreach ($choices as $field => $values) {
            $currentValues[$field] = array_search($accessor->getValue($product, $field), $values, true);
        }

        $form = $this->createForm(VariationChoiceType::class, $currentValues, [
            'product' => $product,
            'fields' => array_keys($data),
        ]);

        $form->handleRequest($request);

        $selectedVariation = $form->getData();

        // Retrieving correct values
        foreach ($selectedVariation as $key => $value) {
            $selectedVariation[$key] = $choices[$key][$value];
        }

        $variation = $provider->getVariation($product, $selectedVariation);

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

        if ($this->get('kernel')->isDebug() && !($response instanceof JsonResponse)) {
            $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;
    }
732231
public function discount(Product $product)
    {
        $discount = $this->money($product);

        if ($product->discount) {
            $discount = $product->discount->product($product);
            $discount = $discount->multiply($product->quantity);
        }

        return $discount;
    }
712100
public function delivery(Product $product)
    {
        $delivery = $product->delivery->multiply($product->quantity);

        return $delivery;
    }
474158
public function product(Product $product): Money
    {
        if ($product->quantity >= $this->quantity) {
            return $this->rate->product($product);
        }

        return new Money(0, $product->price->getCurrency());
    }
217990
private function convertProduct(ProductInterface $productEntity, ProductInterface $publishedProductEntity)
    {
        // Move prices
        foreach ($publishedProductEntity->getPrices() as $data) {
            $this->em->remove($data);
        }
        foreach ($productEntity->getPrices() as $data) {
            $publishedProductEntity->addPrice($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move productAttributes
        foreach ($publishedProductEntity->getProductAttributes() as $data) {
            $this->em->remove($data);
        }
        foreach ($productEntity->getProductAttributes() as $data) {
            $publishedProductEntity->addProductAttribute($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move translations
        foreach ($publishedProductEntity->getTranslations() as $data) {
            $this->em->remove($data);
        }
        foreach ($productEntity->getTranslations() as $data) {
            $publishedProductEntity->addTranslation($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move addons
        foreach ($publishedProductEntity->getAddons() as $data) {
            $publishedProductEntity->removeAddon($data);
        }
        foreach ($productEntity->getAddons() as $data) {
            $publishedProductEntity->addAddon($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move sets
        foreach ($publishedProductEntity->getSets() as $data) {
            $publishedProductEntity->removeSet($data);
        }
        foreach ($productEntity->getSets() as $data) {
            $publishedProductEntity->addSet($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move relation
        foreach ($publishedProductEntity->getRelations() as $data) {
            $publishedProductEntity->removeRelation($data);
        }
        foreach ($productEntity->getRelations() as $data) {
            $publishedProductEntity->addRelation($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move upsell
        foreach ($publishedProductEntity->getUpsells() as $data) {
            $publishedProductEntity->removeUpsell($data);
        }
        foreach ($productEntity->getUpsells() as $data) {
            $publishedProductEntity->addUpsell($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move crossells
        foreach ($publishedProductEntity->getCrosssells() as $data) {
            $publishedProductEntity->removeCrosssell($data);
        }
        foreach ($productEntity->getCrosssells() as $data) {
            $publishedProductEntity->addCrosssell($data);
            $data->setProduct($publishedProductEntity);
        }

        // Move categories
        foreach ($publishedProductEntity->getCategories() as $data) {
            $publishedProductEntity->removeCategory($data);
        }
        foreach ($productEntity->getCategories() as $data) {
            $publishedProductEntity->addCategory($data);
        }

        // Move media
        foreach ($publishedProductEntity->getMedia() as $data) {
            $publishedProductEntity->removeMedia($data);
        }
        foreach ($productEntity->getMedia() as $data) {
            $publishedProductEntity->addMedia($data);
        }

        $publishedProductEntity->setNumber($productEntity->getNumber());
        $publishedProductEntity->setGlobalTradeItemNumber($productEntity->getGlobalTradeItemNumber());
        $publishedProductEntity->setInternalItemNumber($productEntity->getInternalItemNumber());
        $publishedProductEntity->setManufacturer($productEntity->getManufacturer());
        $publishedProductEntity->setCost($productEntity->getCost());
        $publishedProductEntity->setPriceInfo($productEntity->getPriceInfo());
        $publishedProductEntity->setChanged($productEntity->getChanged());
        $publishedProductEntity->setManufacturerCountry($productEntity->getManufacturerCountry());
        $publishedProductEntity->setType($productEntity->getType());
        $publishedProductEntity->setStatus($productEntity->getStatus());
        $publishedProductEntity->setDeliveryStatus($productEntity->getDeliveryStatus());
        $publishedProductEntity->setDeliveryTime($productEntity->getDeliveryTime());
        $publishedProductEntity->setSupplier($productEntity->getSupplier());
        $publishedProductEntity->setParent($productEntity->getParent());
        $publishedProductEntity->setContentUnit($productEntity->getContentUnit());
        $publishedProductEntity->setOrderUnit($productEntity->getOrderUnit());
        $publishedProductEntity->setOrderContentRatio($productEntity->getOrderContentRatio());
        $publishedProductEntity->setMinimumOrderQuantity($productEntity->getMinimumOrderQuantity());
        $publishedProductEntity->setRecommendedOrderQuantity($productEntity->getRecommendedOrderQuantity());
        $publishedProductEntity->setChanger($productEntity->getChanger());
        $publishedProductEntity->setSearchTerms($productEntity->getSearchTerms());
        $publishedProductEntity->setTaxClass($productEntity->getTaxClass());

        // Move children
        foreach ($publishedProductEntity->getChildren() as $data) {
            $this->em->remove($data);
        }
        foreach ($productEntity->getChildren() as $data) {
            $data->setParent($publishedProductEntity);
        }

        $this->em->remove($productEntity);
        $this->em->flush();

        return $publishedProductEntity;
    }
7606
protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
    {
        foreach ($this->prices as $price) {
            if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
                return $price;
            }
        }

        return null;
    }
275690
public function getPrice(ProductVariantInterface $productVariant, array $context): int
    {
        Assert::keyExists($context, 'channel');

        return $this
            ->productVariantPriceCalculator
            ->calculate($productVariant, $context)
        ;
    }
1118431
public function total(Product $product)
    {
        $tax      = $this->tax($product);
        $subtotal = $this->subtotal($product);
        $total    = $subtotal->add($tax);

        return $total;
    }
834791
private function getProductOptionsAsArray(ProductInterface $product): array
    {
        $optionsAsArray = [];

        foreach ($product->getOptionTypes() as $label) {
            foreach ($label->getOptions() as $option) {
                $optionsAsArray[$label->getName()][] = $option;
            }
        }

        return $optionsAsArray;
    }
170253
public function copyFrom( MShop_Product_Item_Interface $product )
	{
		$this->setName( $product->getName() );
		$this->setType( $product->getType() );
		$this->setSupplierCode( $product->getSupplierCode() );
		$this->setProductCode( $product->getCode() );
		$this->setProductId( $product->getId() );

		$items = $product->getRefItems( 'media', 'default', 'default' );
		if( ( $item = reset( $items ) ) !== false ) {
			$this->setMediaUrl( $item->getUrl() );
		}

		$this->setModified();
	}
250699
public function setProduct(\Magento\Catalog\Model\Product $product)
    {
        $this->setProductName($product->getName());
        $this->setProductSku($product->getSku());

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

        return $product->getName();
    }
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,
        ]);
    }
851202
public function retrieveProductAttributeByAttribute(ProductInterface $product, Attribute $attribute)
    {
        foreach ($product->getProductAttributes() as $productAttribute) {
            if ($productAttribute->getAttribute()->getId() === $attribute->getId()) {
                return $productAttribute;
            }
        }

        return null;
    }