# Backend Plugin Batch Processes - Beispiel, funktioniert nicht

**URL:** https://forum.shopware.com/t/backend-plugin-batch-processes-beispiel-funktioniert-nicht/45855
**Category:** Shopware 3.5
**Tags:** programming
**Created:** [18. Mai 2017 um 19:06 UTC](https://forum.shopware.com/t/backend-plugin-batch-processes-beispiel-funktioniert-nicht/45855 "2017-05-18T19:06:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jamie\_11](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jamie\_11](https://forum.shopware.com/u/jamie_11)
#### Post date: [18. Mai 2017 um 19:06 UTC](https://forum.shopware.com/t/backend-plugin-batch-processes-beispiel-funktioniert-nicht/45855/1 "2017-05-18T19:06:41Z")

</div>

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&nbsp;[Batch Processes Beispiel](https://developers.shopware.com/developers-guide/backend-components/batch-processes/) funktioniert auch alles wunderbar.

Ich habe das&nbsp;Plugin&nbsp;[SwagProductAssoc](https://developers.shopware.com/developers-guide/backend-components/associations/)&nbsp;mit dem Code aus&nbsp;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

![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/2f0984456f8dd47c5beb0a68b72c3d6cf62ef2aa.jpeg)

&nbsp;

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);
            }
        });
    }

});

```

&nbsp;

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  
&nbsp;

![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/2f0984456f8dd47c5beb0a68b72c3d6cf62ef2aa.jpeg)

&nbsp;

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?&nbsp;

Danke im Voraus für hilfreiche Antworten&nbsp; ![Smile](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/smile.png "Smile")

&nbsp;

LG
