Skip to content

Commit

Permalink
Add item grid to backend order form
Browse files Browse the repository at this point in the history
Creates a new form widget for that lists items, and uses this on
the backend to display order items. Read-only at the moment, but
it's better than nothing... Also set a blank label for the field
  • Loading branch information
dshoreman committed Oct 17, 2014
1 parent cea2b83 commit 4def26d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public function registerNavigation()
];
}

public function registerFormWidgets()
{
return [
'Dshoreman\Shop\FormWidgets\ItemGrid' => [
'label' => 'Order Item Grid',
'alias' => 'itemgrid',
],
];
}

public function registerPermissions()
{
return [
Expand Down
28 changes: 28 additions & 0 deletions formwidgets/ItemGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Dshoreman\Shop\FormWidgets;

use Backend\Classes\FormWidgetBase;
use Backend\Widgets\Grid;

class ItemGrid extends FormWidgetBase {

public function widgetDetails()
{
return [
'name' => 'Item Grid',
'description' => 'Renders a grid of items from an order',
];
}

public function render()
{
$this->prepareVars();

return $this->makePartial('itemgrid');
}

public function prepareVars()
{
$this->vars['items'] = json_decode($this->formField->value);
}

}
22 changes: 22 additions & 0 deletions formwidgets/itemgrid/partials/_itemgrid.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table class="table table-condensed">
<thead>
<tr>
<th>Item #</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td><?= $item->id ?></td>
<td><?= $item->name ?></td>
<td><?= $item->price ?></td>
<td><?= $item->qty ?></td>
<td><?= $item->subtotal ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
3 changes: 2 additions & 1 deletion models/order/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ tabs:
tab: Addresses

items:
label: Order Items
label:
tab: Items
type: itemgrid
total:
label: Order Value
span: right
Expand Down

0 comments on commit 4def26d

Please sign in to comment.