How to add custom field in Premium items Module in Shopware 5?

Viewed 130

I am new in Shopware 5. I want to create custom field in Premium item module. Please check the screenshot.

I have checked there is no any attribute table for Premium items.

Please tell me how I can create custom field here: Screenshot illustrating where to add a maximum order value field

1 Answers

You did not mention what you tried so far, so I will give you some basic information how to start. Feel free to come back with more questions.

Adding the field endPrice to the detail view

The component you want to extend is Shopware.apps.Premium.view.premium.Detail.

You can add your new field, with similar code as the startPrice field.

See the developer guide on backend extensions. This will guide you trough the steps required to extend the detail window. (more information about detail windows is also available)

Extending JS Model / Controller

Basically I recommend to full text search through https://github.com/shopware/shopware/tree/5.7/themes/Backend/ExtJs/backend/premium for startPrice. This will give you a hint what else to extend, to be able to persist your new field endPrice.

Implementing the storage logic

You also need to implement the logic so that the setting actually will be saved. This core code is in Premium.php - there is a special formatting for start-price:

$params['startPrice'] = str_replace(',', '.', $params['startPrice']);

which you might do via a hook.

The basic parameters are stored in s_addon_premiums, but you cannot extend the core model, so you might want to use workarounds as described in another StackOverflow question to store the value of your new endPrice field.

Adding the logic

Finally you can hook into sGetPremiums. You can use an after hook to remove those premium items which should not be added from the returned $premiums array, because the order exceeds the endPrice.

Related