Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nicanaca0/18f009532e5fe7204f47993053e32efc to your computer and use it in GitHub Desktop.
Save nicanaca0/18f009532e5fe7204f47993053e32efc to your computer and use it in GitHub Desktop.
<?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