protected function setItemByProductData($productData, ApiItemInterface $item, $locale)
    {
        $productId = $this->getProductId($productData, 'product.id');

        /** @var Product $product */
        $product = $this->productRepository->find($productId);
        if (!$product) {
            throw new ProductNotFoundException(self::$productEntityName, $productId);
        }
        $item->setProduct($product);
        $translation = $product->getTranslation($locale);

        // When the product is not available in the current language choose the first translation you find.
        if (is_null($translation)) {
            if (count($product->getTranslations()) > 0) {
                $translation = $product->getTranslations()[0];
            } else {
                throw new ProductException('Product ' . $product->getId() . ' has no translations!');
            }
        }

        $this->setItemSupplier($item, $product);

        $item->setName($translation->getName());
        $item->setDescription($translation->getLongDescription());
        $item->setNumber($product->getNumber());

        // set order unit
        if ($product->getOrderUnit()) {
            $item->setQuantityUnit($product->getOrderUnit()->getTranslation($locale)->getName());
        } else if ($product->getParent() && $product->getParent()->getOrderUnit()) {
            $item->setQuantityUnit($product->getParent()->getOrderUnit()->getTranslation($locale)->getName());
        }

        $item->setIsRecurringPrice($product->isRecurringPrice());

        $taxClass = $product->getTaxClass();

        /*
         * If the product doesn't have a taxClass but has a parent, we try to get the taxClass from the parent.
         * This is used for product variants, which get the taxClass from the original product.
         */
        if (!$taxClass && $product->getParent()) {
            $taxClass = $product->getParent()->getTaxClass();
        }

        if ($taxClass) {
            $tax = $this->retrieveTaxForClass($taxClass);
            $item->setTax($tax);
        } else {
            $item->setTax(0);
        }

        return $product;
    }
protected function setItemByProductData($productData, ApiItemInterface $item, $locale)
    {
        $productId = $this->getProductId($productData, 'product.id');

        /** @var Product $product */
        $product = $this->productRepository->find($productId);
        if (!$product) {
            throw new ProductNotFoundException(self::$productEntityName, $productId);
        }
        $item->setProduct($product);
        $translation = $product->getTranslation($locale);

        // When the product is not available in the current language choose the first translation you find.
        if (is_null($translation)) {
            if (count($product->getTranslations()) > 0) {
                $translation = $product->getTranslations()[0];
            } else {
                throw new ProductException('Product ' . $product->getId() . ' has no translations!');
            }
        }

        $this->setItemSupplier($item, $product);

        $item->setName($translation->getName());
        $item->setDescription($translation->getLongDescription());
        $item->setNumber($product->getNumber());

        // set order unit
        if ($product->getOrderUnit()) {
            $item->setQuantityUnit($product->getOrderUnit()->getTranslation($locale)->getName());
        } else if ($product->getParent() && $product->getParent()->getOrderUnit()) {
            $item->setQuantityUnit($product->getParent()->getOrderUnit()->getTranslation($locale)->getName());
        }

        $item->setIsRecurringPrice($product->isRecurringPrice());

        $taxClass = $product->getTaxClass();

        /*
         * If the product doesn't have a taxClass but has a parent, we try to get the taxClass from the parent.
         * This is used for product variants, which get the taxClass from the original product.
         */
        if (!$taxClass && $product->getParent()) {
            $taxClass = $product->getParent()->getTaxClass();
        }

        if ($taxClass) {
            $tax = $this->retrieveTaxForClass($taxClass);
            $item->setTax($tax);
        } else {
            $item->setTax(0);
        }

        return $product;
    }
protected function setItemByProductData ( $ productData , ApiItemInterface $ item , $ locale ) { $ productId = $ this -> getProductId ( $ productData , 'product.id' ) ; /** @var Product $product */ $ product = $ this -> productRepository -> find ( $ productId ) ; if ( ! $ product ) { throw new ProductNotFoundException ( self :: $ productEntityName , $ productId ) ; } $ item -> setProduct ( $ product ) ; $ translation = $ product -> getTranslation ( $ locale ) ; // When the product is not available in the current language choose the first translation you find. if ( is_null ( $ translation ) ) { if ( count ( $ product -> getTranslations ( ) ) > 0 ) { $ translation = $ product -> getTranslations ( ) [ 0 ] ; } else { throw new ProductException ( 'Product ' . $ product -> getId ( ) . ' has no translations!' ) ; } } $ this -> setItemSupplier ( $ item , $ product ) ; $ item -> setName ( $ translation -> getName ( ) ) ; $ item -> setDescription ( $ translation -> getLongDescription ( ) ) ; $ item -> setNumber ( $ product -> getNumber ( ) ) ; // set order unit if ( $ product -> getOrderUnit ( ) ) { $ item -> setQuantityUnit ( $ product -> getOrderUnit ( ) -> getTranslation ( $ locale ) -> getName ( ) ) ; } else if ( $ product -> getParent ( ) && $ product -> getParent ( ) -> getOrderUnit ( ) ) { $ item -> setQuantityUnit ( $ product -> getParent ( ) -> getOrderUnit ( ) -> getTranslation ( $ locale ) -> getName ( ) ) ; } $ item -> setIsRecurringPrice ( $ product -> isRecurringPrice ( ) ) ; $ taxClass = $ product -> getTaxClass ( ) ; /*
         * If the product doesn't have a taxClass but has a parent, we try to get the taxClass from the parent.
         * This is used for product variants, which get the taxClass from the original product.
         */ if ( ! $ taxClass && $ product -> getParent ( ) ) { $ taxClass = $ product -> getParent ( ) -> getTaxClass ( ) ; } if ( $ taxClass ) { $ tax = $ this -> retrieveTaxForClass ( $ taxClass ) ; $ item -> setTax ( $ tax ) ; } else { $ item -> setTax ( 0 ) ; } return $ product ; }
Sets item based on given product data.

@param array $productData
@param ApiItemInterface $item
@param string $locale

@throws MissingItemAttributeException
@throws ProductException
@throws ProductNotFoundException

@return ProductInterface
Sets item based on given product data .