I'm creating an extbase extension to handle very simple product orders. The model is:
Order --1:n--> OrderItem --1:1--> Product
To order a selection of products, the customer goes to checkout page and uses a Fluid based Order form. All selected products are available in the fluid template as {products}.
The OrderController->createAction processes new Orders by creating OrderItems from the given Products.
Writing the code I'd like to have would look like this:
class OrderController
{
public function create(Order $order, array $products)
{
foreach ($products as $product) {
$orderItem = new OrderItem()
->setProduct($product)
->setPrice($product->getPrice());
$order->addOrderItem($orderItem);
}
$this->orderRepository->add($order);
}
}
- How to assign products to a Fluid form fields, in order to receive them as ControllerAction array argument?
- How to trigger extbase to automagically provide an array of product objects to the ControllerAction?
- I wonder if it is even possible to simplify the Controller createAction like shown below and assemble objects elsewhere:
public function create(Order $order) {
$this->orderRepository->add($order);
}