There are two tables in our database that are important for this question. In Orders, we have the following fields:
ID, account_id, sale_id, site_id, pending, order_date
The other related table, orders_product_types, is an associative table that contains
order_id, product_id, quantity
Cake originally baked an admin page for orders that works just as you would expect. However, the client has requested that we add the ability to edit the quantity of each product associated with the sale on that same orders.admin_edit page, as well as see the products on the admin_view page. I have already managed to get the view page to display (albeit in an unpretty way) with the following code. To the controller, I added
$order = $this->Order->findById($id);
$this->recursive = 1;
to the controller and included it in the set, and I display them on the view page with this:
<?php foreach ($order['ProductType'] as $productType){
echo $productType['type'];
echo $productType['OrdersProductType']['quantity'];?>
<br></br>
<?
}?>
However, now I'm stuck on how to do this in the cake form for editing. Ideally, I would like to find a way to do this using proper cake functions, but I'm still new to this and am still figuring out how everything works. The pertinent part of the form that allows them to edit the information for the order looks like this:
<?php echo $this->Form->create('Order'); ?>
<fieldset>
<legend><?php echo __('Edit Order'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('account_id');
echo $this->Form->input('sale_id');
echo $this->Form->input('site_id');
echo $this->Form->input('pay later');
echo $this->Form->input('order_date');
echo $this->Form->input('Coupon');
echo $this->Form->input('ProductType');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
Ideally, I would like to find some way to follow this syntax, but to include fields from the associated table orders_product_types so that they can edit the quantities directly in this form. How would I include a second table within the cake structure?