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 # | +Name | +Price | +Quantity | +Subtotal | +
---|---|---|---|---|
= $item->id ?> | += $item->name ?> | += $item->price ?> | += $item->qty ?> | += $item->subtotal ?> | +