Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7955391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:42:09+00:00 2026-06-04T03:42:09+00:00

This is propably a simple task to solve in Symfony2 but I am really

  • 0

This is propably a simple task to solve in Symfony2 but I am really stuck here:

I am building a very simple shop. There are three entities: Products, Customers, and Orders. The last one contains three columns: customer_id, product_id, and quantity. The shop simply consists of a page listing all the products with a select field for each to chose the quantity, followed by a form to enter your customer data.

I have no problem creating the form for the customer data nor listing the products itself (without the select fields).

But how do I create a form including the select fields of the products, which then should become order entities?

I played around with form collections and I do understand all the given examples with adding tags to an entity etc. But I can’t get the hang of how to adjust it to my situation.

What I have in mind goes something like this:

// Create new customer
$customer = new Customer();

// At this point, create form and validate it.
// Having trouble here, need a hint to get it right.
...

// If form is ok, loop thru all the products.
// Since I do not know yet how to define the form,
// I don't know yet what to loop over, too.
foreach( ..... ){
    if($quantity > 0){
        $order = new Order();
        $order->setQuantity($quantity);
        $order->setProduct($product);
        $customer->addOrder($order);
    }
}

// then persist $customer, cascading its orders.
...

I have been spending hours on this. Any help is greatly appreciated. Thanks!

Update:
Eventually I got it working. I created an OrderFactory and a OrderFormType and had to change around the whole setting a bit. The AcmePizzaBundle which is mentioned in the responses below was actually a great help to get the missing parts right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:42:10+00:00Added an answer on June 4, 2026 at 3:42 am

    Take a look at an example: AcmePizzaBundle.
    It has 4 entities you need: Pizza, Order, OrderItem, Customer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably very simple but it's really confusing me. When I implement the
This is probably a simple one to answer, but I'm stuck, so here goes.
This is probably a very simple task to perform but I'm taking the risk
I know this probably really simple but Im not sure what im doing wrong...
This is probably a very simple fix but I've been unable to find an
This is probably a simple question, but I really don't know what I'm doing
This is probably a simple question but I can't seem to figure out how
this is probably pretty simple, but I've got this text file containing a bunch
This is probably a simple question, but i have been unable to find a
This is probably quite simple, but I just don't know how to do this...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.