Exemplo n.º 1
0
 /**
  * Toggle Sale activity
  *
  * @param SaleToggleActivityEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function toggleActivity(SaleToggleActivityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $sale = $event->getSale();
     $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $sale->setDispatcher($dispatcher)->setActive(!$sale->getActive())->save($con);
         // Update related products sale status
         $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale));
         $event->setSale($sale);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
Exemplo n.º 2
0
 public function testSaleToggleVisibility()
 {
     $sale = $this->getRandomSale();
     $visibility = $sale->getActive();
     $event = new SaleToggleActivityEvent($sale);
     $event->setDispatcher($this->dispatcher);
     $saleAction = new Sale($this->getContainer());
     $saleAction->toggleActivity($event);
     $updatedSale = $event->getSale();
     $this->assertInstanceOf('Thelia\\Model\\Sale', $updatedSale);
     $this->assertEquals(!$visibility, $updatedSale->getActive());
 }