/** * @depends testAddAccessory */ public function testRemoveAccessory(ProductModel $product) { $accessories = AccessoryQuery::create()->filterByProductId($product->getId())->find(); $this->assertEquals(1, count($accessories)); $currentAccessory = $accessories->getFirst(); $event = new ProductDeleteAccessoryEvent($product, $currentAccessory->getAccessory()); $event->setDispatcher($this->getDispatcher()); $action = new Product(); $action->removeAccessory($event); $this->assertEquals(0, AccessoryQuery::create()->filterByProductId($product->getId())->count()); return $product; }
public function removeAccessory(ProductDeleteAccessoryEvent $event) { $accessory = AccessoryQuery::create()->filterByAccessory($event->getAccessoryId())->filterByProductId($event->getProduct()->getId())->findOne(); if ($accessory !== null) { $accessory->setDispatcher($event->getDispatcher())->delete(); } }