# How to save state of the custom block while saving the product?

**URL:** <https://forum.shopware.com/t/how-to-save-state-of-the-custom-block-while-saving-the-product/87310>\
**Category:** Programming (EN)\
**Tags:** programming\
**Created:** [30. April 2021 um 15:22 UTC](https://forum.shopware.com/t/how-to-save-state-of-the-custom-block-while-saving-the-product/87310 "2021-04-30T15:22:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![valeria.zaviriukha](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@valeria.zaviriukha](https://forum.shopware.com/u/valeria.zaviriukha)\
**Post date:** [30. April 2021 um 15:22 UTC](https://forum.shopware.com/t/how-to-save-state-of-the-custom-block-while-saving-the-product/87310/1 "2021-04-30T15:22:02Z")

</div>

Hi everyone! I will be grateful for your advice!  
I need to save state of the custom switch in the product.  
To the file sw-product-basic-form.html.twig i added this switch. When the state of the switch changes it shows or hides the block. By default the block is hidden. This is switch code.

 ![Снимок экрана 2021-04-30 в 18.28.28](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/3/3aa4b1b9a37f41372cda146e177a0886574c7ffc.png)

But when the product is saved, the state of the switch is not saved. I suggested that need to rewrite the function onSave().  
I found a file app/administration/src/module/sw-product/page/sw-product-detail/state.js . If I understand correctly (but this is most likely a mistake ) it stores the states of the different parts of the product. So i add in state qrCode: {} and in loading - qrCode: false. Then i add a mutation

```
    setQrCode(state, newQrCode) {
        state.qrCode = newQrCode;
    }

```

Then in file app/administration/src/module/sw-product/page/sw-product-detail/index.js i added a call to my custom state

```
    loadQrFeature() {
        Shopware.State.commit('swProductDetail/setLoading', ['qrCode', true]);

        return this.featureSetRepository.search(this.customQrCodeCriteria, Shopware.Context.api).then((res) => {
            Shopware.State.commit('swProductDetail/qrCode', res);
        }).then(() => {
            Shopware.State.commit('swProductDetail/setLoading', ['qrCode', false]);
        });
    },

```

and add criteria for this one

```
    customQrCodeCriteria() {
        const criteria = new Criteria(1, 1);
        return criteria;
    }

```

And declared this function in createState() function promise. But it didn’t work.

The task itself is not difficult, but I’m confused. As I said at the beginning - I will be grateful for advice and hints on how to do it right.
