⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Order with full list of order items, each with related info



kk8
  • profile picture
  • Member

Posted 24 March 2012 - 17:53 PM

Hi,

thanks for an awesome system in groceryCRUD.

Can't find related information to the issue I'm having, perhaps there is an obvious solution I'm missing.

The system I've got set up the in MySQL RDBMS allows a full order to be placed for per depot. Each order has a set of order items (with product descriptions, serial numbers and SKUs that need capturing and updating along the process), and the order is only shipped once order items have been added.

How would I go about linking the addition of adding orders, and from there directly adding order items and updating their info? Would I just use add_action to point to a redirecting function?

 public function order()
{
$this->grocery_crud->set_table('orders');
$this->grocery_crud->set_subject('Order');
$this->grocery_crud->set_relation('order_status','order_status','order_status_description');
$this->grocery_crud->set_relation('order_placing_user','user','user_name');
$this->grocery_crud->set_relation('order_fulfillment_user','user','user_name');
$this->grocery_crud->set_relation('order_receipt_user','user','user_name');
$this->grocery_crud->set_relation('order_depot','depot','depot_name');
$this->grocery_crud->add_action('Order Detail', '', 'ui-icon-plus',array($this, 'order_details_link'));
$this->grocery_crud->columns('order_placing_date','order_placing_user','order_status','order_hospital');
$this->grocery_crud->unset_delete();
$output = $this->grocery_crud->render();

$this->_example_output($output);
}

function order_details_link($primary_key, $row)
{
return site_url('main/order_detail').'?order=' . $row->id;
}



I can add the actual main order using the above, but the drill-down for the order_items is not working. It doesn't show the button, create a new order detail view (or automatically edit it) :(

I'm sure I'm doing something obvious wrong - help?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 24 March 2012 - 21:23 PM

In your case you just need the 1-1 relation that grocery CRUD doesn't automatically support it yet.

So the only way to do it right now is with the combination of the add_action and the getState method. I will be more specific:

You where absolutely right to the redirection link. So The only wrong thing that you have is the callback.
It is the only way to do it right now. In the future I will probably have the relation_1_1 that it will make our life even easier with
similar situations.

So In your case you will have something like this:


function order_details_link($primary_key, $row)
{
return site_url('main/order_redirect/'.$row->id);
}


and :

function order_redirect($order_id)
{
$this->db->where('order_id',$order_id);
$id = $this->db->get('orders_detail')->row()->id;
redirect('main/order_detail/edit/'.$id);
}


Just don't forget to use the getState method ( http://www.grocerycrud.com/documentation/options_functions/getState ) .
So the order_detail function will be someting like this:


public function order_detail()
{
$this->grocery_crud->set_table('orders_detail');
....
....
$output = $this->grocery_crud->render();

$state = $crud->getState();
$state_info = $crud->getStateInfo();
if($state == 'list')
{
redirect('main/order');
}
else
{
$this->_example_output($output);
}
}


kk8
  • profile picture
  • Member

Posted 25 March 2012 - 19:44 PM

Super, thanks -- have built a workaround for this.

Quick question on the below -- it's not working -- what am I doing wrong?

$this->grocery_crud->change_field_type('order_fulfillment_date','hidden',date('d/m/Y'));


Thanks!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 26 March 2012 - 06:23 AM

Try this:


$this->grocery_crud->change_field_type('order_fulfillment_date','hidden',date('Y-m-d'));


and probably will work fine.

The problem is that when you change a type you have only one type and not multiple. For example if you change the type in hidden is not "date" type anymore (for grocery CRUD I mean) so it can not recogize the 'd/m/Y' thing.