public function createOrUpdate(
        $code,
        $title,
        array $effects,
        $type,
        $isRemovingPostage,
        $shortDescription,
        $description,
        $isEnabled,
        $expirationDate,
        $isAvailableOnSpecialOffers,
        $isCumulative,
        $maxUsage,
        $defaultSerializedRule,
        $locale,
        $freeShippingForCountries,
        $freeShippingForMethods,
        $perCustomerUsageCount,
        $startDate = null
    ) {
        $con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME);

        $con->beginTransaction();

        try {
            $this
                ->setCode($code)
                ->setType($type)
                ->setEffects($effects)
                ->setIsRemovingPostage($isRemovingPostage)
                ->setIsEnabled($isEnabled)
                ->setStartDate($startDate)
                ->setExpirationDate($expirationDate)
                ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
                ->setIsCumulative($isCumulative)
                ->setMaxUsage($maxUsage)
                ->setPerCustomerUsageCount($perCustomerUsageCount)
                ->setLocale($locale)
                ->setTitle($title)
                ->setShortDescription($shortDescription)
                ->setDescription($description)
            ;

            // If no rule given, set default rule
            if (null === $this->getSerializedConditions()) {
                $this->setSerializedConditions($defaultSerializedRule);
            }

            $this->save();

            // Update countries and modules relation for free shipping
            CouponCountryQuery::create()->filterByCouponId($this->id)->delete();
            CouponModuleQuery::create()->filterByCouponId($this->id)->delete();

            foreach ($freeShippingForCountries as $countryId) {
                if ($countryId <= 0) {
                    continue;
                }

                $couponCountry = new CouponCountry();

                $couponCountry
                    ->setCouponId($this->getId())
                    ->setCountryId($countryId)
                    ->save();
                ;
            }

            foreach ($freeShippingForMethods as $moduleId) {
                if ($moduleId <= 0) {
                    continue;
                }

                $couponModule = new CouponModule();

                $couponModule
                    ->setCouponId($this->getId())
                    ->setModuleId($moduleId)
                    ->save()
                ;
            }

            $con->commit();
        } catch (\Exception $ex) {
            $con->rollback();

            throw $ex;
        }
    }
public function createOrUpdate(
        $code,
        $title,
        array $effects,
        $type,
        $isRemovingPostage,
        $shortDescription,
        $description,
        $isEnabled,
        $expirationDate,
        $isAvailableOnSpecialOffers,
        $isCumulative,
        $maxUsage,
        $defaultSerializedRule,
        $locale,
        $freeShippingForCountries,
        $freeShippingForMethods,
        $perCustomerUsageCount,
        $startDate = null
    ) {
        $con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME);

        $con->beginTransaction();

        try {
            $this
                ->setCode($code)
                ->setType($type)
                ->setEffects($effects)
                ->setIsRemovingPostage($isRemovingPostage)
                ->setIsEnabled($isEnabled)
                ->setStartDate($startDate)
                ->setExpirationDate($expirationDate)
                ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
                ->setIsCumulative($isCumulative)
                ->setMaxUsage($maxUsage)
                ->setPerCustomerUsageCount($perCustomerUsageCount)
                ->setLocale($locale)
                ->setTitle($title)
                ->setShortDescription($shortDescription)
                ->setDescription($description)
            ;

            // If no rule given, set default rule
            if (null === $this->getSerializedConditions()) {
                $this->setSerializedConditions($defaultSerializedRule);
            }

            $this->save();

            // Update countries and modules relation for free shipping
            CouponCountryQuery::create()->filterByCouponId($this->id)->delete();
            CouponModuleQuery::create()->filterByCouponId($this->id)->delete();

            foreach ($freeShippingForCountries as $countryId) {
                if ($countryId <= 0) {
                    continue;
                }

                $couponCountry = new CouponCountry();

                $couponCountry
                    ->setCouponId($this->getId())
                    ->setCountryId($countryId)
                    ->save();
                ;
            }

            foreach ($freeShippingForMethods as $moduleId) {
                if ($moduleId <= 0) {
                    continue;
                }

                $couponModule = new CouponModule();

                $couponModule
                    ->setCouponId($this->getId())
                    ->setModuleId($moduleId)
                    ->save()
                ;
            }

            $con->commit();
        } catch (\Exception $ex) {
            $con->rollback();

            throw $ex;
        }
    }
public function createOrUpdate ( $ code , $ title , array $ effects , $ type , $ isRemovingPostage , $ shortDescription , $ description , $ isEnabled , $ expirationDate , $ isAvailableOnSpecialOffers , $ isCumulative , $ maxUsage , $ defaultSerializedRule , $ locale , $ freeShippingForCountries , $ freeShippingForMethods , $ perCustomerUsageCount , $ startDate = null ) { $ con = Propel :: getWriteConnection ( CouponTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ this -> setCode ( $ code ) -> setType ( $ type ) -> setEffects ( $ effects ) -> setIsRemovingPostage ( $ isRemovingPostage ) -> setIsEnabled ( $ isEnabled ) -> setStartDate ( $ startDate ) -> setExpirationDate ( $ expirationDate ) -> setIsAvailableOnSpecialOffers ( $ isAvailableOnSpecialOffers ) -> setIsCumulative ( $ isCumulative ) -> setMaxUsage ( $ maxUsage ) -> setPerCustomerUsageCount ( $ perCustomerUsageCount ) -> setLocale ( $ locale ) -> setTitle ( $ title ) -> setShortDescription ( $ shortDescription ) -> setDescription ( $ description ) ; // If no rule given, set default rule if ( null === $ this -> getSerializedConditions ( ) ) { $ this -> setSerializedConditions ( $ defaultSerializedRule ) ; } $ this -> save ( ) ; // Update countries and modules relation for free shipping CouponCountryQuery :: create ( ) -> filterByCouponId ( $ this -> id ) -> delete ( ) ; CouponModuleQuery :: create ( ) -> filterByCouponId ( $ this -> id ) -> delete ( ) ; foreach ( $ freeShippingForCountries as $ countryId ) { if ( $ countryId <= 0 ) { continue ; } $ couponCountry = new CouponCountry ( ) ; $ couponCountry -> setCouponId ( $ this -> getId ( ) ) -> setCountryId ( $ countryId ) -> save ( ) ; ; } foreach ( $ freeShippingForMethods as $ moduleId ) { if ( $ moduleId <= 0 ) { continue ; } $ couponModule = new CouponModule ( ) ; $ couponModule -> setCouponId ( $ this -> getId ( ) ) -> setModuleId ( $ moduleId ) -> save ( ) ; } $ con -> commit ( ) ; } catch ( \ Exception $ ex ) { $ con -> rollback ( ) ; throw $ ex ; } }
Create or Update this Coupon

@param string $code Coupon Code
@param string $title Coupon title
@param array $effects Ready to be serialized in JSON effect params
@param string $type Coupon type
@param bool $isRemovingPostage Is removing Postage
@param string $shortDescription Coupon short description
@param string $description Coupon description
@param boolean $isEnabled Enable/Disable
@param \DateTime $expirationDate Coupon expiration date
@param boolean $isAvailableOnSpecialOffers Is available on special offers
@param boolean $isCumulative Is cumulative
@param int $maxUsage Coupon quantity
@param string $defaultSerializedRule Serialized default rule added if none found
@param string $locale Coupon Language code ISO (ex: fr_FR)
@param array $freeShippingForCountries ID of Countries to which shipping is free
@param array $freeShippingForMethods ID of Shipping modules for which shipping is free
@param bool $perCustomerUsageCount True if usage coiunt is per customer
@param $startDate

@throws \Exception
Create or Update this Coupon