Explorar el Código

[Administration] Accessoires : gestion suppression

develop
Guillaume Bourgeois hace 4 meses
padre
commit
0312aa18b7
Se han modificado 3 ficheros con 38 adiciones y 1 borrados
  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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

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

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

return $accessory->delete();
}
}

Cargando…
Cancelar
Guardar