You need to remove the optical cable and connect an HDMI cable from the tv’s HDMI ( ARC) port to the soundbar’s ARC port.
After doing that turn on LG Simplink in the settings. Then you will be able to control the soundbar from the magic remote.
You can also add the device using device connector -> add device.
Simplink is basically HDMI CEC that allows control of connected HDMI devices.
Optical cable is just an audio output cable and cannot be used to control the other device.
Get a decent HDMI cable.