From 4def26df96d751fea9bdc354ccddbf9c2b6d85ff Mon Sep 17 00:00:00 2001 From: Dave Shoreman Date: Fri, 17 Oct 2014 21:11:26 +0100 Subject: [PATCH] Add item grid to backend order form 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 --- Plugin.php | 10 ++++++++ formwidgets/ItemGrid.php | 28 +++++++++++++++++++++ formwidgets/itemgrid/partials/_itemgrid.htm | 22 ++++++++++++++++ models/order/fields.yaml | 3 ++- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 formwidgets/ItemGrid.php create mode 100644 formwidgets/itemgrid/partials/_itemgrid.htm diff --git a/Plugin.php b/Plugin.php index 66d93ae..2615bf9 100644 --- a/Plugin.php +++ b/Plugin.php @@ -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 [ diff --git a/formwidgets/ItemGrid.php b/formwidgets/ItemGrid.php new file mode 100644 index 0000000..fda52c2 --- /dev/null +++ b/formwidgets/ItemGrid.php @@ -0,0 +1,28 @@ + '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); + } + +} diff --git a/formwidgets/itemgrid/partials/_itemgrid.htm b/formwidgets/itemgrid/partials/_itemgrid.htm new file mode 100644 index 0000000..ac5faa9 --- /dev/null +++ b/formwidgets/itemgrid/partials/_itemgrid.htm @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
Item #NamePriceQuantitySubtotal
id ?>name ?>price ?>qty ?>subtotal ?>
diff --git a/models/order/fields.yaml b/models/order/fields.yaml index 9520fbe..295c40c 100644 --- a/models/order/fields.yaml +++ b/models/order/fields.yaml @@ -82,8 +82,9 @@ tabs: tab: Addresses items: - label: Order Items + label: tab: Items + type: itemgrid total: label: Order Value span: right