src/Sulu/Bundle/Sales/CoreBundle/Item/ItemManager.php
protected function setItemByProductData($productData, ApiItemInterface $item, $locale)
    {
        $productId = $this->getProductId($productData);

        /** @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
        // FIXME: should be changed when products have a language fallback
        // https://github.com/massiveart/POOL-ALPIN/issues/611
        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());
        }

        // TODO: get tax from product https://github.com/massiveart/POOL-ALPIN/issues/1224
        $item->setTax(0);

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

        /** @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
        // FIXME: should be changed when products have a language fallback
        // https://github.com/massiveart/POOL-ALPIN/issues/611
        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());
        }

        // TODO: get tax from product https://github.com/massiveart/POOL-ALPIN/issues/1224
        $item->setTax(0);

        return $product;
    }
protected function setItemByProductData ( $ productData , ApiItemInterface $ item , $ locale ) { $ productId = $ this -> getProductId ( $ productData ) ; /** @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 // FIXME: should be changed when products have a language fallback // https://github.com/massiveart/POOL-ALPIN/issues/611 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 ( ) ) ; } // TODO: get tax from product https://github.com/massiveart/POOL-ALPIN/issues/1224 $ 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