Example #1
0
 /**
  * Delete a product template entry
  *
  * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
  */
 public function delete(TemplateDeleteEvent $event)
 {
     if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
         // Check if template is used by a product
         $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count();
         if ($product_count <= 0) {
             $template->setDispatcher($event->getDispatcher())->delete();
         }
         $event->setTemplate($template);
         $event->setProductCount($product_count);
     }
 }
Example #2
0
 /**
  * Delete a product template entry
  *
  * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
  * @throws \Exception
  */
 public function delete(TemplateDeleteEvent $event)
 {
     if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
         // Check if template is used by a product
         $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count();
         if ($product_count <= 0) {
             $con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME);
             $con->beginTransaction();
             try {
                 $template->setDispatcher($event->getDispatcher())->delete($con);
                 // We have to also delete any reference of this template in category tables
                 // We can't use a FK here, as the DefaultTemplateId column may be NULL
                 // so let's take care of this.
                 CategoryQuery::create()->filterByDefaultTemplateId($event->getTemplateId())->update(['DefaultTemplateId' => null], $con);
                 $con->commit();
             } catch (\Exception $ex) {
                 $con->rollback();
                 throw $ex;
             }
         }
         $event->setTemplate($template);
         $event->setProductCount($product_count);
     }
 }
Example #3
0
 /**
  * @param array $argArray
  * @depends testUpdate
  */
 public function testRemoveTemplate($argArray)
 {
     $category = $argArray[0];
     $template = $argArray[1];
     $event = new TemplateDeleteEvent($template->getId());
     $event->setDispatcher($this->getDispatcher());
     $action = new \Thelia\Action\Template();
     $action->delete($event);
     $this->assertInstanceOf('Thelia\\Model\\Template', $event->getTemplate());
     $theCat = CategoryQuery::create()->findPk($category->getId());
     $this->assertNull($theCat->getDefaultTemplateId());
     return $category;
 }
 /**
  * Process delete failure, which may occurs if template is in use.
  *
  * @param TemplateDeleteEvent $deleteEvent
  * @return null|\Thelia\Core\HttpFoundation\Response
  */
 protected function performAdditionalDeleteAction($deleteEvent)
 {
     if ($deleteEvent->getProductCount() > 0) {
         $this->getParserContext()->setGeneralError($this->getTranslator()->trans("This template is in use in some of your products, and cannot be deleted. Delete it from all your products and try again."));
         return $this->renderList();
     }
     // Normal delete processing
     return null;
 }