public function updateProductsSaleStatus(ProductSaleStatusUpdateEvent $event)
    {
        $taxCalculator = new Calculator();

        $sale = $event->getSale();

        // Get all selected product sale elements for this sale
        if (null !== $saleProducts = SaleProductQuery::create()->filterBySale($sale)->orderByProductId()) {
            $saleOffsetByCurrency = $sale->getPriceOffsets();

            $offsetType = $sale->getPriceOffsetType();

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

            $con->beginTransaction();

            try {
                /** @var SaleProduct $saleProduct */
                foreach ($saleProducts as $saleProduct) {
                    // Reset all sale status on product's PSE
                    ProductSaleElementsQuery::create()
                        ->filterByProductId($saleProduct->getProductId())
                        ->update([ 'Promo' => false], $con)
                    ;

                    $taxCalculator->load(
                        $saleProduct->getProduct($con),
                        CountryModel::getShopLocation()
                    );

                    $attributeAvId = $saleProduct->getAttributeAvId();

                    $pseRequest = ProductSaleElementsQuery::create()
                        ->filterByProductId($saleProduct->getProductId())
                    ;

                    // If no attribute AV id is defined, consider ALL product combinations
                    if (! \is_null($attributeAvId)) {
                        // Find PSE attached to combination containing this attribute av :
                        // SELECT * from product_sale_elements pse
                        // left join attribute_combination ac on ac.product_sale_elements_id = pse.id
                        // where pse.product_id=363
                        // and ac.attribute_av_id = 7
                        // group by pse.id

                        $pseRequest
                            ->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)
                                ->filterByAttributeAvId($attributeAvId)
                            ->endUse()
                        ;
                    }

                    $pseList = $pseRequest->find();

                    if (null !== $pseList) {
                        $this->updateProductSaleElementsPrices(
                            $pseList,
                            $sale->getActive(),
                            $offsetType,
                            $taxCalculator,
                            $saleOffsetByCurrency,
                            $con
                        );
                    }
                }

                $con->commit();
            } catch (PropelException $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
public function updateProductsSaleStatus(ProductSaleStatusUpdateEvent $event)
    {
        $taxCalculator = new Calculator();

        $sale = $event->getSale();

        // Get all selected product sale elements for this sale
        if (null !== $saleProducts = SaleProductQuery::create()->filterBySale($sale)->orderByProductId()) {
            $saleOffsetByCurrency = $sale->getPriceOffsets();

            $offsetType = $sale->getPriceOffsetType();

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

            $con->beginTransaction();

            try {
                /** @var SaleProduct $saleProduct */
                foreach ($saleProducts as $saleProduct) {
                    // Reset all sale status on product's PSE
                    ProductSaleElementsQuery::create()
                        ->filterByProductId($saleProduct->getProductId())
                        ->update([ 'Promo' => false], $con)
                    ;

                    $taxCalculator->load(
                        $saleProduct->getProduct($con),
                        CountryModel::getShopLocation()
                    );

                    $attributeAvId = $saleProduct->getAttributeAvId();

                    $pseRequest = ProductSaleElementsQuery::create()
                        ->filterByProductId($saleProduct->getProductId())
                    ;

                    // If no attribute AV id is defined, consider ALL product combinations
                    if (! \is_null($attributeAvId)) {
                        // Find PSE attached to combination containing this attribute av :
                        // SELECT * from product_sale_elements pse
                        // left join attribute_combination ac on ac.product_sale_elements_id = pse.id
                        // where pse.product_id=363
                        // and ac.attribute_av_id = 7
                        // group by pse.id

                        $pseRequest
                            ->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)
                                ->filterByAttributeAvId($attributeAvId)
                            ->endUse()
                        ;
                    }

                    $pseList = $pseRequest->find();

                    if (null !== $pseList) {
                        $this->updateProductSaleElementsPrices(
                            $pseList,
                            $sale->getActive(),
                            $offsetType,
                            $taxCalculator,
                            $saleOffsetByCurrency,
                            $con
                        );
                    }
                }

                $con->commit();
            } catch (PropelException $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
public function updateProductsSaleStatus ( ProductSaleStatusUpdateEvent $ event ) { $ taxCalculator = new Calculator ( ) ; $ sale = $ event -> getSale ( ) ; // Get all selected product sale elements for this sale if ( null !== $ saleProducts = SaleProductQuery :: create ( ) -> filterBySale ( $ sale ) -> orderByProductId ( ) ) { $ saleOffsetByCurrency = $ sale -> getPriceOffsets ( ) ; $ offsetType = $ sale -> getPriceOffsetType ( ) ; $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { /** @var SaleProduct $saleProduct */ foreach ( $ saleProducts as $ saleProduct ) { // Reset all sale status on product's PSE ProductSaleElementsQuery :: create ( ) -> filterByProductId ( $ saleProduct -> getProductId ( ) ) -> update ( [ 'Promo' => false ] , $ con ) ; $ taxCalculator -> load ( $ saleProduct -> getProduct ( $ con ) , CountryModel :: getShopLocation ( ) ) ; $ attributeAvId = $ saleProduct -> getAttributeAvId ( ) ; $ pseRequest = ProductSaleElementsQuery :: create ( ) -> filterByProductId ( $ saleProduct -> getProductId ( ) ) ; // If no attribute AV id is defined, consider ALL product combinations if ( ! \ is_null ( $ attributeAvId ) ) { // Find PSE attached to combination containing this attribute av : // SELECT * from product_sale_elements pse // left join attribute_combination ac on ac.product_sale_elements_id = pse.id // where pse.product_id=363 // and ac.attribute_av_id = 7 // group by pse.id $ pseRequest -> useAttributeCombinationQuery ( null , Criteria :: LEFT_JOIN ) -> filterByAttributeAvId ( $ attributeAvId ) -> endUse ( ) ; } $ pseList = $ pseRequest -> find ( ) ; if ( null !== $ pseList ) { $ this -> updateProductSaleElementsPrices ( $ pseList , $ sale -> getActive ( ) , $ offsetType , $ taxCalculator , $ saleOffsetByCurrency , $ con ) ; } } $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } }
Update the promo status of the sale's selected products and combinations

@param  ProductSaleStatusUpdateEvent              $event
@throws \RuntimeException
@throws \Exception
@throws \Propel\Runtime\Exception\PropelException
Update the promo status of the sale s selected products and combinations