Refactor : Coupon effect inputs are now more customisable

Adding effect to be stored as serialised in JSON
This commit is contained in:
gmorel
2013-12-29 01:23:50 +01:00
parent e18298bbba
commit f8ac32a4a0
23 changed files with 447 additions and 265 deletions

View File

@@ -168,7 +168,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$coupon->createOrUpdate(
$event->getCode(),
$event->getTitle(),
$event->getAmount(),
$event->getEffects(),
$event->getServiceId(),
$event->isRemovingPostage(),
$event->getShortDescription(),

View File

@@ -35,6 +35,7 @@ use Thelia\Coupon\CouponFactory;
use Thelia\Coupon\CouponManager;
use Thelia\Condition\ConditionCollection;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Coupon\Type\RemoveXPercent;
use Thelia\Form\CouponCreationForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
@@ -348,19 +349,7 @@ class CouponController extends BaseAdminController
}
$couponEvent = new CouponCreateOrUpdateEvent(
$coupon->getCode(),
$coupon->getTitle(),
$coupon->getAmount(),
$coupon->getType(),
$coupon->getShortDescription(),
$coupon->getDescription(),
$coupon->getIsEnabled(),
$coupon->getExpirationDate(),
$coupon->getIsAvailableOnSpecialOffers(),
$coupon->getIsCumulative(),
$coupon->getIsRemovingPostage(),
$coupon->getMaxUsage(),
$coupon->getLocale()
$coupon->getCode(), $coupon->getType(), $coupon->getTitle(), array('quantity' => $coupon->getAmount()), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), $coupon->getExpirationDate(), $coupon->getIsAvailableOnSpecialOffers(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getMaxUsage(), $coupon->getLocale()
);
$couponEvent->setCouponModel($coupon);
$couponEvent->setConditions($conditions);
@@ -472,15 +461,20 @@ class CouponController extends BaseAdminController
// Check the form against conditions violations
$form = $this->validateForm($creationForm, 'POST');
// Get the form field values
$data = $form->getData();
$effects = array('amount' => $data['amount']);
$effects = $this->addPercentageLogic($effects);
$couponEvent = new CouponCreateOrUpdateEvent(
$data['code'], $data['title'], $data['amount'], $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale']
$data['code'], $data['type'], $data['title'], $effects, $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale']
);
$couponQuery = new CouponQuery();
$coupon = $couponQuery->findOneByCode($data['code']);
$couponEvent->setCouponModel($coupon);
if (isset($coupon)) {
$couponEvent->setCouponModel($coupon);
}
// Dispatch Event to the Action
$this->dispatch(
@@ -614,4 +608,28 @@ class CouponController extends BaseAdminController
return $response;
}
/**
* Add percentage logic if found in the Coupon post data
*
* @param array $effects Effect to populate
*
* @return array Populated effect with percentage
*/
protected function addPercentageLogic(array $effects)
{
/** @var Request $request */
$request = $this->container->get('request');
$postData = $request->request;
// Validate quantity input
if ($postData->has(RemoveXPercent::INPUT_EXTENDED__NAME)) {
$extentedPostData = $postData->get(RemoveXPercent::INPUT_EXTENDED__NAME);
if (isset($extentedPostData[RemoveXPercent::INPUT_PERCENTAGE_NAME])) {
$percentage = $extentedPostData[RemoveXPercent::INPUT_PERCENTAGE_NAME];
$effects[RemoveXPercent::INPUT_PERCENTAGE_NAME] = floatval($percentage);
}
}
return $effects;
}
}

View File

@@ -25,6 +25,7 @@ namespace Thelia\Core\Event\Coupon;
use Thelia\Core\Event\ActionEvent;
use Thelia\Condition\ConditionCollection;
use Thelia\Model\Coupon;
use Thelia\Model\Exception\InvalidArgumentException;
/**
* Created by JetBrains PhpStorm.
@@ -69,6 +70,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent
/** @var float Amount that will be removed from the Checkout (Coupon Effect) */
protected $amount = 0;
/** @var array Effects ready to be serialized */
protected $effects = array();
/** @var int Max time a Coupon can be used (-1 = unlimited) */
protected $maxUsage = -1;
@@ -88,9 +92,11 @@ class CouponCreateOrUpdateEvent extends ActionEvent
* Constructor
*
* @param string $code Coupon Code
* @param string $title Coupon title
* @param float $amount Amount removed from the Total Checkout
* @param string $serviceId Coupon Service id
* @param string $title Coupon title
* @param array $effects Coupon effects ready to be serialized
* 'amount' key is mandatory and reflects
* the amount deduced from the cart
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param bool $isEnabled Enable/Disable
@@ -102,10 +108,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent
* @param string $locale Coupon Language code ISO (ex: fr_FR)
*/
public function __construct(
$code, $title, $amount, $serviceId, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
$code, $serviceId, $title, array $effects, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
)
{
$this->amount = $amount;
$this->code = $code;
$this->description = $description;
$this->expirationDate = $expirationDate;
@@ -118,6 +123,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
$this->title = $title;
$this->serviceId = $serviceId;
$this->locale = $locale;
$this->setEffects($effects);
}
/**
@@ -189,7 +195,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
*/
public function getAmount()
{
return $this->amount;
return $this->effects['amount'];
}
/**
@@ -253,6 +259,71 @@ class CouponCreateOrUpdateEvent extends ActionEvent
return $this->locale;
}
/**
* Set effects ready to be serialized
*
* @param array $effects Effect ready to be serialized
* Needs at least the key 'amount'
* with the amount removed from the cart
* @throws \Thelia\Model\Exception\InvalidArgumentException
*/
public function setEffects(array $effects)
{
if (null === $effects['amount']) {
throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array');
}
$this->amount = $effects['amount'];
$this->effects = $effects;
}
/**
* Get effects ready to be serialized
*
* @return array
*/
public function getEffects()
{
return $this->effects;
}
/**
* Get if the Coupon will be available on special offers or not
*
* @return boolean
*/
public function getIsAvailableOnSpecialOffers()
{
return $this->isAvailableOnSpecialOffers;
}
/**
* Get if the Coupon effect cancel other Coupon effects
*
* @return boolean
*/
public function getIsCumulative()
{
return $this->isCumulative;
}
/**
* Get if Coupon is enabled or not
*
* @return boolean
*/
public function getIsEnabled()
{
return $this->isEnabled;
}
/**
* @return boolean
*/
public function getIsRemovingPostage()
{
return $this->isRemovingPostage;
}
/**
* Set Coupon Model
*

View File

@@ -111,7 +111,7 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
$coupon->getTitle(),
$coupon->getShortDescription(),
$coupon->getDescription(),
$coupon->getAmount(),
$coupon->getEffects(),
$coupon->getIsCumulative(),
$coupon->getIsRemovingPostage(),
$coupon->getIsAvailableOnSpecialOffers(),

View File

@@ -116,7 +116,7 @@ class CouponFactory
$model->getTitle(),
$model->getShortDescription(),
$model->getDescription(),
$model->getAmount(),
$model->getEffects(),
$isCumulative,
$isRemovingPostage,
$model->getIsAvailableOnSpecialOffers(),

View File

@@ -44,6 +44,10 @@ use Thelia\Exception\InvalidConditionException;
*/
abstract class CouponAbstract implements CouponInterface
{
const INPUT_EXTENDED__NAME = 'thelia_coupon_creation_extended';
const INPUT_AMOUNT_NAME = 'amount';
/** @var FacadeInterface Provide necessary value from Thelia */
protected $facade = null;
@@ -66,6 +70,9 @@ abstract class CouponAbstract implements CouponInterface
/** @var float Amount that will be removed from the Checkout (Coupon Effect) */
protected $amount = 0;
/** @var array Get the Coupon effects params */
protected $effects = array('amount' => 0);
/** @var string Coupon code (ex: XMAS) */
protected $code = null;
@@ -127,6 +134,60 @@ abstract class CouponAbstract implements CouponInterface
return $this;
}
/**
* Set Coupon
*
* @param FacadeInterface $facade Provides necessary value from Thelia
* @param string $code Coupon code (ex: XMAS)
* @param string $title Coupon title (ex: Coupon for XMAS)
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param array $effects Coupon effects params
* @param bool $isCumulative If Coupon is cumulative
* @param bool $isRemovingPostage If Coupon is removing postage
* @param bool $isAvailableOnSpecialOffers If available on Product already
* on special offer price
* @param bool $isEnabled False if Coupon is disabled by admin
* @param int $maxUsage How many usage left
* @param \Datetime $expirationDate When the Code is expiring
*
* @return $this
*/
public function set(
FacadeInterface $facade,
$code,
$title,
$shortDescription,
$description,
array $effects,
$isCumulative,
$isRemovingPostage,
$isAvailableOnSpecialOffers,
$isEnabled,
$maxUsage,
\DateTime $expirationDate
)
{
$this->code = $code;
$this->title = $title;
$this->shortDescription = $shortDescription;
$this->description = $description;
$this->isCumulative = $isCumulative;
$this->isRemovingPostage = $isRemovingPostage;
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
$this->isEnabled = $isEnabled;
$this->maxUsage = $maxUsage;
$this->expirationDate = $expirationDate;
$this->facade = $facade;
$this->effects = $effects;
$this->amount = $effects[self::INPUT_AMOUNT_NAME];
return $this;
}
/**
* Return Coupon code (ex: XMAS)
*
@@ -319,9 +380,9 @@ abstract class CouponAbstract implements CouponInterface
$value = $this->amount;
$html = '
<div class="form-group input-amount ">
<label for="amount" class="control-label">' . $label . '</label>
<input id="amount" type="text" class="form-control" name="thelia_coupon_creation[amount]" value="' . $value . '" placeholder="14.50">
<div class="form-group input-' . self::INPUT_AMOUNT_NAME . ' ">
<label for="' . self::INPUT_AMOUNT_NAME . '" class="control-label">' . $label . '</label>
<input id="' . self::INPUT_AMOUNT_NAME . '" type="text" class="form-control" name="thelia_coupon_creation[' . self::INPUT_AMOUNT_NAME . ']" value="' . $value . '" placeholder="14.50">
</div>
';

View File

@@ -75,7 +75,7 @@ interface CouponInterface
* @param string $title Coupon title (ex: Coupon for XMAS)
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param float $effect Coupon amount/percentage to deduce
* @param array $effects Coupon effects params
* @param bool $isCumulative If Coupon is cumulative
* @param bool $isRemovingPostage If Coupon is removing postage
* @param bool $isAvailableOnSpecialOffers If available on Product already
@@ -90,7 +90,7 @@ interface CouponInterface
$title,
$shortDescription,
$description,
$effect,
array $effects,
$isCumulative,
$isRemovingPostage,
$isAvailableOnSpecialOffers,

View File

@@ -42,55 +42,6 @@ class RemoveXAmount extends CouponAbstract
/** @var string Service Id */
protected $serviceId = 'thelia.coupon.type.remove_x_amount';
/**
* Set Coupon
*
* @param FacadeInterface $facade Provides necessary value from Thelia
* @param string $code Coupon code (ex: XMAS)
* @param string $title Coupon title (ex: Coupon for XMAS)
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param float $amount Coupon amount to deduce
* @param bool $isCumulative If Coupon is cumulative
* @param bool $isRemovingPostage If Coupon is removing postage
* @param bool $isAvailableOnSpecialOffers If available on Product already
* on special offer price
* @param bool $isEnabled False if Coupon is disabled by admin
* @param int $maxUsage How many usage left
* @param \Datetime $expirationDate When the Code is expiring
*/
public function set(
FacadeInterface $facade,
$code,
$title,
$shortDescription,
$description,
$amount,
$isCumulative,
$isRemovingPostage,
$isAvailableOnSpecialOffers,
$isEnabled,
$maxUsage,
\DateTime $expirationDate
)
{
$this->code = $code;
$this->title = $title;
$this->shortDescription = $shortDescription;
$this->description = $description;
$this->isCumulative = $isCumulative;
$this->isRemovingPostage = $isRemovingPostage;
$this->amount = $amount;
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
$this->isEnabled = $isEnabled;
$this->maxUsage = $maxUsage;
$this->expirationDate = $expirationDate;
$this->facade = $facade;
}
/**
* Get I18n name
*

View File

@@ -38,10 +38,13 @@ use Thelia\Exception\MissingFacadeException;
*/
class RemoveXPercent extends CouponAbstract
{
const INPUT_PERCENTAGE_NAME = 'percentage';
/** @var string Service Id */
protected $serviceId = 'thelia.coupon.type.remove_x_percent';
protected $percent = 0;
/** @var float Percentage removed from the Cart */
protected $percentage = 0;
/**
* Set Coupon
@@ -51,7 +54,7 @@ class RemoveXPercent extends CouponAbstract
* @param string $title Coupon title (ex: Coupon for XMAS)
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param float $percent Coupon percentage to deduce
* @param array $effects Coupon effects params
* @param bool $isCumulative If Coupon is cumulative
* @param bool $isRemovingPostage If Coupon is removing postage
* @param bool $isAvailableOnSpecialOffers If available on Product already
@@ -59,6 +62,8 @@ class RemoveXPercent extends CouponAbstract
* @param bool $isEnabled False if Coupon is disabled by admin
* @param int $maxUsage How many usage left
* @param \Datetime $expirationDate When the Code is expiring
*
* @return $this
*/
public function set(
FacadeInterface $facade,
@@ -66,29 +71,21 @@ class RemoveXPercent extends CouponAbstract
$title,
$shortDescription,
$description,
$percent,
array $effects,
$isCumulative,
$isRemovingPostage,
$isAvailableOnSpecialOffers,
$isEnabled,
$maxUsage,
\DateTime $expirationDate)
\DateTime $expirationDate
)
{
$this->code = $code;
$this->title = $title;
$this->shortDescription = $shortDescription;
$this->description = $description;
parent::set(
$facade, $code, $title, $shortDescription, $description, $effects, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate
);
$this->percentage = $effects[self::INPUT_PERCENTAGE_NAME];
$this->isCumulative = $isCumulative;
$this->isRemovingPostage = $isRemovingPostage;
$this->percent = $percent;
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
$this->isEnabled = $isEnabled;
$this->maxUsage = $maxUsage;
$this->expirationDate = $expirationDate;
$this->facade = $facade;
return $this;
}
/**
@@ -101,7 +98,7 @@ class RemoveXPercent extends CouponAbstract
*/
public function exec()
{
if ($this->percent >= 100) {
if ($this->percentage >= 100) {
throw new \InvalidArgumentException(
'Percentage must be inferior to 100'
);
@@ -109,7 +106,7 @@ class RemoveXPercent extends CouponAbstract
$basePrice = $this->facade->getCartTotalPrice();
return $basePrice * (( $this->percent ) / 100);
return $basePrice * (( $this->percentage ) / 100);
}
@@ -155,4 +152,25 @@ class RemoveXPercent extends CouponAbstract
return $toolTip;
}
/**
* Draw the input displayed in the BackOffice
* allowing Admin to set its Coupon effect
*
* @return string HTML string
*/
public function drawBackOfficeInputs()
{
$labelPercentage = $this->getInputName();
$html = '
<input type="hidden" name="thelia_coupon_creation[' . self::INPUT_AMOUNT_NAME . ']" value="0"/>
<div class="form-group input-' . self::INPUT_PERCENTAGE_NAME . '">
<label for="' . self::INPUT_PERCENTAGE_NAME . '" class="control-label">' . $labelPercentage . '</label>
<input id="' . self::INPUT_PERCENTAGE_NAME . '" class="form-control" name="' . self::INPUT_EXTENDED__NAME . '[' . self::INPUT_PERCENTAGE_NAME . ']' . '" type="text" value="' . $this->percentage . '"/>
</div>
';
return $html;
}
}

View File

@@ -79,10 +79,10 @@ abstract class Coupon implements ActiveRecordInterface
protected $type;
/**
* The value for the amount field.
* @var double
* The value for the serialized_effects field.
* @var string
*/
protected $amount;
protected $serialized_effects;
/**
* The value for the is_enabled field.
@@ -510,14 +510,14 @@ abstract class Coupon implements ActiveRecordInterface
}
/**
* Get the [amount] column value.
* Get the [serialized_effects] column value.
*
* @return double
* @return string
*/
public function getAmount()
public function getSerializedEffects()
{
return $this->amount;
return $this->serialized_effects;
}
/**
@@ -732,25 +732,25 @@ abstract class Coupon implements ActiveRecordInterface
} // setType()
/**
* Set the value of [amount] column.
* Set the value of [serialized_effects] column.
*
* @param double $v new value
* @param string $v new value
* @return \Thelia\Model\Coupon The current object (for fluent API support)
*/
public function setAmount($v)
public function setSerializedEffects($v)
{
if ($v !== null) {
$v = (double) $v;
$v = (string) $v;
}
if ($this->amount !== $v) {
$this->amount = $v;
$this->modifiedColumns[] = CouponTableMap::AMOUNT;
if ($this->serialized_effects !== $v) {
$this->serialized_effects = $v;
$this->modifiedColumns[] = CouponTableMap::SERIALIZED_EFFECTS;
}
return $this;
} // setAmount()
} // setSerializedEffects()
/**
* Sets the value of the [is_enabled] column.
@@ -1073,8 +1073,8 @@ abstract class Coupon implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CouponTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)];
$this->type = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)];
$this->amount = (null !== $col) ? (double) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponTableMap::translateFieldName('SerializedEffects', TableMap::TYPE_PHPNAME, $indexType)];
$this->serialized_effects = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)];
$this->is_enabled = (null !== $col) ? (boolean) $col : null;
@@ -1401,8 +1401,8 @@ abstract class Coupon implements ActiveRecordInterface
if ($this->isColumnModified(CouponTableMap::TYPE)) {
$modifiedColumns[':p' . $index++] = 'TYPE';
}
if ($this->isColumnModified(CouponTableMap::AMOUNT)) {
$modifiedColumns[':p' . $index++] = 'AMOUNT';
if ($this->isColumnModified(CouponTableMap::SERIALIZED_EFFECTS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS';
}
if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) {
$modifiedColumns[':p' . $index++] = 'IS_ENABLED';
@@ -1457,8 +1457,8 @@ abstract class Coupon implements ActiveRecordInterface
case 'TYPE':
$stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
break;
case 'AMOUNT':
$stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR);
case 'SERIALIZED_EFFECTS':
$stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR);
break;
case 'IS_ENABLED':
$stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT);
@@ -1565,7 +1565,7 @@ abstract class Coupon implements ActiveRecordInterface
return $this->getType();
break;
case 3:
return $this->getAmount();
return $this->getSerializedEffects();
break;
case 4:
return $this->getIsEnabled();
@@ -1632,7 +1632,7 @@ abstract class Coupon implements ActiveRecordInterface
$keys[0] => $this->getId(),
$keys[1] => $this->getCode(),
$keys[2] => $this->getType(),
$keys[3] => $this->getAmount(),
$keys[3] => $this->getSerializedEffects(),
$keys[4] => $this->getIsEnabled(),
$keys[5] => $this->getExpirationDate(),
$keys[6] => $this->getMaxUsage(),
@@ -1701,7 +1701,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->setType($value);
break;
case 3:
$this->setAmount($value);
$this->setSerializedEffects($value);
break;
case 4:
$this->setIsEnabled($value);
@@ -1763,7 +1763,7 @@ abstract class Coupon implements ActiveRecordInterface
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]);
if (array_key_exists($keys[3], $arr)) $this->setSerializedEffects($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]);
@@ -1789,7 +1789,7 @@ abstract class Coupon implements ActiveRecordInterface
if ($this->isColumnModified(CouponTableMap::ID)) $criteria->add(CouponTableMap::ID, $this->id);
if ($this->isColumnModified(CouponTableMap::CODE)) $criteria->add(CouponTableMap::CODE, $this->code);
if ($this->isColumnModified(CouponTableMap::TYPE)) $criteria->add(CouponTableMap::TYPE, $this->type);
if ($this->isColumnModified(CouponTableMap::AMOUNT)) $criteria->add(CouponTableMap::AMOUNT, $this->amount);
if ($this->isColumnModified(CouponTableMap::SERIALIZED_EFFECTS)) $criteria->add(CouponTableMap::SERIALIZED_EFFECTS, $this->serialized_effects);
if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) $criteria->add(CouponTableMap::IS_ENABLED, $this->is_enabled);
if ($this->isColumnModified(CouponTableMap::EXPIRATION_DATE)) $criteria->add(CouponTableMap::EXPIRATION_DATE, $this->expiration_date);
if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) $criteria->add(CouponTableMap::MAX_USAGE, $this->max_usage);
@@ -1866,7 +1866,7 @@ abstract class Coupon implements ActiveRecordInterface
{
$copyObj->setCode($this->getCode());
$copyObj->setType($this->getType());
$copyObj->setAmount($this->getAmount());
$copyObj->setSerializedEffects($this->getSerializedEffects());
$copyObj->setIsEnabled($this->getIsEnabled());
$copyObj->setExpirationDate($this->getExpirationDate());
$copyObj->setMaxUsage($this->getMaxUsage());
@@ -2399,7 +2399,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->id = null;
$this->code = null;
$this->type = null;
$this->amount = null;
$this->serialized_effects = null;
$this->is_enabled = null;
$this->expiration_date = null;
$this->max_usage = null;
@@ -2703,7 +2703,7 @@ abstract class Coupon implements ActiveRecordInterface
$version->setId($this->getId());
$version->setCode($this->getCode());
$version->setType($this->getType());
$version->setAmount($this->getAmount());
$version->setSerializedEffects($this->getSerializedEffects());
$version->setIsEnabled($this->getIsEnabled());
$version->setExpirationDate($this->getExpirationDate());
$version->setMaxUsage($this->getMaxUsage());
@@ -2755,7 +2755,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->setId($version->getId());
$this->setCode($version->getCode());
$this->setType($version->getType());
$this->setAmount($version->getAmount());
$this->setSerializedEffects($version->getSerializedEffects());
$this->setIsEnabled($version->getIsEnabled());
$this->setExpirationDate($version->getExpirationDate());
$this->setMaxUsage($version->getMaxUsage());

View File

@@ -25,7 +25,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCouponQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildCouponQuery orderByCode($order = Criteria::ASC) Order by the code column
* @method ChildCouponQuery orderByType($order = Criteria::ASC) Order by the type column
* @method ChildCouponQuery orderByAmount($order = Criteria::ASC) Order by the amount column
* @method ChildCouponQuery orderBySerializedEffects($order = Criteria::ASC) Order by the serialized_effects column
* @method ChildCouponQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column
* @method ChildCouponQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column
* @method ChildCouponQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column
@@ -41,7 +41,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCouponQuery groupById() Group by the id column
* @method ChildCouponQuery groupByCode() Group by the code column
* @method ChildCouponQuery groupByType() Group by the type column
* @method ChildCouponQuery groupByAmount() Group by the amount column
* @method ChildCouponQuery groupBySerializedEffects() Group by the serialized_effects column
* @method ChildCouponQuery groupByIsEnabled() Group by the is_enabled column
* @method ChildCouponQuery groupByExpirationDate() Group by the expiration_date column
* @method ChildCouponQuery groupByMaxUsage() Group by the max_usage column
@@ -72,7 +72,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCoupon findOneById(int $id) Return the first ChildCoupon filtered by the id column
* @method ChildCoupon findOneByCode(string $code) Return the first ChildCoupon filtered by the code column
* @method ChildCoupon findOneByType(string $type) Return the first ChildCoupon filtered by the type column
* @method ChildCoupon findOneByAmount(double $amount) Return the first ChildCoupon filtered by the amount column
* @method ChildCoupon findOneBySerializedEffects(string $serialized_effects) Return the first ChildCoupon filtered by the serialized_effects column
* @method ChildCoupon findOneByIsEnabled(boolean $is_enabled) Return the first ChildCoupon filtered by the is_enabled column
* @method ChildCoupon findOneByExpirationDate(string $expiration_date) Return the first ChildCoupon filtered by the expiration_date column
* @method ChildCoupon findOneByMaxUsage(int $max_usage) Return the first ChildCoupon filtered by the max_usage column
@@ -88,7 +88,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method array findById(int $id) Return ChildCoupon objects filtered by the id column
* @method array findByCode(string $code) Return ChildCoupon objects filtered by the code column
* @method array findByType(string $type) Return ChildCoupon objects filtered by the type column
* @method array findByAmount(double $amount) Return ChildCoupon objects filtered by the amount column
* @method array findBySerializedEffects(string $serialized_effects) Return ChildCoupon objects filtered by the serialized_effects column
* @method array findByIsEnabled(boolean $is_enabled) Return ChildCoupon objects filtered by the is_enabled column
* @method array findByExpirationDate(string $expiration_date) Return ChildCoupon objects filtered by the expiration_date column
* @method array findByMaxUsage(int $max_usage) Return ChildCoupon objects filtered by the max_usage column
@@ -195,7 +195,7 @@ abstract class CouponQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0';
$sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -384,44 +384,32 @@ abstract class CouponQuery extends ModelCriteria
}
/**
* Filter the query on the amount column
* Filter the query on the serialized_effects column
*
* Example usage:
* <code>
* $query->filterByAmount(1234); // WHERE amount = 1234
* $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34)
* $query->filterByAmount(array('min' => 12)); // WHERE amount > 12
* $query->filterBySerializedEffects('fooValue'); // WHERE serialized_effects = 'fooValue'
* $query->filterBySerializedEffects('%fooValue%'); // WHERE serialized_effects LIKE '%fooValue%'
* </code>
*
* @param mixed $amount The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $serializedEffects The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponQuery The current query, for fluid interface
*/
public function filterByAmount($amount = null, $comparison = null)
public function filterBySerializedEffects($serializedEffects = null, $comparison = null)
{
if (is_array($amount)) {
$useMinMax = false;
if (isset($amount['min'])) {
$this->addUsingAlias(CouponTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($amount['max'])) {
$this->addUsingAlias(CouponTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
if (null === $comparison) {
if (is_array($serializedEffects)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $serializedEffects)) {
$serializedEffects = str_replace('*', '%', $serializedEffects);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(CouponTableMap::AMOUNT, $amount, $comparison);
return $this->addUsingAlias(CouponTableMap::SERIALIZED_EFFECTS, $serializedEffects, $comparison);
}
/**

View File

@@ -74,10 +74,10 @@ abstract class CouponVersion implements ActiveRecordInterface
protected $type;
/**
* The value for the amount field.
* @var double
* The value for the serialized_effects field.
* @var string
*/
protected $amount;
protected $serialized_effects;
/**
* The value for the is_enabled field.
@@ -464,14 +464,14 @@ abstract class CouponVersion implements ActiveRecordInterface
}
/**
* Get the [amount] column value.
* Get the [serialized_effects] column value.
*
* @return double
* @return string
*/
public function getAmount()
public function getSerializedEffects()
{
return $this->amount;
return $this->serialized_effects;
}
/**
@@ -690,25 +690,25 @@ abstract class CouponVersion implements ActiveRecordInterface
} // setType()
/**
* Set the value of [amount] column.
* Set the value of [serialized_effects] column.
*
* @param double $v new value
* @param string $v new value
* @return \Thelia\Model\CouponVersion The current object (for fluent API support)
*/
public function setAmount($v)
public function setSerializedEffects($v)
{
if ($v !== null) {
$v = (double) $v;
$v = (string) $v;
}
if ($this->amount !== $v) {
$this->amount = $v;
$this->modifiedColumns[] = CouponVersionTableMap::AMOUNT;
if ($this->serialized_effects !== $v) {
$this->serialized_effects = $v;
$this->modifiedColumns[] = CouponVersionTableMap::SERIALIZED_EFFECTS;
}
return $this;
} // setAmount()
} // setSerializedEffects()
/**
* Sets the value of the [is_enabled] column.
@@ -1031,8 +1031,8 @@ abstract class CouponVersion implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CouponVersionTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)];
$this->type = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponVersionTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)];
$this->amount = (null !== $col) ? (double) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponVersionTableMap::translateFieldName('SerializedEffects', TableMap::TYPE_PHPNAME, $indexType)];
$this->serialized_effects = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponVersionTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)];
$this->is_enabled = (null !== $col) ? (boolean) $col : null;
@@ -1313,8 +1313,8 @@ abstract class CouponVersion implements ActiveRecordInterface
if ($this->isColumnModified(CouponVersionTableMap::TYPE)) {
$modifiedColumns[':p' . $index++] = 'TYPE';
}
if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) {
$modifiedColumns[':p' . $index++] = 'AMOUNT';
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) {
$modifiedColumns[':p' . $index++] = 'IS_ENABLED';
@@ -1369,8 +1369,8 @@ abstract class CouponVersion implements ActiveRecordInterface
case 'TYPE':
$stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
break;
case 'AMOUNT':
$stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR);
case 'SERIALIZED_EFFECTS':
$stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR);
break;
case 'IS_ENABLED':
$stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT);
@@ -1470,7 +1470,7 @@ abstract class CouponVersion implements ActiveRecordInterface
return $this->getType();
break;
case 3:
return $this->getAmount();
return $this->getSerializedEffects();
break;
case 4:
return $this->getIsEnabled();
@@ -1537,7 +1537,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$keys[0] => $this->getId(),
$keys[1] => $this->getCode(),
$keys[2] => $this->getType(),
$keys[3] => $this->getAmount(),
$keys[3] => $this->getSerializedEffects(),
$keys[4] => $this->getIsEnabled(),
$keys[5] => $this->getExpirationDate(),
$keys[6] => $this->getMaxUsage(),
@@ -1603,7 +1603,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$this->setType($value);
break;
case 3:
$this->setAmount($value);
$this->setSerializedEffects($value);
break;
case 4:
$this->setIsEnabled($value);
@@ -1665,7 +1665,7 @@ abstract class CouponVersion implements ActiveRecordInterface
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]);
if (array_key_exists($keys[3], $arr)) $this->setSerializedEffects($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]);
@@ -1691,7 +1691,7 @@ abstract class CouponVersion implements ActiveRecordInterface
if ($this->isColumnModified(CouponVersionTableMap::ID)) $criteria->add(CouponVersionTableMap::ID, $this->id);
if ($this->isColumnModified(CouponVersionTableMap::CODE)) $criteria->add(CouponVersionTableMap::CODE, $this->code);
if ($this->isColumnModified(CouponVersionTableMap::TYPE)) $criteria->add(CouponVersionTableMap::TYPE, $this->type);
if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) $criteria->add(CouponVersionTableMap::AMOUNT, $this->amount);
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) $criteria->add(CouponVersionTableMap::SERIALIZED_EFFECTS, $this->serialized_effects);
if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) $criteria->add(CouponVersionTableMap::IS_ENABLED, $this->is_enabled);
if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) $criteria->add(CouponVersionTableMap::EXPIRATION_DATE, $this->expiration_date);
if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) $criteria->add(CouponVersionTableMap::MAX_USAGE, $this->max_usage);
@@ -1776,7 +1776,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$copyObj->setId($this->getId());
$copyObj->setCode($this->getCode());
$copyObj->setType($this->getType());
$copyObj->setAmount($this->getAmount());
$copyObj->setSerializedEffects($this->getSerializedEffects());
$copyObj->setIsEnabled($this->getIsEnabled());
$copyObj->setExpirationDate($this->getExpirationDate());
$copyObj->setMaxUsage($this->getMaxUsage());
@@ -1874,7 +1874,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$this->id = null;
$this->code = null;
$this->type = null;
$this->amount = null;
$this->serialized_effects = null;
$this->is_enabled = null;
$this->expiration_date = null;
$this->max_usage = null;

View File

@@ -24,7 +24,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersionQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildCouponVersionQuery orderByCode($order = Criteria::ASC) Order by the code column
* @method ChildCouponVersionQuery orderByType($order = Criteria::ASC) Order by the type column
* @method ChildCouponVersionQuery orderByAmount($order = Criteria::ASC) Order by the amount column
* @method ChildCouponVersionQuery orderBySerializedEffects($order = Criteria::ASC) Order by the serialized_effects column
* @method ChildCouponVersionQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column
* @method ChildCouponVersionQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column
* @method ChildCouponVersionQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column
@@ -40,7 +40,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersionQuery groupById() Group by the id column
* @method ChildCouponVersionQuery groupByCode() Group by the code column
* @method ChildCouponVersionQuery groupByType() Group by the type column
* @method ChildCouponVersionQuery groupByAmount() Group by the amount column
* @method ChildCouponVersionQuery groupBySerializedEffects() Group by the serialized_effects column
* @method ChildCouponVersionQuery groupByIsEnabled() Group by the is_enabled column
* @method ChildCouponVersionQuery groupByExpirationDate() Group by the expiration_date column
* @method ChildCouponVersionQuery groupByMaxUsage() Group by the max_usage column
@@ -67,7 +67,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersion findOneById(int $id) Return the first ChildCouponVersion filtered by the id column
* @method ChildCouponVersion findOneByCode(string $code) Return the first ChildCouponVersion filtered by the code column
* @method ChildCouponVersion findOneByType(string $type) Return the first ChildCouponVersion filtered by the type column
* @method ChildCouponVersion findOneByAmount(double $amount) Return the first ChildCouponVersion filtered by the amount column
* @method ChildCouponVersion findOneBySerializedEffects(string $serialized_effects) Return the first ChildCouponVersion filtered by the serialized_effects column
* @method ChildCouponVersion findOneByIsEnabled(boolean $is_enabled) Return the first ChildCouponVersion filtered by the is_enabled column
* @method ChildCouponVersion findOneByExpirationDate(string $expiration_date) Return the first ChildCouponVersion filtered by the expiration_date column
* @method ChildCouponVersion findOneByMaxUsage(int $max_usage) Return the first ChildCouponVersion filtered by the max_usage column
@@ -83,7 +83,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method array findById(int $id) Return ChildCouponVersion objects filtered by the id column
* @method array findByCode(string $code) Return ChildCouponVersion objects filtered by the code column
* @method array findByType(string $type) Return ChildCouponVersion objects filtered by the type column
* @method array findByAmount(double $amount) Return ChildCouponVersion objects filtered by the amount column
* @method array findBySerializedEffects(string $serialized_effects) Return ChildCouponVersion objects filtered by the serialized_effects column
* @method array findByIsEnabled(boolean $is_enabled) Return ChildCouponVersion objects filtered by the is_enabled column
* @method array findByExpirationDate(string $expiration_date) Return ChildCouponVersion objects filtered by the expiration_date column
* @method array findByMaxUsage(int $max_usage) Return ChildCouponVersion objects filtered by the max_usage column
@@ -183,7 +183,7 @@ abstract class CouponVersionQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1';
$sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
@@ -386,44 +386,32 @@ abstract class CouponVersionQuery extends ModelCriteria
}
/**
* Filter the query on the amount column
* Filter the query on the serialized_effects column
*
* Example usage:
* <code>
* $query->filterByAmount(1234); // WHERE amount = 1234
* $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34)
* $query->filterByAmount(array('min' => 12)); // WHERE amount > 12
* $query->filterBySerializedEffects('fooValue'); // WHERE serialized_effects = 'fooValue'
* $query->filterBySerializedEffects('%fooValue%'); // WHERE serialized_effects LIKE '%fooValue%'
* </code>
*
* @param mixed $amount The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $serializedEffects The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponVersionQuery The current query, for fluid interface
*/
public function filterByAmount($amount = null, $comparison = null)
public function filterBySerializedEffects($serializedEffects = null, $comparison = null)
{
if (is_array($amount)) {
$useMinMax = false;
if (isset($amount['min'])) {
$this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($amount['max'])) {
$this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
if (null === $comparison) {
if (is_array($serializedEffects)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $serializedEffects)) {
$serializedEffects = str_replace('*', '%', $serializedEffects);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount, $comparison);
return $this->addUsingAlias(CouponVersionTableMap::SERIALIZED_EFFECTS, $serializedEffects, $comparison);
}
/**

0
core/lib/Thelia/Model/Base/OrderCouponQuery.php Normal file → Executable file
View File

View File

@@ -27,6 +27,7 @@ use Propel\Runtime\Propel;
use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Coupon\ConditionCollection;
use Thelia\Model\Base\Coupon as BaseCoupon;
use Thelia\Model\Exception\InvalidArgumentException;
use Thelia\Model\Map\CouponTableMap;
/**
@@ -53,7 +54,7 @@ class Coupon extends BaseCoupon
*
* @param string $code Coupon Code
* @param string $title Coupon title
* @param float $amount Amount removed from the Total Checkout
* @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
@@ -68,20 +69,20 @@ class Coupon extends BaseCoupon
*
* @throws \Exception
*/
function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null)
function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null)
{
$this->setCode($code)
->setTitle($title)
->setShortDescription($shortDescription)
->setDescription($description)
->setType($type)
->setAmount($amount)
->setEffects($effects)
->setIsRemovingPostage($isRemovingPostage)
->setIsEnabled($isEnabled)
->setExpirationDate($expirationDate)
->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
->setIsCumulative($isCumulative)
->setMaxUsage($maxUsage);
$this->setTitle($title)
->setShortDescription($shortDescription)
->setDescription($description);
// If no rule given, set default rule
if (null === $this->getSerializedConditions()) {
@@ -132,4 +133,82 @@ class Coupon extends BaseCoupon
throw $e;
}
}
/**
* Get the amount removed from the coupon to the cart
*
* @return float
*/
public function getAmount()
{
$amount = $this->getEffects()['amount'];
return floatval($amount);
}
/**
* Get the Coupon effects
*
* @return array
* @throws Exception\InvalidArgumentException
*/
public function getEffects()
{
$effects = $this->unserializeEffects($this->getSerializedEffects());
if (null === $effects['amount']) {
throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect coming from database');
}
return $effects;
}
/**
* Get the Coupon effects
*
* @param array $effects Effect ready to be serialized
* Needs at least the key 'amount'
* with the amount removed from the cart
*
* @throws Exception\InvalidArgumentException
* @return $this
*/
public function setEffects(array $effects)
{
if (null === $effects['amount']) {
throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array');
}
$this->setSerializedEffects($this->serializeEffects($effects));
return $this;
}
/**
* Return unserialized effects
*
* @param string $serializedEffects Serialized effect string to unserialize
*
* @return array
*/
public function unserializeEffects($serializedEffects)
{
$effects = json_decode($serializedEffects, true);
return $effects;
}
/**
* Return serialized effects
*
* @param array $unserializedEffects Unserialized array string to serialize
*
* @return string
*/
public function serializeEffects(array $unserializedEffects)
{
$effects = json_encode($unserializedEffects);
return $effects;
}
}

View File

@@ -85,9 +85,9 @@ class CouponTableMap extends TableMap
const TYPE = 'coupon.TYPE';
/**
* the column name for the AMOUNT field
* the column name for the SERIALIZED_EFFECTS field
*/
const AMOUNT = 'coupon.AMOUNT';
const SERIALIZED_EFFECTS = 'coupon.SERIALIZED_EFFECTS';
/**
* the column name for the IS_ENABLED field
@@ -165,11 +165,11 @@ class CouponTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ),
self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::AMOUNT, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::IS_USED, CouponTableMap::SERIALIZED_CONDITIONS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ),
self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ),
self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ),
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ),
self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::SERIALIZED_EFFECTS, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::IS_USED, CouponTableMap::SERIALIZED_CONDITIONS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ),
self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'SERIALIZED_EFFECTS', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ),
self::TYPE_FIELDNAME => array('id', 'code', 'type', 'serialized_effects', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
);
@@ -180,11 +180,11 @@ class CouponTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ),
self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::AMOUNT => 3, CouponTableMap::IS_ENABLED => 4, CouponTableMap::EXPIRATION_DATE => 5, CouponTableMap::MAX_USAGE => 6, CouponTableMap::IS_CUMULATIVE => 7, CouponTableMap::IS_REMOVING_POSTAGE => 8, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponTableMap::IS_USED => 10, CouponTableMap::SERIALIZED_CONDITIONS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ),
self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ),
self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'SerializedEffects' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serializedEffects' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ),
self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::SERIALIZED_EFFECTS => 3, CouponTableMap::IS_ENABLED => 4, CouponTableMap::EXPIRATION_DATE => 5, CouponTableMap::MAX_USAGE => 6, CouponTableMap::IS_CUMULATIVE => 7, CouponTableMap::IS_REMOVING_POSTAGE => 8, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponTableMap::IS_USED => 10, CouponTableMap::SERIALIZED_CONDITIONS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'SERIALIZED_EFFECTS' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ),
self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serialized_effects' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
);
@@ -207,7 +207,7 @@ class CouponTableMap extends TableMap
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null);
$this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null);
$this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null);
$this->addColumn('SERIALIZED_EFFECTS', 'SerializedEffects', 'LONGVARCHAR', true, null, null);
$this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null);
$this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null);
$this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null);
@@ -396,7 +396,7 @@ class CouponTableMap extends TableMap
$criteria->addSelectColumn(CouponTableMap::ID);
$criteria->addSelectColumn(CouponTableMap::CODE);
$criteria->addSelectColumn(CouponTableMap::TYPE);
$criteria->addSelectColumn(CouponTableMap::AMOUNT);
$criteria->addSelectColumn(CouponTableMap::SERIALIZED_EFFECTS);
$criteria->addSelectColumn(CouponTableMap::IS_ENABLED);
$criteria->addSelectColumn(CouponTableMap::EXPIRATION_DATE);
$criteria->addSelectColumn(CouponTableMap::MAX_USAGE);
@@ -412,7 +412,7 @@ class CouponTableMap extends TableMap
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.CODE');
$criteria->addSelectColumn($alias . '.TYPE');
$criteria->addSelectColumn($alias . '.AMOUNT');
$criteria->addSelectColumn($alias . '.SERIALIZED_EFFECTS');
$criteria->addSelectColumn($alias . '.IS_ENABLED');
$criteria->addSelectColumn($alias . '.EXPIRATION_DATE');
$criteria->addSelectColumn($alias . '.MAX_USAGE');

View File

@@ -85,9 +85,9 @@ class CouponVersionTableMap extends TableMap
const TYPE = 'coupon_version.TYPE';
/**
* the column name for the AMOUNT field
* the column name for the SERIALIZED_EFFECTS field
*/
const AMOUNT = 'coupon_version.AMOUNT';
const SERIALIZED_EFFECTS = 'coupon_version.SERIALIZED_EFFECTS';
/**
* the column name for the IS_ENABLED field
@@ -156,11 +156,11 @@ class CouponVersionTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ),
self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::AMOUNT, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::IS_USED, CouponVersionTableMap::SERIALIZED_CONDITIONS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ),
self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ),
self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ),
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ),
self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::SERIALIZED_EFFECTS, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::IS_USED, CouponVersionTableMap::SERIALIZED_CONDITIONS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ),
self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'SERIALIZED_EFFECTS', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ),
self::TYPE_FIELDNAME => array('id', 'code', 'type', 'serialized_effects', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
);
@@ -171,11 +171,11 @@ class CouponVersionTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ),
self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::AMOUNT => 3, CouponVersionTableMap::IS_ENABLED => 4, CouponVersionTableMap::EXPIRATION_DATE => 5, CouponVersionTableMap::MAX_USAGE => 6, CouponVersionTableMap::IS_CUMULATIVE => 7, CouponVersionTableMap::IS_REMOVING_POSTAGE => 8, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponVersionTableMap::IS_USED => 10, CouponVersionTableMap::SERIALIZED_CONDITIONS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ),
self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ),
self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'SerializedEffects' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serializedEffects' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ),
self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::SERIALIZED_EFFECTS => 3, CouponVersionTableMap::IS_ENABLED => 4, CouponVersionTableMap::EXPIRATION_DATE => 5, CouponVersionTableMap::MAX_USAGE => 6, CouponVersionTableMap::IS_CUMULATIVE => 7, CouponVersionTableMap::IS_REMOVING_POSTAGE => 8, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponVersionTableMap::IS_USED => 10, CouponVersionTableMap::SERIALIZED_CONDITIONS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'SERIALIZED_EFFECTS' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ),
self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serialized_effects' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
);
@@ -198,7 +198,7 @@ class CouponVersionTableMap extends TableMap
$this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'coupon', 'ID', true, null, null);
$this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null);
$this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null);
$this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null);
$this->addColumn('SERIALIZED_EFFECTS', 'SerializedEffects', 'LONGVARCHAR', true, null, null);
$this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null);
$this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null);
$this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null);
@@ -410,7 +410,7 @@ class CouponVersionTableMap extends TableMap
$criteria->addSelectColumn(CouponVersionTableMap::ID);
$criteria->addSelectColumn(CouponVersionTableMap::CODE);
$criteria->addSelectColumn(CouponVersionTableMap::TYPE);
$criteria->addSelectColumn(CouponVersionTableMap::AMOUNT);
$criteria->addSelectColumn(CouponVersionTableMap::SERIALIZED_EFFECTS);
$criteria->addSelectColumn(CouponVersionTableMap::IS_ENABLED);
$criteria->addSelectColumn(CouponVersionTableMap::EXPIRATION_DATE);
$criteria->addSelectColumn(CouponVersionTableMap::MAX_USAGE);
@@ -426,7 +426,7 @@ class CouponVersionTableMap extends TableMap
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.CODE');
$criteria->addSelectColumn($alias . '.TYPE');
$criteria->addSelectColumn($alias . '.AMOUNT');
$criteria->addSelectColumn($alias . '.SERIALIZED_EFFECTS');
$criteria->addSelectColumn($alias . '.IS_ENABLED');
$criteria->addSelectColumn($alias . '.EXPIRATION_DATE');
$criteria->addSelectColumn($alias . '.MAX_USAGE');

View File

@@ -7,6 +7,8 @@ use Thelia\Condition\Implementation\MatchForXArticles;
use Thelia\Condition\Operators;
use Thelia\Coupon\FacadeInterface;
use Thelia\Condition\ConditionCollection;
use Thelia\Coupon\Type\RemoveXAmount;
use Thelia\Coupon\Type\RemoveXPercent;
require __DIR__ . '/../core/bootstrap.php';
@@ -663,7 +665,9 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse
Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.
Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
$coupon1->setAmount(10.00);
$coupon1->setEffects(array(
RemoveXAmount::INPUT_AMOUNT_NAME => 10.00,
));
$coupon1->setIsUsed(true);
$coupon1->setIsEnabled(true);
$date = new \DateTime();
@@ -721,7 +725,10 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse
Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.
Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
$coupon2->setAmount(10.00);
$coupon2->setEffects(array(
RemoveXPercent::INPUT_AMOUNT_NAME => 0.00,
RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00,
));
$coupon2->setIsUsed(true);
$coupon2->setIsEnabled(true);
$date = new \DateTime();
@@ -765,7 +772,10 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse
Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.
Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
$coupon3->setAmount(10.00);
$coupon3->setEffects(array(
RemoveXPercent::INPUT_AMOUNT_NAME => 0.00,
RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00,
));
$coupon3->setIsUsed(false);
$coupon3->setIsEnabled(false);
$date = new \DateTime();

View File

@@ -1084,7 +1084,7 @@ CREATE TABLE `coupon`
`id` INTEGER NOT NULL AUTO_INCREMENT,
`code` VARCHAR(45) NOT NULL,
`type` VARCHAR(255) NOT NULL,
`amount` FLOAT NOT NULL,
`serialized_effects` TEXT NOT NULL,
`is_enabled` TINYINT(1) NOT NULL,
`expiration_date` DATETIME NOT NULL,
`max_usage` INTEGER NOT NULL,
@@ -1101,7 +1101,6 @@ CREATE TABLE `coupon`
INDEX `idx_is_enabled` (`is_enabled`),
INDEX `idx_is_used` (`is_used`),
INDEX `idx_type` (`type`),
INDEX `idx_amount` (`amount`),
INDEX `idx_expiration_date` (`expiration_date`),
INDEX `idx_is_cumulative` (`is_cumulative`),
INDEX `idx_is_removing_postage` (`is_removing_postage`),
@@ -2385,7 +2384,7 @@ CREATE TABLE `coupon_version`
`id` INTEGER NOT NULL,
`code` VARCHAR(45) NOT NULL,
`type` VARCHAR(255) NOT NULL,
`amount` FLOAT NOT NULL,
`serialized_effects` TEXT NOT NULL,
`is_enabled` TINYINT(1) NOT NULL,
`expiration_date` DATETIME NOT NULL,
`max_usage` INTEGER NOT NULL,

View File

@@ -852,7 +852,7 @@
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="code" required="true" size="45" type="VARCHAR" />
<column name="type" required="true" size="255" type="VARCHAR" />
<column name="amount" required="true" type="FLOAT" />
<column name="serialized_effects" required="true" type="LONGVARCHAR" />
<column name="title" required="true" size="255" type="VARCHAR" />
<column name="is_enabled" required="true" type="BOOLEAN" />
<column name="short_description" required="true" type="LONGVARCHAR" />
@@ -876,9 +876,6 @@
<index name="idx_type">
<index-column name="type" />
</index>
<index name="idx_amount">
<index-column name="amount" />
</index>
<index name="idx_expiration_date">
<index-column name="expiration_date" />
</index>

0
local/modules/TheliaDebugBar/Config/routing.xml Normal file → Executable file
View File

View File

@@ -134,8 +134,9 @@ $(function($){
var inputsDiv = mainDiv.find('.inputs');
inputsDiv.html('<div class="loading" ></div>');
var url = $.couponManager.urlAjaxAdminCouponDrawInputs;
console.log(url);
url = url.replace('couponServiceId', optionSelected.val());
console.log(url);
$.ajax({
type: "GET",
url: url,

View File

@@ -60,10 +60,11 @@
external_plugins: { "filemanager" : "{url file='/tinymce/plugins/filemanager/plugin.min.js'}"}
});
// Url alowing to get coupon inputs
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
$(function($){
// Url alowing to get coupon inputs
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
});
</script>
{/block}