-1

Hello guys I'm a newbie in PHP and have an assignment due in the afternoon. Actually i have to create a store that use a session array to retrieve data input in a form, and display it . But the shopping cart has to be built with MVC. So here is a little details of the assignement: in the first place we have only a navbar that appears where there is two link ( both are dropdowns menu): Order and Product When you click on ORDER the dropdown menu appears and you can read "Create" and "List" . When you click on PRODUCT the dropdown menu appears and you can read "Create".

When you click on " Create" from the PRODUCT 's DROPDOWN you are redirect to a new page. On this new page there is a form where you can input the reference, name, price and quantity of the product you want to add and there is a save button too. When you click on save the informations are save in a array stored in data.php. Naturally before they get stored the information input have to check if they are valid first.

When you click on " Create" from theORDER 's DROPDOWN, there is a form with two buttons that appears in the same page where you can input information about your order. And when you click on "ADD", a table appear in which you can read the order you entered . when you click on "Save", the informations are save in a array "product" stored in data.php.

When you click on " List" from the ORDER 's DROPDOWN you are redirect to a new page. On this new page there is a table where you can see the list of your order the reference, name, price and quantity of the product you want to add and there is a save button too. And in each row there is a Details button. When you click on it an other table appears where you can see the elements ordered in that day and the Total

And i need help to know how to start this MVC model in the best way possible. All help appreciated and thanks for everything.

aita.kane
  • 21
  • 3

1 Answers1

0

Assuming you understand how MVC works.

Create a $_SESSION variable for your cart, which will be an array. Create the view for your form, POST the product data from said form to a different route to add it to the cart (which is an $_SESSION array).

All you have to do is create an associative array of the product added, push that array to the $_SESSION variable cart which is also an array, so if they add a product your cart array would look like

$_SESSION['cart'] = [
    0 => [
        'name': 'name'
        \\other product info here
    ]
]

Hope this helps

adot
  • 398
  • 1
  • 3
  • 14