public function update(SaleUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $sale = SaleQuery::create()->findPk($event->getSaleId())) {
            $sale->setDispatcher($dispatcher);

            $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);

            $con->beginTransaction();

            try {
                // Disable all promo flag on sale's currently selected products,
                // to reset promo status of the products that may have been removed from the selection.
                $sale->setActive(false);

                $dispatcher->dispatch(
                    TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                    new ProductSaleStatusUpdateEvent($sale)
                );

                $sale
                    ->setActive($event->getActive())
                    ->setStartDate($event->getStartDate())
                    ->setEndDate($event->getEndDate())
                    ->setPriceOffsetType($event->getPriceOffsetType())
                    ->setDisplayInitialPrice($event->getDisplayInitialPrice())
                    ->setLocale($event->getLocale())
                    ->setSaleLabel($event->getSaleLabel())
                    ->setTitle($event->getTitle())
                    ->setDescription($event->getDescription())
                    ->setChapo($event->getChapo())
                    ->setPostscriptum($event->getPostscriptum())
                    ->save($con)
                ;

                $event->setSale($sale);

                // Update price offsets
                SaleOffsetCurrencyQuery::create()->filterBySaleId($sale->getId())->delete($con);

                foreach ($event->getPriceOffsets() as $currencyId => $priceOffset) {
                    $saleOffset = new SaleOffsetCurrency();

                    $saleOffset
                        ->setCurrencyId($currencyId)
                        ->setSaleId($sale->getId())
                        ->setPriceOffsetValue($priceOffset)
                        ->save($con)
                    ;
                }

                // Update products
                SaleProductQuery::create()->filterBySaleId($sale->getId())->delete($con);

                $productAttributesArray = $event->getProductAttributes();

                foreach ($event->getProducts() as $productId) {
                    if (isset($productAttributesArray[$productId])) {
                        foreach ($productAttributesArray[$productId] as $attributeId) {
                            $saleProduct = new SaleProduct();

                            $saleProduct
                                ->setSaleId($sale->getId())
                                ->setProductId($productId)
                                ->setAttributeAvId($attributeId)
                                ->save($con)
                            ;
                        }
                    } else {
                        $saleProduct = new SaleProduct();

                        $saleProduct
                            ->setSaleId($sale->getId())
                            ->setProductId($productId)
                            ->setAttributeAvId(null)
                            ->save($con)
                        ;
                    }
                }

                // Update related products sale status if the Sale is active. This is not required if the sale is
                // not active, as we de-activated promotion for this sale at the beginning ofd this method
                if ($sale->getActive()) {
                    $dispatcher->dispatch(
                        TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                        new ProductSaleStatusUpdateEvent($sale)
                    );
                }

                $con->commit();
            } catch (PropelException $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
public function update(SaleUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $sale = SaleQuery::create()->findPk($event->getSaleId())) {
            $sale->setDispatcher($dispatcher);

            $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);

            $con->beginTransaction();

            try {
                // Disable all promo flag on sale's currently selected products,
                // to reset promo status of the products that may have been removed from the selection.
                $sale->setActive(false);

                $dispatcher->dispatch(
                    TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                    new ProductSaleStatusUpdateEvent($sale)
                );

                $sale
                    ->setActive($event->getActive())
                    ->setStartDate($event->getStartDate())
                    ->setEndDate($event->getEndDate())
                    ->setPriceOffsetType($event->getPriceOffsetType())
                    ->setDisplayInitialPrice($event->getDisplayInitialPrice())
                    ->setLocale($event->getLocale())
                    ->setSaleLabel($event->getSaleLabel())
                    ->setTitle($event->getTitle())
                    ->setDescription($event->getDescription())
                    ->setChapo($event->getChapo())
                    ->setPostscriptum($event->getPostscriptum())
                    ->save($con)
                ;

                $event->setSale($sale);

                // Update price offsets
                SaleOffsetCurrencyQuery::create()->filterBySaleId($sale->getId())->delete($con);

                foreach ($event->getPriceOffsets() as $currencyId => $priceOffset) {
                    $saleOffset = new SaleOffsetCurrency();

                    $saleOffset
                        ->setCurrencyId($currencyId)
                        ->setSaleId($sale->getId())
                        ->setPriceOffsetValue($priceOffset)
                        ->save($con)
                    ;
                }

                // Update products
                SaleProductQuery::create()->filterBySaleId($sale->getId())->delete($con);

                $productAttributesArray = $event->getProductAttributes();

                foreach ($event->getProducts() as $productId) {
                    if (isset($productAttributesArray[$productId])) {
                        foreach ($productAttributesArray[$productId] as $attributeId) {
                            $saleProduct = new SaleProduct();

                            $saleProduct
                                ->setSaleId($sale->getId())
                                ->setProductId($productId)
                                ->setAttributeAvId($attributeId)
                                ->save($con)
                            ;
                        }
                    } else {
                        $saleProduct = new SaleProduct();

                        $saleProduct
                            ->setSaleId($sale->getId())
                            ->setProductId($productId)
                            ->setAttributeAvId(null)
                            ->save($con)
                        ;
                    }
                }

                // Update related products sale status if the Sale is active. This is not required if the sale is
                // not active, as we de-activated promotion for this sale at the beginning ofd this method
                if ($sale->getActive()) {
                    $dispatcher->dispatch(
                        TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                        new ProductSaleStatusUpdateEvent($sale)
                    );
                }

                $con->commit();
            } catch (PropelException $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
public function update ( SaleUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( null !== $ sale = SaleQuery :: create ( ) -> findPk ( $ event -> getSaleId ( ) ) ) { $ sale -> setDispatcher ( $ dispatcher ) ; $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { // Disable all promo flag on sale's currently selected products, // to reset promo status of the products that may have been removed from the selection. $ sale -> setActive ( false ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; $ sale -> setActive ( $ event -> getActive ( ) ) -> setStartDate ( $ event -> getStartDate ( ) ) -> setEndDate ( $ event -> getEndDate ( ) ) -> setPriceOffsetType ( $ event -> getPriceOffsetType ( ) ) -> setDisplayInitialPrice ( $ event -> getDisplayInitialPrice ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setSaleLabel ( $ event -> getSaleLabel ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setDescription ( $ event -> getDescription ( ) ) -> setChapo ( $ event -> getChapo ( ) ) -> setPostscriptum ( $ event -> getPostscriptum ( ) ) -> save ( $ con ) ; $ event -> setSale ( $ sale ) ; // Update price offsets SaleOffsetCurrencyQuery :: create ( ) -> filterBySaleId ( $ sale -> getId ( ) ) -> delete ( $ con ) ; foreach ( $ event -> getPriceOffsets ( ) as $ currencyId => $ priceOffset ) { $ saleOffset = new SaleOffsetCurrency ( ) ; $ saleOffset -> setCurrencyId ( $ currencyId ) -> setSaleId ( $ sale -> getId ( ) ) -> setPriceOffsetValue ( $ priceOffset ) -> save ( $ con ) ; } // Update products SaleProductQuery :: create ( ) -> filterBySaleId ( $ sale -> getId ( ) ) -> delete ( $ con ) ; $ productAttributesArray = $ event -> getProductAttributes ( ) ; foreach ( $ event -> getProducts ( ) as $ productId ) { if ( isset ( $ productAttributesArray [ $ productId ] ) ) { foreach ( $ productAttributesArray [ $ productId ] as $ attributeId ) { $ saleProduct = new SaleProduct ( ) ; $ saleProduct -> setSaleId ( $ sale -> getId ( ) ) -> setProductId ( $ productId ) -> setAttributeAvId ( $ attributeId ) -> save ( $ con ) ; } } else { $ saleProduct = new SaleProduct ( ) ; $ saleProduct -> setSaleId ( $ sale -> getId ( ) ) -> setProductId ( $ productId ) -> setAttributeAvId ( null ) -> save ( $ con ) ; } } // Update related products sale status if the Sale is active. This is not required if the sale is // not active, as we de-activated promotion for this sale at the beginning ofd this method if ( $ sale -> getActive ( ) ) { $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; } $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } }
Process update sale

@param  SaleUpdateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher
@throws PropelException
Process update sale