Browse Source

[Administration] Accessoires : gestion suppression

develop
Guillaume Bourgeois 4 months ago
parent
commit
0312aa18b7
3 changed files with 38 additions and 1 deletions
  1. +1
    -1
      backend/controllers/AccessoryController.php
  2. +28
    -0
      console/migrations/m240704_071250_create_foreign_keys_product_accessory.php
  3. +9
    -0
      domain/Product/Accessory/AccessoryManager.php

+ 1
- 1
backend/controllers/AccessoryController.php View File

@@ -122,7 +122,7 @@ class AccessoryController extends BackendController
public function actionDelete(int $id): Response
{
$accessory = $this->findAccessory($id);
if($accessory->delete()) {
if($this->getAccessoryModule()->getManager()->deleteAccessory($accessory)) {
$this->setFlash('success', "Accessoire supprimé");
}


+ 28
- 0
console/migrations/m240704_071250_create_foreign_keys_product_accessory.php View File

@@ -0,0 +1,28 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240704_071250_create_foreign_keys_product_accessory
*/
class m240704_071250_create_foreign_keys_product_accessory extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addForeignKey('product_accessory_fk_id_product', 'product_accessory', 'id_product', 'product', 'id');
$this->addForeignKey('product_accessory_fk_id_accessory', 'product_accessory', 'id_accessory', 'accessory', 'id');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('product_accessory_fk_id_product', 'product_accessory');
$this->dropForeignKey('product_accessory_fk_id_accessory', 'product_accessory');
}
}

+ 9
- 0
domain/Product/Accessory/AccessoryManager.php View File

@@ -42,4 +42,13 @@ class AccessoryManager extends AbstractManager
}
}
}

public function deleteAccessory(Accessory $accessory): bool
{
foreach($accessory->getProductAccessories() as $productAccessory) {
$productAccessory->delete();
}

return $accessory->delete();
}
}

Loading…
Cancel
Save