-
-
Save nicanaca0/18f009532e5fe7204f47993053e32efc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param array $data | |
* @throws ProductImportException | |
*/ | |
public function createProduct(array $data) | |
{ | |
$originalProduct = $this->productRepository->findOneByCode($data['code']); | |
$form = $this->formFactory->createNamed( | |
'', | |
'Sylius\Bundle\ProductBundle\Form\Type\ProductType', | |
(null === $originalProduct ? new Product() : $originalProduct), | |
['csrf_protection' => false] | |
); | |
$form->submit($data); | |
if ($form->isValid()) { | |
/** @var ProductInterface $product */ | |
$product = $form->getData(); | |
/* ... */ | |
} else { | |
throw new ProductImportException($form->getErrors(true)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment