public function addAccessory(ProductAddAccessoryEvent $event) { if (AccessoryQuery::create()->filterByAccessory($event->getAccessoryId())->filterByProductId($event->getProduct()->getId())->count() <= 0) { $accessory = new Accessory(); $accessory->setDispatcher($event->getDispatcher())->setProductId($event->getProduct()->getId())->setAccessory($event->getAccessoryId())->save(); } }