Hallo zusammen,
ich bin gerade dabei ein Plugin zu bauen, dass die Bestellpositionen Ansicht im Backend unter Kunden -> Bestellungen -> Stift Icon -> Tab „Positionen“ erweitern soll um eine Spalte.
Die Daten werden angereichert, das klappt soweit, auch meine zusäztliche Spalte wird angefügt, doch nur leider kann ich sie nirgendswo auswählen zum Anzeigen:
Mein Subscriber (der Übersicht halber habe ich alles in eine Klasse geapackt, normalerweise habe ich noch eine Basisklasse):
container = $container;
$this->em = $this->container->get('models');
}
public static function getSubscribedEvents ()
{
return [
'Shopware_Controllers_Backend_Order::getList::after' => 'onBackendOrdersGetList',
'Enlight_Controller_Action_PostDispatch_Backend_Order' => 'onPostDispatchBackendOrder'
];
}
final protected function getPath()
{
if (empty($this->path)) {
$paths = explode(DIRECTORY_SEPARATOR, __DIR__ );
unset($paths[count($paths) - 1]);
$this->path = implode(DIRECTORY_SEPARATOR, $paths);
}
return $this->path;
}
/**
* A function that gives you the controller, view and request object from the EventArgs object
*
* Call it using
* list($controller, $view, $request) = self::getEverythingfromArgs($args);
*
* @param \Enlight_Event_EventArgs $args
* @return array
*/
protected static function getEverythingFromArgs(\Enlight_Event_EventArgs $args)
{
/**
* @var \Enlight_Controller_Action $controller
*/
$controller = $args->getSubject();
/**
* @var \Enlight_View_Default $view
*/
$view = $controller->View();
/**
* @var \Zend_Controller_Request_Http $request
*/
$request = $controller->Request();
return array($controller, $view, $request);
}
/**
* @param \Enlight_Hook_HookArgs $args
*
* Modifies every backend order getList call and adds our name embossing data.
*
* @return array
*/
public function onBackendOrdersGetList (\Enlight_Hook_HookArgs $args)
{
$json = $args->getReturn();
$orders = &$json['data'];
if (isset($orders[0]) && isset($orders[0]['details'])) {
$detailIds = array();
foreach ($orders as $order) {
foreach ($order['details'] as $detail) {
$detailIds[] = $detail['id'];
}
}
$myModelRepo = $this->em->getRepository(MyModel::class);
/**
* @var \Doctrine\ORM\Query $query
*/
$query = $myModelRepo->getWithMyData($detailIds);
$resultSets = $query->getResult(Query::HYDRATE_ARRAY);
foreach ($orders as $key => $order) {
foreach ($order['details'] as $detailKey => $detail) {
$myCol = 'leer';
foreach ($resultSets as $resultSet) {
if ($resultSet['orderDetailId'] === $detail['id']) {
$myCol = $resultSet['myCol'];
break;
}
}
$orders[$key]['details'][$detailKey]['myCol'] = $myCol;
}
}
}
$json['data'] = $orders;
$args->setReturn($json);
return $json;
}
public function onPostDispatchBackendOrder (\Enlight_Event_EventArgs $args)
{
/**
* @var \Enlight_Controller_Action $controller
* @var \Enlight_View_Default $view
* @var \Zend_Controller_Request_Http $request
*/
list($controller, $view, $request) = self::getEverythingFromArgs($args);
if (strtolower($request->getActionName()) === 'load') {
$this->handleBackendOrderLoad($view);
}
}
private function handleBackendOrderLoad (\Enlight_View_Default $view)
{
$view->addTemplateDir($this->getPath() . '/Resources/Views/backend_components/');
$view->extendsTemplate('order/model/position.js');
$view->extendsTemplate('order/view/list/position.js');
}
}
Meine ExtJS Model Erweiterung (Pfad: Resources/Views/backend_components/order/model/position.js):
// {block name='backend/order/model/position/fields' append}
// {literal}
{ name: 'myCol', type: 'string' },
// {/literal}
// {/block}
Meine Grid Erweiterung (Pfad: Resources/Views/backend_components/order/view/list/position.js):
//{namespace name='backend/order/main'}
//{block name='backend/order/view/list/position' append}
//{literal}
Ext.define('MyModule.apps.backend.order.view.list.position', {
override: 'Shopware.apps.Order.view.list.Position',
initComponent: function () {
var me = this;
me.snippets = Object.assign(
me.snippets,
{
//{/literal}
myCol: '{s name=myCol}{/s}',
myColNA: '{s name=myColNA}{/s}'
//{literal}
}
);
console.log('im initComponent()');
me.callParent(arguments);
},
/**
* Creates the grid columns
*
* @return [array] grid columns
*/
getColumns: function () {
var me = this;
var columns = me.callParent(arguments);
columns.push({
header: me.snippets.myCol,
dataIndex: 'myCol',
sortable: false,
flex: 1,
renderer: me.myColRenderer
});
console.log('bin drin im getColumns', columns);
return columns;
},
myColRenderer: function (value, metaData, rowRecord) {
console.log('value', value);
console.log('metaData', metaData);
console.log('rowRecord', rowRecord);
return 'hallo';
}
});
//{/literal}
//{/block}
Der Vollständigkeit halber meine services.xml:
Was mir aufgefallen ist, der renderer für meine Spalte wird nicht aufgerufen. Ich bin aber ratlos warum das so ist. Für Hilfe wäre ich sehr dankbar.
Etwas ältere Literatur, die ich dazu gefunden habe: Advanced Example how to create 2 custom fields, fill them in order process, display them in backend order list as new columns and make them editable in order detail view · GitHub
Ich benutze Shopware 5.2.27.
MFG
derwunner