protected function updateProductSaleElementsPrices($pseList, $promoStatus, $offsetType, Calculator $taxCalculator, $saleOffsetByCurrency, ConnectionInterface $con)
    {
        /** @var ProductSaleElements $pse */
        foreach ($pseList as $pse) {
            if ($pse->getPromo()!= $promoStatus) {
                $pse
                    ->setPromo($promoStatus)
                    ->save($con)
                ;
            }

            /** @var SaleOffsetCurrency $offsetByCurrency */
            foreach ($saleOffsetByCurrency as $currencyId => $offset) {
                $productPrice = ProductPriceQuery::create()
                    ->filterByProductSaleElementsId($pse->getId())
                    ->filterByCurrencyId($currencyId)
                    ->findOne($con);

                if (null !== $productPrice) {
                    // Get the taxed price
                    $priceWithTax = $taxCalculator->getTaxedPrice($productPrice->getPrice());

                    // Remove the price offset to get the taxed promo price
                    switch ($offsetType) {
                        case SaleModel::OFFSET_TYPE_AMOUNT:
                            $promoPrice = max(0, $priceWithTax - $offset);
                            break;

                        case SaleModel::OFFSET_TYPE_PERCENTAGE:
                            $promoPrice = $priceWithTax * (1 - $offset / 100);
                            break;

                        default:
                            $promoPrice = $priceWithTax;
                    }

                    // and then get the untaxed promo price.
                    $promoPrice = $taxCalculator->getUntaxedPrice($promoPrice);

                    $productPrice
                        ->setPromoPrice($promoPrice)
                        ->save($con)
                    ;
                }
            }
        }
    }
protected function updateProductSaleElementsPrices($pseList, $promoStatus, $offsetType, Calculator $taxCalculator, $saleOffsetByCurrency, ConnectionInterface $con)
    {
        /** @var ProductSaleElements $pse */
        foreach ($pseList as $pse) {
            if ($pse->getPromo()!= $promoStatus) {
                $pse
                    ->setPromo($promoStatus)
                    ->save($con)
                ;
            }

            /** @var SaleOffsetCurrency $offsetByCurrency */
            foreach ($saleOffsetByCurrency as $currencyId => $offset) {
                $productPrice = ProductPriceQuery::create()
                    ->filterByProductSaleElementsId($pse->getId())
                    ->filterByCurrencyId($currencyId)
                    ->findOne($con);

                if (null !== $productPrice) {
                    // Get the taxed price
                    $priceWithTax = $taxCalculator->getTaxedPrice($productPrice->getPrice());

                    // Remove the price offset to get the taxed promo price
                    switch ($offsetType) {
                        case SaleModel::OFFSET_TYPE_AMOUNT:
                            $promoPrice = max(0, $priceWithTax - $offset);
                            break;

                        case SaleModel::OFFSET_TYPE_PERCENTAGE:
                            $promoPrice = $priceWithTax * (1 - $offset / 100);
                            break;

                        default:
                            $promoPrice = $priceWithTax;
                    }

                    // and then get the untaxed promo price.
                    $promoPrice = $taxCalculator->getUntaxedPrice($promoPrice);

                    $productPrice
                        ->setPromoPrice($promoPrice)
                        ->save($con)
                    ;
                }
            }
        }
    }
protected function updateProductSaleElementsPrices ( $ pseList , $ promoStatus , $ offsetType , Calculator $ taxCalculator , $ saleOffsetByCurrency , ConnectionInterface $ con ) { /** @var ProductSaleElements $pse */ foreach ( $ pseList as $ pse ) { if ( $ pse -> getPromo ( ) != $ promoStatus ) { $ pse -> setPromo ( $ promoStatus ) -> save ( $ con ) ; } /** @var SaleOffsetCurrency $offsetByCurrency */ foreach ( $ saleOffsetByCurrency as $ currencyId => $ offset ) { $ productPrice = ProductPriceQuery :: create ( ) -> filterByProductSaleElementsId ( $ pse -> getId ( ) ) -> filterByCurrencyId ( $ currencyId ) -> findOne ( $ con ) ; if ( null !== $ productPrice ) { // Get the taxed price $ priceWithTax = $ taxCalculator -> getTaxedPrice ( $ productPrice -> getPrice ( ) ) ; // Remove the price offset to get the taxed promo price switch ( $ offsetType ) { case SaleModel :: OFFSET_TYPE_AMOUNT : $ promoPrice = max ( 0 , $ priceWithTax - $ offset ) ; break ; case SaleModel :: OFFSET_TYPE_PERCENTAGE : $ promoPrice = $ priceWithTax * ( 1 - $ offset / 100 ) ; break ; default : $ promoPrice = $ priceWithTax ; } // and then get the untaxed promo price. $ promoPrice = $ taxCalculator -> getUntaxedPrice ( $ promoPrice ) ; $ productPrice -> setPromoPrice ( $ promoPrice ) -> save ( $ con ) ; } } } }
Update PSE for a given product

@param array               $pseList              an array of priduct sale elements
@param bool                $promoStatus          true if the PSEs are on sale, false otherwise
@param int                 $offsetType           the offset type, see SaleModel::OFFSET_* constants
@param Calculator          $taxCalculator        the tax calculator
@param array               $saleOffsetByCurrency an array of price offset for each currency (currency ID => offset_amount)
@param ConnectionInterface $con
@throws PropelException
Update PSE for a given product