. */ /* */ /**********************************************************************************/ namespace Thelia\Model; use Propel\Runtime\Propel; use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Coupon\CouponRuleCollection; use Thelia\Model\Base\Coupon as BaseCoupon; use Thelia\Model\Map\CouponTableMap; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * * Used to provide an effect (mostly a discount) * at the end of the Customer checkout tunnel * It will be usable for a Customer only if it matches the Coupon criteria (Rules) * * @package Coupon * @author Guillaume MOREL * */ class Coupon extends BaseCoupon { use \Thelia\Model\Tools\ModelEventDispatcherTrait; /** * Constructor * * @param string $code Coupon Code * @param string $title Coupon title * @param float $amount Amount removed from the Total Checkout * @param string $effect Coupon effect * @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 boolean $isRemovingPostage Is removing Postage * @param int $maxUsage Coupon quantity * @param CouponRuleCollection $rules CouponRuleInterface to add * @param string $locale Coupon Language code ISO (ex: fr_FR) */ function createOrUpdate($code, $title, $amount, $effect, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $rules, $locale = null) { $this->setCode($code) ->setTitle($title) ->setShortDescription($shortDescription) ->setDescription($description) ->setType($effect) ->setAmount($amount) ->setType($amount) ->setIsEnabled($isEnabled) ->setExpirationDate($expirationDate) ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) ->setIsCumulative($isCumulative) ->setMaxUsage($maxUsage) ->setRules($rules); // Set object language (i18n) if (!is_null($locale)) { $this->setLocale($locale); } $con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME); $con->beginTransaction(); try { $this->save($con); $con->commit(); } catch(\Exception $e) { $con->rollback(); throw $e; } } // /** // * Set the value of [serialized_rules] column. // * Convert a CouponRuleCollection into a serialized array of SerializableRule // * // * @param CouponRuleCollection $rules A set of Rules // * // * @return \Thelia\Model\Coupon The current object (for fluent API support) // */ // public function setRules(CouponRuleCollection $rules) // { // $serializedRules = null; // if ($rules !== null) { // /** @var $rule CouponRuleInterface */ // foreach ($rules->getRules() as $rule) { // $serializedRules[] = $rule->getSerializableRule(); // } // // $serializedRules = (string) base64_encode(serialize($serializedRules)); // } // // if ($this->serialized_rules !== $serializedRules) { // $this->serialized_rules = $serializedRules; // $this->modifiedColumns[] = CouponTableMap::SERIALIZED_RULES; // } // // return $this; // } }