Last active
August 14, 2017 13:15
-
-
Save chornobils/09a30a935dfd1e229d558dbf9b673d86 to your computer and use it in GitHub Desktop.
OrderItem attaching as Collection to Order problem
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
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' | |
]) | |
... |
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
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 | |
]); | |
; | |
}} |
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
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