public function getProduct(array $productData)
    {
        // check if all mandatory fields are present
        foreach ($this->mandatoryFields as $mandatoryField) {
            if (!array_key_exists($mandatoryField, $productData)) {
                throw new ProductException("The field '$mandatoryField' is missing in the given product data");
            }
        }

        // try to create a product from the available data
        try {

            // sku
            $sku = new SKU($productData[self::FIELD_SKU]);

            // slug
            $slug = new Slug($productData[self::FIELD_SLUG]);

            // product content
            $content = $this->contentMapper->getContent($productData);

            $product = new Product($sku, $slug, $content);
            return $product;

        } catch (\Exception $productException) {
            throw new ProductException(sprintf("Failed to create a product from the given data: %s",
                $productException->getMessage()), $productException);
        }
    }
public function getProduct(array $productData)
    {
        // check if all mandatory fields are present
        foreach ($this->mandatoryFields as $mandatoryField) {
            if (!array_key_exists($mandatoryField, $productData)) {
                throw new ProductException("The field '$mandatoryField' is missing in the given product data");
            }
        }

        // try to create a product from the available data
        try {

            // sku
            $sku = new SKU($productData[self::FIELD_SKU]);

            // slug
            $slug = new Slug($productData[self::FIELD_SLUG]);

            // product content
            $content = $this->contentMapper->getContent($productData);

            $product = new Product($sku, $slug, $content);
            return $product;

        } catch (\Exception $productException) {
            throw new ProductException(sprintf("Failed to create a product from the given data: %s",
                $productException->getMessage()), $productException);
        }
    }
public function getProduct ( array $ productData ) { // check if all mandatory fields are present foreach ( $ this -> mandatoryFields as $ mandatoryField ) { if ( ! array_key_exists ( $ mandatoryField , $ productData ) ) { throw new ProductException ( "The field '$mandatoryField' is missing in the given product data" ) ; } } // try to create a product from the available data try { // sku $ sku = new SKU ( $ productData [ self :: FIELD_SKU ] ) ; // slug $ slug = new Slug ( $ productData [ self :: FIELD_SLUG ] ) ; // product content $ content = $ this -> contentMapper -> getContent ( $ productData ) ; $ product = new Product ( $ sku , $ slug , $ content ) ; return $ product ; } catch ( \ Exception $ productException ) { throw new ProductException ( sprintf ( "Failed to create a product from the given data: %s" , $ productException -> getMessage ( ) ) , $ productException ) ; } }
Get a Catalog model from an array of unstructured product data

@param array $productData An array containing product attributes

@return Product

@throws ProductException If a mandatory field is missing
@throws ProductException If the no Product could be created from the given product data
Get a Catalog model from an array of unstructured product data