Skip to content

Commit

Permalink
Added the touching of the parent model (product/master/variant) when …
Browse files Browse the repository at this point in the history
…changing property assignments
  • Loading branch information
fulopattila122 committed Sep 25, 2024
1 parent bd4cf9c commit c372d36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
- Added input validation at Property Value assignment
- Added the configuration widget, that can handle JSON config samples
- Fixed master products not being listed on the Channel show page
- Changed the product/master product creation so that the record creation and channel assignment are in a single transaction
- Changed the product/master product creation so that the record creation and channel assignment are in a single transaction
- Added the touching of the parent model (product/master/variant) when changing property assignments

## 4.1.1
##### 2024-07-23
Expand Down
15 changes: 13 additions & 2 deletions src/Http/Controllers/PropertyValueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Vanilo\Admin\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Konekt\AppShell\Http\Controllers\BaseController;
use Vanilo\Admin\Contracts\Requests\CreatePropertyValue;
use Vanilo\Admin\Contracts\Requests\CreatePropertyValueForm;
Expand Down Expand Up @@ -102,8 +103,18 @@ public function destroy(Property $property, PropertyValue $property_value)

public function sync(SyncModelPropertyValues $request, $for, $forId)
{
$model = $request->getFor();
$model->propertyValues()->sync($request->getPropertyValueIds());
DB::beginTransaction();
try {
$model = $request->getFor();
$model->propertyValues()->sync($request->getPropertyValueIds());
$model->touch();
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
flash()->error(__('There was an error at updating the properties: :msg', ['msg' => $e->getMessage()]));

return redirect()->back();
}

$resource = shorten(get_class($model));
if ('master_product_variant' === $resource) {
Expand Down

0 comments on commit c372d36

Please sign in to comment.