JavaScript
Since you stated in your comment that you want the price to be updated realtime, you need to add some JavaScript. Once again, there are various ways to do this. The most elegant way would require you to create a new UI Component that does your magic on change and apply it to the cost-input-field.
There also is a more 'hacky' way to do is by extending the JavaScript Magento_Ui/js/form/element/abstract
and manipulate the onUpdate()
-method. This method is fired when the user changes input on any input field so we need to do an additional check:
/**
* Callback that fires when 'value' property is updated.
*/
onUpdate: function () {
this.bubble('update', this.hasChanged());
if (this.namespace === 'product_form' && this.index === 'cost') {
// The most hacky solution I've ever seen ...
var priceField = document.querySelector('[name="product\\[price\\]"]');
priceField.value = this.value() * 1.5;
// Force trigger the 'change'-event on this field:
var event = new Event('change');
priceField.dispatchEvent(event);
}
this.validate();
}
Needless to say, this is very ugly. But if you look at the code, you'll see that the update
-event bubbles. So a more proper way would be to utilise this event and leave the original class intact. Unfortunately for you I don't have too much experience on this specific area, but perhaps it gives you a good starting point.
In Conclusion
To achieve your goal you need to do the following:
- Update on save (in case the product is saved somewhere other than the form).
- Extend an existing JS Component to manipulate the
onUpdate
method - OR - utilize the event bubbling in UI Components.