if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
+ // Логирование создания
+ $mpPriceLog = new MarketplacePricesLog([
+ 'marketplace_prices_id' => $model->id,
+ 'price_before' => null,
+ 'price_after' => $model->price,
+ 'old_price_before' => null,
+ 'old_price_after' => $model->old_price,
+ 'action' => 1, // create
+ ]);
+ if (!$mpPriceLog->save()) {
+ Yii::error("Ошибка создания лога цены: " . json_encode($mpPriceLog->getErrors()), __METHOD__);
+ }
+
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
{
$model = $this->findModel($id);
- if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
+ if ($this->request->isPost && $model->load($this->request->post())) {
+ // Сохраняем предыдущие значения для логирования
+ $beforePrice = $model->price;
+ $beforeOldPrice = $model->old_price;
+
+ if ($model->save()) {
+ // Логирование обновления
+ if ($beforePrice !== $model->price || $beforeOldPrice !== $model->old_price) {
+ $mpPriceLog = new MarketplacePricesLog([
+ 'marketplace_prices_id' => $model->id,
+ 'price_before' => $beforePrice,
+ 'price_after' => $model->price,
+ 'old_price_before' => $beforeOldPrice,
+ 'old_price_after' => $model->old_price,
+ 'action' => 2, // update
+ ]);
+ if (!$mpPriceLog->save()) {
+ Yii::error("Ошибка создания лога цены: " . json_encode($mpPriceLog->getErrors()), __METHOD__);
+ }
+ }
+
+ return $this->redirect(['view', 'id' => $model->id]);
+ }
}
// Данные для выпадающих списков