Created
July 5, 2017 16:10
-
-
Save haltsir/a9300daab1e1adf882c5ad1719172912 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
how this function work? can you please send csv file format ?
thanks