public function delete(ProductDeleteEvent $event)
    {
        if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) {
            $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
            $con->beginTransaction();

            try {
                $fileList = ['images' => [], 'documentList' => []];

                // Get product's files to delete after product deletion
                $fileList['images']['list'] = ProductImageQuery::create()
                    ->findByProductId($event->getProductId());
                $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;

                $fileList['documentList']['list'] = ProductDocumentQuery::create()
                    ->findByProductId($event->getProductId());
                $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;

                // Delete product
                $product
                    ->setDispatcher($this->eventDispatcher)
                    ->delete($con)
                ;

                $event->setProduct($product);

                // Dispatch delete product's files event
                foreach ($fileList as $fileTypeList) {
                    foreach ($fileTypeList['list'] as $fileToDelete) {
                        $fileDeleteEvent = new FileDeleteEvent($fileToDelete);
                        $this->eventDispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
                    }
                }

                $con->commit();
            } catch (\Exception $e) {
                $con->rollBack();
                throw $e;
            }
        }
    }
public function delete(ProductDeleteEvent $event)
    {
        if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) {
            $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
            $con->beginTransaction();

            try {
                $fileList = ['images' => [], 'documentList' => []];

                // Get product's files to delete after product deletion
                $fileList['images']['list'] = ProductImageQuery::create()
                    ->findByProductId($event->getProductId());
                $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;

                $fileList['documentList']['list'] = ProductDocumentQuery::create()
                    ->findByProductId($event->getProductId());
                $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;

                // Delete product
                $product
                    ->setDispatcher($this->eventDispatcher)
                    ->delete($con)
                ;

                $event->setProduct($product);

                // Dispatch delete product's files event
                foreach ($fileList as $fileTypeList) {
                    foreach ($fileTypeList['list'] as $fileToDelete) {
                        $fileDeleteEvent = new FileDeleteEvent($fileToDelete);
                        $this->eventDispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
                    }
                }

                $con->commit();
            } catch (\Exception $e) {
                $con->rollBack();
                throw $e;
            }
        }
    }
public function delete ( ProductDeleteEvent $ event ) { if ( null !== $ product = ProductQuery :: create ( ) -> findPk ( $ event -> getProductId ( ) ) ) { $ con = Propel :: getWriteConnection ( ProductTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ fileList = [ 'images' => [ ] , 'documentList' => [ ] ] ; // Get product's files to delete after product deletion $ fileList [ 'images' ] [ 'list' ] = ProductImageQuery :: create ( ) -> findByProductId ( $ event -> getProductId ( ) ) ; $ fileList [ 'images' ] [ 'type' ] = TheliaEvents :: IMAGE_DELETE ; $ fileList [ 'documentList' ] [ 'list' ] = ProductDocumentQuery :: create ( ) -> findByProductId ( $ event -> getProductId ( ) ) ; $ fileList [ 'documentList' ] [ 'type' ] = TheliaEvents :: DOCUMENT_DELETE ; // Delete product $ product -> setDispatcher ( $ this -> eventDispatcher ) -> delete ( $ con ) ; $ event -> setProduct ( $ product ) ; // Dispatch delete product's files event foreach ( $ fileList as $ fileTypeList ) { foreach ( $ fileTypeList [ 'list' ] as $ fileToDelete ) { $ fileDeleteEvent = new FileDeleteEvent ( $ fileToDelete ) ; $ this -> eventDispatcher -> dispatch ( $ fileTypeList [ 'type' ] , $ fileDeleteEvent ) ; } } $ con -> commit ( ) ; } catch ( \ Exception $ e ) { $ con -> rollBack ( ) ; throw $ e ; } } }
Delete a product entry

@param \Thelia\Core\Event\Product\ProductDeleteEvent $event
@throws \Exception
Delete a product entry