Skip to content

Instantly share code, notes, and snippets.

@haltsir
Created July 5, 2017 16:10
Show Gist options
  • Save haltsir/a9300daab1e1adf882c5ad1719172912 to your computer and use it in GitHub Desktop.
Save haltsir/a9300daab1e1adf882c5ad1719172912 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));
}
}
@onusgit
Copy link

onusgit commented Nov 29, 2017

how this function work? can you please send csv file format ?
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment