Beispiel #1
0
 /**
  * This method check the activation and deactivation dates of sales, and perform
  * the required action depending on the current date.
  *
  * @param  SaleActiveStatusCheckEvent                $event
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function checkSaleActivation(SaleActiveStatusCheckEvent $event)
 {
     $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $now = time();
         // Disable expired sales
         if (null !== ($salesToDisable = SaleQuery::create()->filterByActive(true)->filterByEndDate($now, Criteria::LESS_THAN)->find())) {
             /** @var SaleModel $sale */
             foreach ($salesToDisable as $sale) {
                 $sale->setActive(false)->save();
                 // Update related products sale status
                 $event->getDispatcher()->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale));
             }
         }
         // Enable sales that should be enabled.
         if (null !== ($salesToEnable = SaleQuery::create()->filterByActive(false)->filterByStartDate($now, Criteria::LESS_EQUAL)->filterByEndDate($now, Criteria::GREATER_EQUAL)->find())) {
             /** @var SaleModel $sale */
             foreach ($salesToEnable as $sale) {
                 $sale->setActive(true)->save();
                 // Update related products sale status
                 $event->getDispatcher()->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale));
             }
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
Beispiel #2
0
 public function testCheckSaleActivation()
 {
     $event = new SaleActiveStatusCheckEvent();
     $event->setDispatcher($this->dispatcher);
     $saleAction = new Sale($this->getContainer());
     $saleAction->checkSaleActivation($event);
 }