Hallo Zusammen,
ich fange gerade an mich in der Plugin-Entwicklung einzuarbeiten und habe mich durch die developer Guide schon ganz gut durchgearbeitet. (Shopware Version 4.3.7)
Bis auf das Batch Processes Beispiel funktioniert auch alles wunderbar.
Ich habe das Plugin SwagProductAssoc mit dem Code aus Batch Processes erweitert, bekomme es aber nicht funktionsfähig. Anscheinend werden die Methoden nicht aufgerufen. Ich habe es mit console.log(); versucht zu testen Fehler werden mir keine angezeigt. Das Fenster öffnet sich zwar, aber da tut sich nicht (siehe Screenshot). Abbrechen ist auch nicht möglich
Hier der Code:
SwagProduct.php Controller
leftJoin( 'product.tax', 'tax' );
$builder->addSelect( array(
'tax'
) );
return $builder;
}
protected function getDetailQuery( $id ) {
$builder = parent::getDetailQuery( $id );
$builder->leftJoin( 'product.tax', 'tax' )->leftJoin( 'product.attribute', 'attribute' );
$builder->addSelect( array(
'tax',
'attribute'
) );
return $builder;
}
protected function getAdditionalDetailData( array $data ) {
$data ['categories'] = $this->getCategories( $data ['id'] );
$data ['variants'] = array();
return $data;
}
protected function getCategories( $productId ) {
$builder = $this->getManager()->createQueryBuilder();
$builder->select( array(
'products',
'categories'
) )->from( 'Shopware\CustomModels\Product\Product', 'products' )->innerJoin( 'products.categories', 'categories' )->where( 'products.id = :id' )->setParameter( 'id', $productId );
$paginator = $this->getQueryPaginator( $builder );
$data = $paginator->getIterator()->current();
return $data ['categories'];
}
public function deactivateProductsAction() {
try {
$productId = $this->Request()->getParam( 'productId' );
/**@var $product \Shopware\CustomModels\Product\Product */
$product = $this->getManager()->find( $this->model, $productId );
$product->setActive( 0 );
$this->getManager()->flush( $product );
$this->View()->assign( array(
'success' => true
) );
} catch ( Exception $e ) {
$this->View()->assign( array(
'success' => false,
'error' => $e->getMessage()
) );
}
}
public function changeCreateDateAction() {
try {
$productId = $this->Request()->getParam( 'productId' );
/**@var $product \Shopware\CustomModels\Product\Product */
$product = $this->getManager()->find( $this->model, $productId );
$product->setCreateDate( 'now' );
$this->getManager()->flush( $product );
$this->View()->assign( array(
'success' => true
) );
} catch ( Exception $e ) {
$this->View()->assign( array(
'success' => false,
'error' => $e->getMessage()
) );
}
}
}
product.js - Product list view (Extjs)
Ext.define('Shopware.apps.SwagProduct.view.list.Product', {
extend: 'Shopware.grid.Panel',
alias: 'widget.product-listing-grid',
region: 'center',
configure: function () {
return {
detailWindow: 'Shopware.apps.SwagProduct.view.detail.Window'
};
},
createToolbarItems: function () {
var me = this, items = me.callParent(arguments);
items = Ext.Array.insert(items, 2, [me.createToolbarButton()]);
return items;
},
createToolbarButton: function () {
var me = this;
return Ext.create('Ext.button.Button', {
text: 'Change products',
handler: function () {
me.fireEvent('change-products', me);
}
});
}
});
main.js - Controller
Ext.define('Shopware.apps.SwagProduct.controller.Main', {
extend: 'Enlight.app.Controller',
init: function () {
var me = this;
me.callOverridden();
me.control({
'product-listing-grid': {
'change-products': me.displayProcessWindow
}
});
Shopware.app.Application.on('deactivate-products-process', me.onDeactivateProducts);
Shopware.app.Application.on('change-create-date-process', me.onChangeCreateDate);
me.mainWindow = me.getView('list.Window').create({}).show();
},
onChangeCreateDate: function (task, record, callback) {
Ext.Ajax.request({
url: '{url controller=SwagProduct action=changeCreateDate}',
method: 'POST',
params: {
productId: record.get('id')
},
success: function (response, operation) {
callback(response, operation);
}
});
},
onDeactivateProducts: function (task, record, callback) {
Ext.Ajax.request({
url: '{url controller=SwagProduct action=deactivateProducts}',
method: 'POST',
params: {
productId: record.get('id')
},
success: function (response, operation) {
callback(response, operation);
}
});
},
displayProcessWindow: function (grid) {
var selection = grid.getSelectionModel().getSelection();
if (selection.length <= 0) return;
Ext.create('Shopware.window.Progress', {
title: 'Batch processing',
configure: function () {
return {
tasks: [{
event: 'deactivate-products-process',
data: Ext.clone(selection),
text: 'Product [0] of [1]'
}],
infoText: 'Deactivate products' +
'You can use the `Cancel process` button the cancel the process. ' +
'Depending on the amount of the data set, this process might take a while.'
}
}
}).show();
}
});
Ordnerstruktur
Wenn ich das Events aufrufe, dann wird auch die Controller-Action gestartet.
me.control({
'product-listing-grid': {
'change-products': me.onDeactivateProducts
}
});
Habe ich irgendwas übersehen?
Danke im Voraus für hilfreiche Antworten
LG