Hung Mac's memory

Hung Mac's memory

How to overwrite a core element by adding a new defaultConfig field in Shopware 6

How to overwrite a core element by adding a new defaultConfig field in Shopware 6

Subscribe to my newsletter and never miss my upcoming articles

I will do an example with the product listing cms and add a new field name is hungMac.

In my plugin, I will create an index.js file at src/Resources/app/administration/src/module/sw-cms/elements/product-listing/index.js

const cmsElements = Shopware.Service('cmsService').getCmsElementRegistry();

// Get the cms element of product-listing cms
const cmsElProductListing = cmsElements['product-listing'];

// Check the field named HungMac does not exist yet
if (!cmsElProductListing.defaultConfig.hungMac) {
    cmsElProductListing.defaultConfig = {
        ...cmsElProductListing.defaultConfig,
        hungMac: {
            source: 'static',
            value: 'this is my data'
        },
    }

Note: after adding, you should remove the old element in your layout and then add it again.

 
Share this