Skip to content

Instantly share code, notes, and snippets.

@cornobils
Last active August 14, 2017 13:15
Show Gist options
  • Save cornobils/09a30a935dfd1e229d558dbf9b673d86 to your computer and use it in GitHub Desktop.
Save cornobils/09a30a935dfd1e229d558dbf9b673d86 to your computer and use it in GitHub Desktop.
OrderItem attaching as Collection to Order problem
final class AdminOrderCreateType extends AbstractResourceType {
...
$builder
->add('items', CollectionType::class, [
'entry_type' => AdminOrderItemCollectionType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'block_name' => 'entry'
])
...
class AdminOrderItemCollectionType extends AbstractResourceType {
/**
* @var RepositoryInterface
*/
private $productRepository;
public function __construct($dataClass, $validationGroups, RepositoryInterface $productRepository) {
parent::__construct($dataClass, $validationGroups);
$this->productRepository = $productRepository;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$product = $this->productRepository->findOneByCode("ogu1");
$builder
->add('product', ProductChoiceType::class, [
'mapped' => false
]);
/*->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) use ($builder, $options){
})*/
$builder->add('variant', AdminOrderItemType::class, [
'product' => $product
]);
;
}}
app.form.admin.order_item.collection.create:
class: AppBundle\Form\AdminOrderItemCollectionType
arguments:
- %sylius.model.order_item.class%
- %sylius.form.type.checkout_address.validation_groups%
- '@sylius.repository.product'
tags:
- { name: form.type }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment