public function actionStoreChanges() { if (isset($_POST['CarPart'])) { $result = []; $selectedParts = $_POST['CarPart']; $carPart = CarPart::getByParts($selectedParts['size_id'], $selectedParts['color_id'], $selectedParts['damage_id']); if (isset($carPart, $carPart->price)) { $total = (double) $carPart->price->total; if ($_POST['mode'] == 0) { Yii::$app->session['carPartTotal'] += $total; } elseif ($_POST['mode'] == 1) { Yii::$app->session['carPartTotal'] -= $total; } $result['total'] = Yii::$app->formatter->asCurrency(Yii::$app->session['carPartTotal']); $result['error'] = false; } else { $result['message'] = Yii::t('app', 'The requested car part need to be defined. You can do it <a href="{route}">here</a>', ['route' => Url::to(['car-part/create']) . '?' . http_build_query($_POST['CarPart'])]); $result['error'] = true; } echo json_encode($result); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }