Added per-user coupon maximum usage count

This commit is contained in:
Franck Allimant
2014-05-17 10:20:26 +02:00
parent 9cdac6d50e
commit f8ccea1899
43 changed files with 4506 additions and 152 deletions

View File

@@ -25,11 +25,13 @@ use Thelia\Core\HttpFoundation\Request;
use Thelia\Coupon\CouponFactory;
use Thelia\Coupon\CouponManager;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Base\CouponCountry;
use Thelia\Model\Base\CouponModule;
use Thelia\Model\Base\CouponModuleQuery;
use Thelia\Model\Coupon as CouponModel;
use Thelia\Model\CouponCountry;
use Thelia\Model\CouponCountryQuery;
use Thelia\Model\CouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery;
use Thelia\Model\CouponModule;
use Thelia\Model\CouponModuleQuery;
use Thelia\Model\CouponQuery;
use Thelia\Model\Map\OrderCouponTableMap;
use Thelia\Model\OrderCoupon;
@@ -40,7 +42,7 @@ use Thelia\Model\OrderCouponModule;
* Process Coupon Events
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
* @author Guillaume MOREL <gmorel@openstudio.fr>, Franck Allimant <franck@cqfdev.fr>
*
*/
class Coupon extends BaseAction implements EventSubscriberInterface
@@ -123,7 +125,9 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$coupon = $this->couponFactory->buildCouponFromCode($event->getCode());
if ($coupon) {
$isValid = $coupon->isMatching();
if ($isValid) {
$consumedCoupons = $this->request->getSession()->getConsumedCoupons();
@@ -132,6 +136,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
}
if (!isset($consumedCoupons[$event->getCode()])) {
// Prevent accumulation of the same Coupon on a Checkout
$consumedCoupons[$event->getCode()] = $event->getCode();
@@ -148,7 +153,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
->getSession()
->getOrder()
->setDiscount($totalDiscount)
// ->save()
;
}
}
@@ -158,9 +162,8 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$event->setDiscount($totalDiscount);
}
public function updateOrderDiscount($event)
public function updateOrderDiscount(/** @noinspection PhpUnusedParameterInspection */ $event)
{
$discount = $this->couponManager->getDiscount();
$this->request
@@ -168,6 +171,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
->getCart()
->setDiscount($discount)
->save();
$this->request
->getSession()
->getOrder()
@@ -212,7 +216,8 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$defaultSerializedRule,
$event->getLocale(),
$event->getFreeShippingForCountries(),
$event->getFreeShippingForMethods()
$event->getFreeShippingForMethods(),
$event->getPerCustomerUsageCount()
);
$event->setCouponModel($coupon);
@@ -278,7 +283,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$couponModel->setLocale($this->request->getSession()->getLang()->getLocale());
/* decrease coupon quantity */
$this->couponManager->decrementQuantity($couponModel);
$this->couponManager->decrementQuantity($couponModel, $event->getOrder()->getCustomerId());
/* memorize coupon */
$orderCoupon = new OrderCoupon();
@@ -296,6 +301,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
->setIsRemovingPostage($couponModel->getIsRemovingPostage())
->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())
->setSerializedConditions($couponModel->getSerializedConditions())
->setPerCustomerUsageCount($couponModel->getPerCustomerUsageCount())
;
$orderCoupon->save();

View File

@@ -25,24 +25,30 @@ return array(
'Administrator ID not found' => 'Administrator ID not found',
'Advertise this product as new' => 'Advertise this product as new',
'Alerts' => 'Alerts',
'All countries' => 'All countries',
'All shipping methods' => 'All shipping methods',
'Alpha code 2 *' => 'Alpha code 2 *',
'Alpha code 3 *' => 'Alpha code 3 *',
'Apply exchange rates on price in %sym' => 'Apply exchange rates on price in %sym',
'At least one of cart products categories is %op% <strong>%categories_list%</strong>' => 'At least one of cart products categories is %op% <strong>%categories_list%</strong>',
'Attribute ID:Attribute AV ID' => 'Attribute ID:Attribute AV ID',
'Auth mode' => 'Auth mode',
'Available quantity' => 'Available quantity',
'Available quantity *' => 'Available quantity *',
'Available shipping zones' => 'Available shipping zones',
'Bad tax list JSON' => 'Bad tax list JSON',
'Billing country condition' => 'Pays de facturation',
'Billing country' => 'Billing country',
'Billing coutry is' => 'Le pays de facturation est',
'Business ID' => 'Business ID',
'By cart total amount' => 'By cart total amount',
'Cannot find a default country. Please define one.' => 'Cannot find a default country. Please define one.',
'Cannot find the shop country. Please select a shop country.' => 'Cannot find the shop country. Please select a shop country.',
'Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?' => 'Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?',
'Cart item count condition' => 'Cart item count condition',
'Cart contains at least a product %op% <strong>%products_list%</strong>' => 'Cart contains at least a product %op% <strong>%products_list%</strong>',
'Cart contains categories condition' => 'Cart contains categories condition',
'Cart contains specific products' => 'Cart contains specific products',
'Cart item count' => 'Cart item count',
'Cart item count is' => 'Cart item count is',
'Cart total amount' => 'Cart total amount',
'Cart total amount is' => 'Cart total amount is',
'Category title *' => 'Category title *',
'Cellphone' => 'Cellphone',
@@ -61,16 +67,19 @@ return array(
'Country ID not found' => 'Country ID not found',
'Country area' => 'Country area',
'Country title *' => 'Country title *',
'Coupon %code is expired.' => 'Coupon %code is expired.',
'Critical' => 'Critical',
'Current Password' => 'Current Password',
'Customer is %op% <strong>%customer_list%</strong>' => 'Customer is %op% <strong>%customer_list%</strong>',
'Date \'%date\' is invalid, please enter a valid date using %fmt format' => 'Date \'%date\' is invalid, please enter a valid date using %fmt format',
'Debug' => 'Debug',
'Decimal places' => 'Decimal places',
'Default folder *' => 'Default folder *',
'Default product category *' => 'Default product category *',
'Default product sale element' => 'Default product sale element',
'Deleting document for %id% with parent id %parentId%' => 'Deleting document for %id% with parent id %parentId%',
'Deleting image for %id% with parent id %parentId%' => 'Deleting image for %id% with parent id %parentId%',
'Delivery country condition' => 'Pays de livraison',
'Delivery country' => 'Delivery country',
'Delivery coutry is' => 'Le pays de livraison est',
'Delivery module ID not found' => 'Delivery module ID not found',
'Description' => 'Description',
@@ -103,7 +112,9 @@ return array(
'First Name' => 'First Name',
'Firstname' => 'Firstname',
'Fixed Amount Discount' => 'Fixed Amount Discount',
'Fixed amount discount on selected categories' => 'Fixed amount discount on selected categories',
'Folder title *' => 'Folder title *',
'For one ore more customers' => 'For one ore more customers',
'Full Name' => 'Full Name',
'Greater than' => 'Greater than',
'Greater than or equals' => 'Greater than or equals',
@@ -140,6 +151,7 @@ return array(
'Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`' => 'Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`',
'Loop type \'%type\' is not defined.' => 'Loop type \'%type\' is not defined.',
'Make this address as my primary address' => 'Make this address as my primary address',
'Maximum usage count reached for coupon %code' => 'Maximum usage count reached for coupon %code',
'Message subject' => 'Message subject',
'Meta Description' => 'Meta Description',
'Meta Keywords' => 'Meta Keywords',
@@ -170,12 +182,14 @@ return array(
'Order address ID not found' => 'Order address ID not found',
'Order ref. %ref is now unpaid.' => 'Order ref. %ref is now unpaid.',
'Order ref. %ref, ID %id has been successfully paid.' => 'Order ref. %ref, ID %id has been successfully paid.',
'Overall' => 'Overall',
'Page Title' => 'Page Title',
'Parent category *' => 'Parent category *',
'Parent folder *' => 'Parent folder *',
'Password' => 'Password',
'Password *' => 'Password *',
'Password confirmation' => 'Password confirmation',
'Per customer' => 'Per customer',
'Percent Discount' => 'Percent Discount',
'Percentage of the product price' => 'Percentage of the product price',
'Phone' => 'Phone',
@@ -260,6 +274,9 @@ return array(
'Text Message' => 'Text Message',
'The TaxEngine should be passed to this form before using it.' => 'The TaxEngine should be passed to this form before using it.',
'The cart item count should match the condition' => 'The cart item count should match the condition',
'The coupon applies if the cart contains at least one product of the selected categories' => 'The coupon applies if the cart contains at least one product of the selected categories',
'The coupon applies if the cart contains at least one product of the specified product list' => 'The coupon applies if the cart contains at least one product of the specified product list',
'The coupon applies to some customers only' => 'The coupon applies to some customers only',
'The coupon applies to the selected delivery countries' => 'Ce code promo s\'applique seulement aux pays de facturation sélectionnés',
'The coupon is valid after a given date' => 'Le code promo est valide seulement à partir d\'une certaine date',
'The image which replaces an undefined country flag (%file) was not found. Please check unknown-flag-path configuration variable, and check that the image exists.' => 'The image which replaces an undefined country flag (%file) was not found. Please check unknown-flag-path configuration variable, and check that the image exists.',
@@ -268,6 +285,7 @@ return array(
'This condition is always true' => 'This condition is always true',
'This content is online.' => 'This content is online.',
'This coupon does not exists' => 'This coupon does not exists',
'This coupon subtracts the specified amount from the order total for each product of the selected categories. If the discount is greater than the total order, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.' => 'This coupon subtracts the specified amount from the order total for each product of the selected categories. If the discount is greater than the total order, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.',
'This coupon will offert a flat percentage off a shopper\'s entire order (not applied to shipping costs or tax rates). If the discount is greater than the total order corst, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.' => 'This coupon will offert a flat percentage off a shopper\'s entire order (not applied to shipping costs or tax rates). If the discount is greater than the total order corst, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.',
'This coupon will subtracts a set amount from the total cost of an order. If the discount is greater than the total order corst, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.' => 'This coupon will subtracts a set amount from the total cost of an order. If the discount is greater than the total order corst, the customer will only pay the shipping, or nothing if the coupon also provides free shipping.',
'This email already exists.' => 'This email already exists.',

View File

@@ -67,6 +67,7 @@ return array(
'Country ID not found' => 'ID du pays non trouvé',
'Country area' => 'Zone du pays',
'Country title *' => 'Pays *',
'Coupon %code is expired.' => 'La date limite d\'utilisation du coupon %code est dépassée.',
'Critical' => 'Critique',
'Current Password' => 'Mot de passe actuel.',
'Customer is %op% <strong>%customer_list%</strong>' => 'Le client est %op% <strong>%customer_list%</strong> ',
@@ -149,6 +150,7 @@ return array(
'Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`' => 'Une boucle doit implémenter au moins une de ces interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`',
'Loop type \'%type\' is not defined.' => 'La boucle de type \'%type\' n\'existe pas.',
'Make this address as my primary address' => 'Choisir cette adresse comme adresse par défaut',
'Maximum usage count reached for coupon %code' => 'Le nombre maximum d\'utilisation pour le coupon %code est dépassé.',
'Message subject' => 'Sujet',
'Meta Description' => 'Meta description',
'Meta Keywords' => 'Meta keywords',
@@ -179,12 +181,14 @@ return array(
'Order address ID not found' => 'ID de l\'adresse de la commande non trouvé',
'Order ref. %ref is now unpaid.' => 'La commande %ref, ID %id est désormais non payée',
'Order ref. %ref, ID %id has been successfully paid.' => 'La commande ref. %ref, ID %id a été correctement payée',
'Overall' => 'Pour tous les clients',
'Page Title' => 'Titre de la page',
'Parent category *' => 'Catégorie parente *',
'Parent folder *' => 'Dossier parent *',
'Password' => 'Mot de passe',
'Password *' => 'Mot de passe *',
'Password confirmation' => 'Confirmation du mot de passe.',
'Per customer' => 'Par client',
'Percent Discount' => 'Remise en pourcentage de la commande',
'Percentage of the product price' => 'Pourcentage du prix du produit',
'Phone' => 'Téléphone',

View File

@@ -185,7 +185,8 @@ class CouponController extends BaseAdminController
'conditions' => $conditions,
'locale' => $this->getCurrentEditionLocale(),
'freeShippingForCountries' => $freeShippingForCountries,
'freeShippingForModules' => $freeShippingForModules
'freeShippingForModules' => $freeShippingForModules,
'perCustomerUsageCount' => $coupon->getPerCustomerUsageCount(),
];
$args['conditions'] = $this->cleanConditionForTemplate($conditions);
@@ -721,7 +722,7 @@ class CouponController extends BaseAdminController
$couponManager = $this->container->get($serviceId);
$effects = [CouponAbstract::INPUT_AMOUNT_NAME => $data[CouponAbstract::INPUT_AMOUNT_NAME]];
$effects = $this->addExtendedLogic($effects, $couponManager->getExtendedInputs());
var_dump($data);
$couponEvent = new CouponCreateOrUpdateEvent(
$data['code'],
$serviceId,
@@ -737,7 +738,8 @@ var_dump($data);
$data['maxUsage'],
$data['locale'],
$data['freeShippingForCountries'],
$data['freeShippingForModules']
$data['freeShippingForModules'],
$data['perCustomerUsageCount']
);
// If Update mode
@@ -797,7 +799,8 @@ var_dump($data);
$coupon->getMaxUsage(),
$coupon->getLocale(),
$coupon->getFreeShippingForCountries(),
$coupon->getFreeShippingForModules()
$coupon->getFreeShippingForModules(),
$coupon->getPerCustomerUsageCount()
);
$couponEvent->setCouponModel($coupon);
$couponEvent->setConditions($conditions);

View File

@@ -79,6 +79,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent
/** @var array ID of Shipping modules for which shipping is free */
protected $freeShippingForMethods;
/** @var true if usage count is per customer only */
protected $perCustomerUsageCount;
/**
* Constructor
*
@@ -99,11 +102,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
* @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 boolean $perCustomerUsageCount Usage count is per customer
*/
public function __construct(
$code, $serviceId, $title, array $effects, $shortDescription, $description,
$isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative,
$isRemovingPostage, $maxUsage, $locale, $freeShippingForCountries, $freeShippingForMethods)
$isRemovingPostage, $maxUsage, $locale, $freeShippingForCountries, $freeShippingForMethods,
$perCustomerUsageCount)
{
$this->code = $code;
$this->description = $description;
@@ -120,6 +125,24 @@ class CouponCreateOrUpdateEvent extends ActionEvent
$this->setEffects($effects);
$this->freeShippingForCountries = $freeShippingForCountries;
$this->freeShippingForMethods = $freeShippingForMethods;
$this->perCustomerUsageCount = $perCustomerUsageCount;
}
/**
* @param true $perCustomerUsageCount
*/
public function setPerCustomerUsageCount($perCustomerUsageCount)
{
$this->perCustomerUsageCount = $perCustomerUsageCount;
return $this;
}
/**
* @return true
*/
public function getPerCustomerUsageCount()
{
return $this->perCustomerUsageCount;
}
/**

View File

@@ -182,7 +182,8 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
$coupon->getMaxUsage(),
$coupon->getExpirationDate(),
$coupon->getFreeShippingForCountries(),
$coupon->getFreeShippingForModules()
$coupon->getFreeShippingForModules(),
$coupon->getPerCustomerUsageCount()
);
$cleanedConditions = array();
@@ -217,6 +218,7 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
->set("DESCRIPTION", $coupon->getVirtualColumn('i18n_DESCRIPTION'))
->set("EXPIRATION_DATE", $coupon->getExpirationDate())
->set("USAGE_LEFT", $coupon->getMaxUsage())
->set("PER_CUSTOMER_USAGE_COUNT", $coupon->getPerCustomerUsageCount())
->set("IS_CUMULATIVE", $coupon->getIsCumulative())
->set("IS_REMOVING_POSTAGE", $coupon->getIsRemovingPostage())
->set("IS_AVAILABLE_ON_SPECIAL_OFFERS", $coupon->getIsAvailableOnSpecialOffers())

View File

@@ -104,6 +104,7 @@ class OrderCoupon extends BaseLoop implements PropelSearchLoopInterface
->set("DAY_LEFT_BEFORE_EXPIRATION", $daysLeftBeforeExpiration)
->set("FREE_SHIPPING_FOR_COUNTRIES_LIST", implode(',', $freeShippingForCountriesIds))
->set("FREE_SHIPPING_FOR_MODULES_LIST", implode(',', $freeShippingForModulesIds))
->set("PER_CUSTOMER_USAGE_COUNT", $orderCoupon->getPerCustomerUsageCount())
;
$loopResult->addRow($loopResultRow);

View File

@@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Condition\ConditionFactory;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Exception\CouponExpiredException;
use Thelia\Exception\CouponNoUsageLeftException;
use Thelia\Exception\InvalidConditionException;
use Thelia\Model\Coupon;
@@ -62,12 +63,19 @@ class CouponFactory
return false;
}
// Check coupon expiration date
if ($couponModel->getExpirationDate() < new \DateTime()) {
throw new CouponExpiredException($couponCode);
}
// Check coupon usage count
if ($couponModel->getUsagesLeft($this->facade->getCustomer()->getId()) <= 0) {
throw new CouponNoUsageLeftException($couponCode);
}
/** @var CouponInterface $couponInterface */
$couponInterface = $this->buildCouponFromModel($couponModel);
if ($couponInterface && $couponInterface->getConditions()->count() == 0) {
throw new InvalidConditionException(
get_class($couponInterface)
@@ -109,7 +117,8 @@ class CouponFactory
$model->getMaxUsage(),
$model->getExpirationDate(),
$model->getFreeShippingForCountries(),
$model->getFreeShippingForModules()
$model->getFreeShippingForModules(),
$model->getPerCustomerUsageCount()
);
/** @var ConditionFactory $conditionFactory */

View File

@@ -20,6 +20,8 @@ use Thelia\Model\AddressQuery;
use Thelia\Model\Base\CouponModule;
use Thelia\Model\Coupon;
use Thelia\Model\CouponCountry;
use Thelia\Model\CouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery;
use Thelia\Model\Order;
use Thelia\Model\OrderAddress;
use Thelia\Model\OrderAddressQuery;
@@ -272,26 +274,64 @@ class CouponManager
* To call when a coupon is consumed
*
* @param \Thelia\Model\Coupon $coupon Coupon consumed
* @param int|null $customerId the ID of the ordering customer
*
* @return int Usage left after decremental
*/
public function decrementQuantity(Coupon $coupon)
public function decrementQuantity(Coupon $coupon, $customerId = null)
{
$ret = -1;
$ret = false;
try {
$usageLeft = $coupon->getMaxUsage();
$usageLeft = $coupon->getUsagesLeft($customerId);
if ($usageLeft > 0) {
$usageLeft--;
$coupon->setMaxUsage($usageLeft);
if ($usageLeft > 0) {
$coupon->save();
$ret = $usageLeft;
}
// If the coupon usage is per user, add an entry to coupon customer usage count table
if ($coupon->getPerCustomerUsageCount()) {
} catch (\Exception $e) {
$ret = false;
if (null == $customerId) {
throw new \LogicException("Customer should not be null at this time.");
}
$ccc = CouponCustomerCountQuery::create()
->filterByCouponId($coupon->getId())
->filterByCustomerId($customerId)
->findOne()
;
if ($ccc === null) {
$ccc = new CouponCustomerCount();
$ccc
->setCustomerId($customerId)
->setCouponId($coupon->getId())
->setCount(0);
}
$newCount = 1 + $ccc->getCount();
$ccc
->setCount($newCount)
->save()
;
$ret = $usageLeft - $newCount;
}
else {
$usageLeft--;
$coupon->setMaxUsage($usageLeft);
$coupon->save();
$ret = $usageLeft;
}
}
} catch (\Exception $ex) {
// Just log the problem.
Tlog::getInstance()->addError(sprintf("Failed to decrement coupon %s: %s", $coupon->getCode(), $ex->getMessage()));
}
return $ret;

View File

@@ -96,6 +96,9 @@ abstract class CouponAbstract implements CouponInterface
/** @var CouponModule[] list of shipping module IDs for which shippiog is free. All if empty*/
protected $freeShippingForModules = [];
/** @var true if usage count is per customer only */
protected $perCustomerUsageCount;
/**
* Constructor
*
@@ -139,7 +142,8 @@ abstract class CouponAbstract implements CouponInterface
$maxUsage,
\DateTime $expirationDate,
$freeShippingForCountries,
$freeShippingForModules
$freeShippingForModules,
$perCustomerUsageCount
)
{
$this->code = $code;
@@ -161,10 +165,29 @@ abstract class CouponAbstract implements CouponInterface
$this->freeShippingForCountries = $freeShippingForCountries;
$this->freeShippingForModules = $freeShippingForModules;
$this->perCustomerUsageCount = $perCustomerUsageCount;
return $this;
}
/**
* @param true $perCustomerUsageCount
*/
public function setPerCustomerUsageCount($perCustomerUsageCount)
{
$this->perCustomerUsageCount = $perCustomerUsageCount;
return $this;
}
/**
* @return true
*/
public function getPerCustomerUsageCount()
{
return $this->perCustomerUsageCount;
}
/**
* Return Coupon code (ex: XMAS)
*

View File

@@ -66,7 +66,7 @@ interface CouponInterface
* @param \Datetime $expirationDate When the Code is expiring
* @param ObjectCollection $freeShippingForCountries list of countries which shipping is free. All if empty
* @param ObjectCollection $freeShippingForModules list of modules for which shipping is free. All if empty
* @param bool $perCustomerUsageCount true if usage count is per customer only
*/
public function set(
FacadeInterface $facade,
@@ -82,7 +82,8 @@ interface CouponInterface
$maxUsage,
\DateTime $expirationDate,
$freeShippingForCountries,
$freeShippingForModules
$freeShippingForModules,
$perCustomerUsageCount
);
/**
@@ -162,6 +163,14 @@ interface CouponInterface
*/
public function isAvailableOnSpecialOffers();
/**
* Check if the Coupon can be used against a
* product already with a special offer price
*
* @return boolean
*/
public function getPerCustomerUsageCount();
/**
* Check if Coupon has been disabled by admin
*

View File

@@ -51,14 +51,16 @@ class RemoveXPercent extends CouponAbstract
$maxUsage,
\DateTime $expirationDate,
$freeShippingForCountries,
$freeShippingForModules
$freeShippingForModules,
$perCustomerUsageCount
)
{
parent::set(
$facade, $code, $title, $shortDescription, $description, $effects,
$isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate,
$freeShippingForCountries,
$freeShippingForModules
$freeShippingForModules,
$perCustomerUsageCount
);
$this->percentage = $effects[self::INPUT_PERCENTAGE_NAME];

View File

@@ -12,6 +12,7 @@
namespace Thelia\Exception;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
/**
@@ -30,7 +31,8 @@ class CouponExpiredException extends \Exception
*/
public function __construct($couponCode)
{
$message = 'Expired Coupon ' . $couponCode . 'attempt';
$message = Translator::getInstance()->trans('Coupon %code is expired.', ['%code' => $couponCode ]);
Tlog::getInstance()->addWarning($message);
parent::__construct($message);

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Exception;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
/**
* Thrown when a Coupon with no usage lect (etiher overall or per customer usage) is tried
*
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class CouponNoUsageLeftException extends \Exception
{
/**
* CouponExpiredException thrown when a Coupon is expired
*
* @param string $couponCode Coupon code
*/
public function __construct($couponCode)
{
$message = Translator::getInstance()->trans('Maximum usage count reached for coupon %code', ['%code' => $couponCode ]);
Tlog::getInstance()->addWarning($message);
parent::__construct($message);
}
}

View File

@@ -181,6 +181,18 @@ class CouponCreationForm extends BaseForm
)
)
)
->add(
'perCustomerUsageCount',
'choice',
array(
'multiple' => false,
'required' => true,
'choices' => [
1 => Translator::getInstance()->trans('Per customer'),
0 => Translator::getInstance()->trans('Overall')
]
)
)
->add(
'locale',
'hidden',

View File

@@ -22,6 +22,8 @@ use Thelia\Model\CountryQuery as ChildCountryQuery;
use Thelia\Model\Coupon as ChildCoupon;
use Thelia\Model\CouponCountry as ChildCouponCountry;
use Thelia\Model\CouponCountryQuery as ChildCouponCountryQuery;
use Thelia\Model\CouponCustomerCount as ChildCouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery as ChildCouponCustomerCountQuery;
use Thelia\Model\CouponI18n as ChildCouponI18n;
use Thelia\Model\CouponI18nQuery as ChildCouponI18nQuery;
use Thelia\Model\CouponModule as ChildCouponModule;
@@ -29,6 +31,8 @@ use Thelia\Model\CouponModuleQuery as ChildCouponModuleQuery;
use Thelia\Model\CouponQuery as ChildCouponQuery;
use Thelia\Model\CouponVersion as ChildCouponVersion;
use Thelia\Model\CouponVersionQuery as ChildCouponVersionQuery;
use Thelia\Model\Customer as ChildCustomer;
use Thelia\Model\CustomerQuery as ChildCustomerQuery;
use Thelia\Model\Module as ChildModule;
use Thelia\Model\ModuleQuery as ChildModuleQuery;
use Thelia\Model\Map\CouponTableMap;
@@ -140,6 +144,12 @@ abstract class Coupon implements ActiveRecordInterface
*/
protected $serialized_conditions;
/**
* The value for the per_customer_usage_count field.
* @var boolean
*/
protected $per_customer_usage_count;
/**
* The value for the created_at field.
* @var string
@@ -171,6 +181,12 @@ abstract class Coupon implements ActiveRecordInterface
protected $collCouponModules;
protected $collCouponModulesPartial;
/**
* @var ObjectCollection|ChildCouponCustomerCount[] Collection to store aggregation of ChildCouponCustomerCount objects.
*/
protected $collCouponCustomerCounts;
protected $collCouponCustomerCountsPartial;
/**
* @var ObjectCollection|ChildCouponI18n[] Collection to store aggregation of ChildCouponI18n objects.
*/
@@ -193,6 +209,11 @@ abstract class Coupon implements ActiveRecordInterface
*/
protected $collModules;
/**
* @var ChildCustomer[] Collection to store aggregation of ChildCustomer objects.
*/
protected $collCustomers;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@@ -235,6 +256,12 @@ abstract class Coupon implements ActiveRecordInterface
*/
protected $modulesScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
*/
protected $customersScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
@@ -247,6 +274,12 @@ abstract class Coupon implements ActiveRecordInterface
*/
protected $couponModulesScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
*/
protected $couponCustomerCountsScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
@@ -671,6 +704,17 @@ abstract class Coupon implements ActiveRecordInterface
return $this->serialized_conditions;
}
/**
* Get the [per_customer_usage_count] column value.
*
* @return boolean
*/
public function getPerCustomerUsageCount()
{
return $this->per_customer_usage_count;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -1014,6 +1058,35 @@ abstract class Coupon implements ActiveRecordInterface
return $this;
} // setSerializedConditions()
/**
* Sets the value of the [per_customer_usage_count] column.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
*
* @param boolean|integer|string $v The new value
* @return \Thelia\Model\Coupon The current object (for fluent API support)
*/
public function setPerCustomerUsageCount($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->per_customer_usage_count !== $v) {
$this->per_customer_usage_count = $v;
$this->modifiedColumns[CouponTableMap::PER_CUSTOMER_USAGE_COUNT] = true;
}
return $this;
} // setPerCustomerUsageCount()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -1157,19 +1230,22 @@ abstract class Coupon implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponTableMap::translateFieldName('SerializedConditions', TableMap::TYPE_PHPNAME, $indexType)];
$this->serialized_conditions = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponTableMap::translateFieldName('PerCustomerUsageCount', TableMap::TYPE_PHPNAME, $indexType)];
$this->per_customer_usage_count = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CouponTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CouponTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CouponTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CouponTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : CouponTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)];
$this->version = (null !== $col) ? (int) $col : null;
$this->resetModified();
@@ -1179,7 +1255,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 15; // 15 = CouponTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 16; // 16 = CouponTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\Coupon object", 0, $e);
@@ -1244,12 +1320,15 @@ abstract class Coupon implements ActiveRecordInterface
$this->collCouponModules = null;
$this->collCouponCustomerCounts = null;
$this->collCouponI18ns = null;
$this->collCouponVersions = null;
$this->collCountries = null;
$this->collModules = null;
$this->collCustomers = null;
} // if (deep)
}
@@ -1446,6 +1525,33 @@ abstract class Coupon implements ActiveRecordInterface
}
}
if ($this->customersScheduledForDeletion !== null) {
if (!$this->customersScheduledForDeletion->isEmpty()) {
$pks = array();
$pk = $this->getPrimaryKey();
foreach ($this->customersScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
$pks[] = array($remotePk, $pk);
}
CouponCustomerCountQuery::create()
->filterByPrimaryKeys($pks)
->delete($con);
$this->customersScheduledForDeletion = null;
}
foreach ($this->getCustomers() as $customer) {
if ($customer->isModified()) {
$customer->save($con);
}
}
} elseif ($this->collCustomers) {
foreach ($this->collCustomers as $customer) {
if ($customer->isModified()) {
$customer->save($con);
}
}
}
if ($this->couponCountriesScheduledForDeletion !== null) {
if (!$this->couponCountriesScheduledForDeletion->isEmpty()) {
\Thelia\Model\CouponCountryQuery::create()
@@ -1480,6 +1586,23 @@ abstract class Coupon implements ActiveRecordInterface
}
}
if ($this->couponCustomerCountsScheduledForDeletion !== null) {
if (!$this->couponCustomerCountsScheduledForDeletion->isEmpty()) {
\Thelia\Model\CouponCustomerCountQuery::create()
->filterByPrimaryKeys($this->couponCustomerCountsScheduledForDeletion->getPrimaryKeys(false))
->delete($con);
$this->couponCustomerCountsScheduledForDeletion = null;
}
}
if ($this->collCouponCustomerCounts !== null) {
foreach ($this->collCouponCustomerCounts as $referrerFK) {
if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->couponI18nsScheduledForDeletion !== null) {
if (!$this->couponI18nsScheduledForDeletion->isEmpty()) {
\Thelia\Model\CouponI18nQuery::create()
@@ -1576,6 +1699,9 @@ abstract class Coupon implements ActiveRecordInterface
if ($this->isColumnModified(CouponTableMap::SERIALIZED_CONDITIONS)) {
$modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
}
if ($this->isColumnModified(CouponTableMap::PER_CUSTOMER_USAGE_COUNT)) {
$modifiedColumns[':p' . $index++] = '`PER_CUSTOMER_USAGE_COUNT`';
}
if ($this->isColumnModified(CouponTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = '`CREATED_AT`';
}
@@ -1632,6 +1758,9 @@ abstract class Coupon implements ActiveRecordInterface
case '`SERIALIZED_CONDITIONS`':
$stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
break;
case '`PER_CUSTOMER_USAGE_COUNT`':
$stmt->bindValue($identifier, (int) $this->per_customer_usage_count, PDO::PARAM_INT);
break;
case '`CREATED_AT`':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1740,12 +1869,15 @@ abstract class Coupon implements ActiveRecordInterface
return $this->getSerializedConditions();
break;
case 12:
return $this->getCreatedAt();
return $this->getPerCustomerUsageCount();
break;
case 13:
return $this->getUpdatedAt();
return $this->getCreatedAt();
break;
case 14:
return $this->getUpdatedAt();
break;
case 15:
return $this->getVersion();
break;
default:
@@ -1789,9 +1921,10 @@ abstract class Coupon implements ActiveRecordInterface
$keys[9] => $this->getIsAvailableOnSpecialOffers(),
$keys[10] => $this->getIsUsed(),
$keys[11] => $this->getSerializedConditions(),
$keys[12] => $this->getCreatedAt(),
$keys[13] => $this->getUpdatedAt(),
$keys[14] => $this->getVersion(),
$keys[12] => $this->getPerCustomerUsageCount(),
$keys[13] => $this->getCreatedAt(),
$keys[14] => $this->getUpdatedAt(),
$keys[15] => $this->getVersion(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@@ -1805,6 +1938,9 @@ abstract class Coupon implements ActiveRecordInterface
if (null !== $this->collCouponModules) {
$result['CouponModules'] = $this->collCouponModules->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
if (null !== $this->collCouponCustomerCounts) {
$result['CouponCustomerCounts'] = $this->collCouponCustomerCounts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
if (null !== $this->collCouponI18ns) {
$result['CouponI18ns'] = $this->collCouponI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
@@ -1882,12 +2018,15 @@ abstract class Coupon implements ActiveRecordInterface
$this->setSerializedConditions($value);
break;
case 12:
$this->setCreatedAt($value);
$this->setPerCustomerUsageCount($value);
break;
case 13:
$this->setUpdatedAt($value);
$this->setCreatedAt($value);
break;
case 14:
$this->setUpdatedAt($value);
break;
case 15:
$this->setVersion($value);
break;
} // switch()
@@ -1926,9 +2065,10 @@ abstract class Coupon implements ActiveRecordInterface
if (array_key_exists($keys[9], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[9]]);
if (array_key_exists($keys[10], $arr)) $this->setIsUsed($arr[$keys[10]]);
if (array_key_exists($keys[11], $arr)) $this->setSerializedConditions($arr[$keys[11]]);
if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]);
if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setVersion($arr[$keys[14]]);
if (array_key_exists($keys[12], $arr)) $this->setPerCustomerUsageCount($arr[$keys[12]]);
if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]);
if (array_key_exists($keys[15], $arr)) $this->setVersion($arr[$keys[15]]);
}
/**
@@ -1952,6 +2092,7 @@ abstract class Coupon implements ActiveRecordInterface
if ($this->isColumnModified(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) $criteria->add(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $this->is_available_on_special_offers);
if ($this->isColumnModified(CouponTableMap::IS_USED)) $criteria->add(CouponTableMap::IS_USED, $this->is_used);
if ($this->isColumnModified(CouponTableMap::SERIALIZED_CONDITIONS)) $criteria->add(CouponTableMap::SERIALIZED_CONDITIONS, $this->serialized_conditions);
if ($this->isColumnModified(CouponTableMap::PER_CUSTOMER_USAGE_COUNT)) $criteria->add(CouponTableMap::PER_CUSTOMER_USAGE_COUNT, $this->per_customer_usage_count);
if ($this->isColumnModified(CouponTableMap::CREATED_AT)) $criteria->add(CouponTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(CouponTableMap::UPDATED_AT)) $criteria->add(CouponTableMap::UPDATED_AT, $this->updated_at);
if ($this->isColumnModified(CouponTableMap::VERSION)) $criteria->add(CouponTableMap::VERSION, $this->version);
@@ -2029,6 +2170,7 @@ abstract class Coupon implements ActiveRecordInterface
$copyObj->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers());
$copyObj->setIsUsed($this->getIsUsed());
$copyObj->setSerializedConditions($this->getSerializedConditions());
$copyObj->setPerCustomerUsageCount($this->getPerCustomerUsageCount());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
$copyObj->setVersion($this->getVersion());
@@ -2050,6 +2192,12 @@ abstract class Coupon implements ActiveRecordInterface
}
}
foreach ($this->getCouponCustomerCounts() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addCouponCustomerCount($relObj->copy($deepCopy));
}
}
foreach ($this->getCouponI18ns() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addCouponI18n($relObj->copy($deepCopy));
@@ -2109,6 +2257,9 @@ abstract class Coupon implements ActiveRecordInterface
if ('CouponModule' == $relationName) {
return $this->initCouponModules();
}
if ('CouponCustomerCount' == $relationName) {
return $this->initCouponCustomerCounts();
}
if ('CouponI18n' == $relationName) {
return $this->initCouponI18ns();
}
@@ -2609,6 +2760,249 @@ abstract class Coupon implements ActiveRecordInterface
return $this->getCouponModules($query, $con);
}
/**
* Clears out the collCouponCustomerCounts collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addCouponCustomerCounts()
*/
public function clearCouponCustomerCounts()
{
$this->collCouponCustomerCounts = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Reset is the collCouponCustomerCounts collection loaded partially.
*/
public function resetPartialCouponCustomerCounts($v = true)
{
$this->collCouponCustomerCountsPartial = $v;
}
/**
* Initializes the collCouponCustomerCounts collection.
*
* By default this just sets the collCouponCustomerCounts collection to an empty array (like clearcollCouponCustomerCounts());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @param boolean $overrideExisting If set to true, the method call initializes
* the collection even if it is not empty
*
* @return void
*/
public function initCouponCustomerCounts($overrideExisting = true)
{
if (null !== $this->collCouponCustomerCounts && !$overrideExisting) {
return;
}
$this->collCouponCustomerCounts = new ObjectCollection();
$this->collCouponCustomerCounts->setModel('\Thelia\Model\CouponCustomerCount');
}
/**
* Gets an array of ChildCouponCustomerCount objects which contain a foreign key that references this object.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this ChildCoupon is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria optional Criteria object to narrow the query
* @param ConnectionInterface $con optional connection object
* @return Collection|ChildCouponCustomerCount[] List of ChildCouponCustomerCount objects
* @throws PropelException
*/
public function getCouponCustomerCounts($criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collCouponCustomerCountsPartial && !$this->isNew();
if (null === $this->collCouponCustomerCounts || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCouponCustomerCounts) {
// return empty collection
$this->initCouponCustomerCounts();
} else {
$collCouponCustomerCounts = ChildCouponCustomerCountQuery::create(null, $criteria)
->filterByCoupon($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collCouponCustomerCountsPartial && count($collCouponCustomerCounts)) {
$this->initCouponCustomerCounts(false);
foreach ($collCouponCustomerCounts as $obj) {
if (false == $this->collCouponCustomerCounts->contains($obj)) {
$this->collCouponCustomerCounts->append($obj);
}
}
$this->collCouponCustomerCountsPartial = true;
}
reset($collCouponCustomerCounts);
return $collCouponCustomerCounts;
}
if ($partial && $this->collCouponCustomerCounts) {
foreach ($this->collCouponCustomerCounts as $obj) {
if ($obj->isNew()) {
$collCouponCustomerCounts[] = $obj;
}
}
}
$this->collCouponCustomerCounts = $collCouponCustomerCounts;
$this->collCouponCustomerCountsPartial = false;
}
}
return $this->collCouponCustomerCounts;
}
/**
* Sets a collection of CouponCustomerCount objects related by a one-to-many relationship
* to the current object.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
*
* @param Collection $couponCustomerCounts A Propel collection.
* @param ConnectionInterface $con Optional connection object
* @return ChildCoupon The current object (for fluent API support)
*/
public function setCouponCustomerCounts(Collection $couponCustomerCounts, ConnectionInterface $con = null)
{
$couponCustomerCountsToDelete = $this->getCouponCustomerCounts(new Criteria(), $con)->diff($couponCustomerCounts);
$this->couponCustomerCountsScheduledForDeletion = $couponCustomerCountsToDelete;
foreach ($couponCustomerCountsToDelete as $couponCustomerCountRemoved) {
$couponCustomerCountRemoved->setCoupon(null);
}
$this->collCouponCustomerCounts = null;
foreach ($couponCustomerCounts as $couponCustomerCount) {
$this->addCouponCustomerCount($couponCustomerCount);
}
$this->collCouponCustomerCounts = $couponCustomerCounts;
$this->collCouponCustomerCountsPartial = false;
return $this;
}
/**
* Returns the number of related CouponCustomerCount objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param ConnectionInterface $con
* @return int Count of related CouponCustomerCount objects.
* @throws PropelException
*/
public function countCouponCustomerCounts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collCouponCustomerCountsPartial && !$this->isNew();
if (null === $this->collCouponCustomerCounts || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCouponCustomerCounts) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getCouponCustomerCounts());
}
$query = ChildCouponCustomerCountQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByCoupon($this)
->count($con);
}
return count($this->collCouponCustomerCounts);
}
/**
* Method called to associate a ChildCouponCustomerCount object to this object
* through the ChildCouponCustomerCount foreign key attribute.
*
* @param ChildCouponCustomerCount $l ChildCouponCustomerCount
* @return \Thelia\Model\Coupon The current object (for fluent API support)
*/
public function addCouponCustomerCount(ChildCouponCustomerCount $l)
{
if ($this->collCouponCustomerCounts === null) {
$this->initCouponCustomerCounts();
$this->collCouponCustomerCountsPartial = true;
}
if (!in_array($l, $this->collCouponCustomerCounts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
$this->doAddCouponCustomerCount($l);
}
return $this;
}
/**
* @param CouponCustomerCount $couponCustomerCount The couponCustomerCount object to add.
*/
protected function doAddCouponCustomerCount($couponCustomerCount)
{
$this->collCouponCustomerCounts[]= $couponCustomerCount;
$couponCustomerCount->setCoupon($this);
}
/**
* @param CouponCustomerCount $couponCustomerCount The couponCustomerCount object to remove.
* @return ChildCoupon The current object (for fluent API support)
*/
public function removeCouponCustomerCount($couponCustomerCount)
{
if ($this->getCouponCustomerCounts()->contains($couponCustomerCount)) {
$this->collCouponCustomerCounts->remove($this->collCouponCustomerCounts->search($couponCustomerCount));
if (null === $this->couponCustomerCountsScheduledForDeletion) {
$this->couponCustomerCountsScheduledForDeletion = clone $this->collCouponCustomerCounts;
$this->couponCustomerCountsScheduledForDeletion->clear();
}
$this->couponCustomerCountsScheduledForDeletion[]= clone $couponCustomerCount;
$couponCustomerCount->setCoupon(null);
}
return $this;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Coupon is new, it will return
* an empty collection; or if this Coupon has previously
* been saved, it will retrieve related CouponCustomerCounts from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in Coupon.
*
* @param Criteria $criteria optional Criteria object to narrow the query
* @param ConnectionInterface $con optional connection object
* @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
* @return Collection|ChildCouponCustomerCount[] List of ChildCouponCustomerCount objects
*/
public function getCouponCustomerCountsJoinCustomer($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
{
$query = ChildCouponCustomerCountQuery::create(null, $criteria);
$query->joinWith('Customer', $joinBehavior);
return $this->getCouponCustomerCounts($query, $con);
}
/**
* Clears out the collCouponI18ns collection
*
@@ -3421,6 +3815,189 @@ abstract class Coupon implements ActiveRecordInterface
return $this;
}
/**
* Clears out the collCustomers collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addCustomers()
*/
public function clearCustomers()
{
$this->collCustomers = null; // important to set this to NULL since that means it is uninitialized
$this->collCustomersPartial = null;
}
/**
* Initializes the collCustomers collection.
*
* By default this just sets the collCustomers collection to an empty collection (like clearCustomers());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initCustomers()
{
$this->collCustomers = new ObjectCollection();
$this->collCustomers->setModel('\Thelia\Model\Customer');
}
/**
* Gets a collection of ChildCustomer objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this ChildCoupon is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria Optional query object to filter the query
* @param ConnectionInterface $con Optional connection object
*
* @return ObjectCollection|ChildCustomer[] List of ChildCustomer objects
*/
public function getCustomers($criteria = null, ConnectionInterface $con = null)
{
if (null === $this->collCustomers || null !== $criteria) {
if ($this->isNew() && null === $this->collCustomers) {
// return empty collection
$this->initCustomers();
} else {
$collCustomers = ChildCustomerQuery::create(null, $criteria)
->filterByCoupon($this)
->find($con);
if (null !== $criteria) {
return $collCustomers;
}
$this->collCustomers = $collCustomers;
}
}
return $this->collCustomers;
}
/**
* Sets a collection of Customer objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
*
* @param Collection $customers A Propel collection.
* @param ConnectionInterface $con Optional connection object
* @return ChildCoupon The current object (for fluent API support)
*/
public function setCustomers(Collection $customers, ConnectionInterface $con = null)
{
$this->clearCustomers();
$currentCustomers = $this->getCustomers();
$this->customersScheduledForDeletion = $currentCustomers->diff($customers);
foreach ($customers as $customer) {
if (!$currentCustomers->contains($customer)) {
$this->doAddCustomer($customer);
}
}
$this->collCustomers = $customers;
return $this;
}
/**
* Gets the number of ChildCustomer objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
*
* @param Criteria $criteria Optional query object to filter the query
* @param boolean $distinct Set to true to force count distinct
* @param ConnectionInterface $con Optional connection object
*
* @return int the number of related ChildCustomer objects
*/
public function countCustomers($criteria = null, $distinct = false, ConnectionInterface $con = null)
{
if (null === $this->collCustomers || null !== $criteria) {
if ($this->isNew() && null === $this->collCustomers) {
return 0;
} else {
$query = ChildCustomerQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByCoupon($this)
->count($con);
}
} else {
return count($this->collCustomers);
}
}
/**
* Associate a ChildCustomer object to this object
* through the coupon_customer_count cross reference table.
*
* @param ChildCustomer $customer The ChildCouponCustomerCount object to relate
* @return ChildCoupon The current object (for fluent API support)
*/
public function addCustomer(ChildCustomer $customer)
{
if ($this->collCustomers === null) {
$this->initCustomers();
}
if (!$this->collCustomers->contains($customer)) { // only add it if the **same** object is not already associated
$this->doAddCustomer($customer);
$this->collCustomers[] = $customer;
}
return $this;
}
/**
* @param Customer $customer The customer object to add.
*/
protected function doAddCustomer($customer)
{
$couponCustomerCount = new ChildCouponCustomerCount();
$couponCustomerCount->setCustomer($customer);
$this->addCouponCustomerCount($couponCustomerCount);
// set the back reference to this object directly as using provided method either results
// in endless loop or in multiple relations
if (!$customer->getCoupons()->contains($this)) {
$foreignCollection = $customer->getCoupons();
$foreignCollection[] = $this;
}
}
/**
* Remove a ChildCustomer object to this object
* through the coupon_customer_count cross reference table.
*
* @param ChildCustomer $customer The ChildCouponCustomerCount object to relate
* @return ChildCoupon The current object (for fluent API support)
*/
public function removeCustomer(ChildCustomer $customer)
{
if ($this->getCustomers()->contains($customer)) {
$this->collCustomers->remove($this->collCustomers->search($customer));
if (null === $this->customersScheduledForDeletion) {
$this->customersScheduledForDeletion = clone $this->collCustomers;
$this->customersScheduledForDeletion->clear();
}
$this->customersScheduledForDeletion[] = $customer;
}
return $this;
}
/**
* Clears the current object and sets all attributes to their default values
*/
@@ -3438,6 +4015,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->is_available_on_special_offers = null;
$this->is_used = null;
$this->serialized_conditions = null;
$this->per_customer_usage_count = null;
$this->created_at = null;
$this->updated_at = null;
$this->version = null;
@@ -3471,6 +4049,11 @@ abstract class Coupon implements ActiveRecordInterface
$o->clearAllReferences($deep);
}
}
if ($this->collCouponCustomerCounts) {
foreach ($this->collCouponCustomerCounts as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collCouponI18ns) {
foreach ($this->collCouponI18ns as $o) {
$o->clearAllReferences($deep);
@@ -3491,6 +4074,11 @@ abstract class Coupon implements ActiveRecordInterface
$o->clearAllReferences($deep);
}
}
if ($this->collCustomers) {
foreach ($this->collCustomers as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
// i18n behavior
@@ -3499,10 +4087,12 @@ abstract class Coupon implements ActiveRecordInterface
$this->collCouponCountries = null;
$this->collCouponModules = null;
$this->collCouponCustomerCounts = null;
$this->collCouponI18ns = null;
$this->collCouponVersions = null;
$this->collCountries = null;
$this->collModules = null;
$this->collCustomers = null;
}
/**
@@ -3760,6 +4350,7 @@ abstract class Coupon implements ActiveRecordInterface
$version->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers());
$version->setIsUsed($this->getIsUsed());
$version->setSerializedConditions($this->getSerializedConditions());
$version->setPerCustomerUsageCount($this->getPerCustomerUsageCount());
$version->setCreatedAt($this->getCreatedAt());
$version->setUpdatedAt($this->getUpdatedAt());
$version->setVersion($this->getVersion());
@@ -3812,6 +4403,7 @@ abstract class Coupon implements ActiveRecordInterface
$this->setIsAvailableOnSpecialOffers($version->getIsAvailableOnSpecialOffers());
$this->setIsUsed($version->getIsUsed());
$this->setSerializedConditions($version->getSerializedConditions());
$this->setPerCustomerUsageCount($version->getPerCustomerUsageCount());
$this->setCreatedAt($version->getCreatedAt());
$this->setUpdatedAt($version->getUpdatedAt());
$this->setVersion($version->getVersion());

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,521 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\CouponCustomerCount as ChildCouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery as ChildCouponCustomerCountQuery;
use Thelia\Model\Map\CouponCustomerCountTableMap;
/**
* Base class that represents a query for the 'coupon_customer_count' table.
*
*
*
* @method ChildCouponCustomerCountQuery orderByCouponId($order = Criteria::ASC) Order by the coupon_id column
* @method ChildCouponCustomerCountQuery orderByCustomerId($order = Criteria::ASC) Order by the customer_id column
* @method ChildCouponCustomerCountQuery orderByCount($order = Criteria::ASC) Order by the count column
*
* @method ChildCouponCustomerCountQuery groupByCouponId() Group by the coupon_id column
* @method ChildCouponCustomerCountQuery groupByCustomerId() Group by the customer_id column
* @method ChildCouponCustomerCountQuery groupByCount() Group by the count column
*
* @method ChildCouponCustomerCountQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildCouponCustomerCountQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildCouponCustomerCountQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildCouponCustomerCountQuery leftJoinCustomer($relationAlias = null) Adds a LEFT JOIN clause to the query using the Customer relation
* @method ChildCouponCustomerCountQuery rightJoinCustomer($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Customer relation
* @method ChildCouponCustomerCountQuery innerJoinCustomer($relationAlias = null) Adds a INNER JOIN clause to the query using the Customer relation
*
* @method ChildCouponCustomerCountQuery leftJoinCoupon($relationAlias = null) Adds a LEFT JOIN clause to the query using the Coupon relation
* @method ChildCouponCustomerCountQuery rightJoinCoupon($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Coupon relation
* @method ChildCouponCustomerCountQuery innerJoinCoupon($relationAlias = null) Adds a INNER JOIN clause to the query using the Coupon relation
*
* @method ChildCouponCustomerCount findOne(ConnectionInterface $con = null) Return the first ChildCouponCustomerCount matching the query
* @method ChildCouponCustomerCount findOneOrCreate(ConnectionInterface $con = null) Return the first ChildCouponCustomerCount matching the query, or a new ChildCouponCustomerCount object populated from the query conditions when no match is found
*
* @method ChildCouponCustomerCount findOneByCouponId(int $coupon_id) Return the first ChildCouponCustomerCount filtered by the coupon_id column
* @method ChildCouponCustomerCount findOneByCustomerId(int $customer_id) Return the first ChildCouponCustomerCount filtered by the customer_id column
* @method ChildCouponCustomerCount findOneByCount(int $count) Return the first ChildCouponCustomerCount filtered by the count column
*
* @method array findByCouponId(int $coupon_id) Return ChildCouponCustomerCount objects filtered by the coupon_id column
* @method array findByCustomerId(int $customer_id) Return ChildCouponCustomerCount objects filtered by the customer_id column
* @method array findByCount(int $count) Return ChildCouponCustomerCount objects filtered by the count column
*
*/
abstract class CouponCustomerCountQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\CouponCustomerCountQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\CouponCustomerCount', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildCouponCustomerCountQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildCouponCustomerCountQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\CouponCustomerCountQuery) {
return $criteria;
}
$query = new \Thelia\Model\CouponCustomerCountQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(12, $con);
* </code>
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildCouponCustomerCount|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
throw new \LogicException('The ChildCouponCustomerCount class has no primary key');
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
throw new \LogicException('The ChildCouponCustomerCount class has no primary key');
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
throw new \LogicException('The ChildCouponCustomerCount class has no primary key');
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
throw new \LogicException('The ChildCouponCustomerCount class has no primary key');
}
/**
* Filter the query on the coupon_id column
*
* Example usage:
* <code>
* $query->filterByCouponId(1234); // WHERE coupon_id = 1234
* $query->filterByCouponId(array(12, 34)); // WHERE coupon_id IN (12, 34)
* $query->filterByCouponId(array('min' => 12)); // WHERE coupon_id > 12
* </code>
*
* @see filterByCoupon()
*
* @param mixed $couponId 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 $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByCouponId($couponId = null, $comparison = null)
{
if (is_array($couponId)) {
$useMinMax = false;
if (isset($couponId['min'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::COUPON_ID, $couponId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($couponId['max'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::COUPON_ID, $couponId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(CouponCustomerCountTableMap::COUPON_ID, $couponId, $comparison);
}
/**
* Filter the query on the customer_id column
*
* Example usage:
* <code>
* $query->filterByCustomerId(1234); // WHERE customer_id = 1234
* $query->filterByCustomerId(array(12, 34)); // WHERE customer_id IN (12, 34)
* $query->filterByCustomerId(array('min' => 12)); // WHERE customer_id > 12
* </code>
*
* @see filterByCustomer()
*
* @param mixed $customerId 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 $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByCustomerId($customerId = null, $comparison = null)
{
if (is_array($customerId)) {
$useMinMax = false;
if (isset($customerId['min'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::CUSTOMER_ID, $customerId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($customerId['max'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::CUSTOMER_ID, $customerId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(CouponCustomerCountTableMap::CUSTOMER_ID, $customerId, $comparison);
}
/**
* Filter the query on the count column
*
* Example usage:
* <code>
* $query->filterByCount(1234); // WHERE count = 1234
* $query->filterByCount(array(12, 34)); // WHERE count IN (12, 34)
* $query->filterByCount(array('min' => 12)); // WHERE count > 12
* </code>
*
* @param mixed $count 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 $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByCount($count = null, $comparison = null)
{
if (is_array($count)) {
$useMinMax = false;
if (isset($count['min'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::COUNT, $count['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($count['max'])) {
$this->addUsingAlias(CouponCustomerCountTableMap::COUNT, $count['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(CouponCustomerCountTableMap::COUNT, $count, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\Customer object
*
* @param \Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByCustomer($customer, $comparison = null)
{
if ($customer instanceof \Thelia\Model\Customer) {
return $this
->addUsingAlias(CouponCustomerCountTableMap::CUSTOMER_ID, $customer->getId(), $comparison);
} elseif ($customer instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(CouponCustomerCountTableMap::CUSTOMER_ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByCustomer() only accepts arguments of type \Thelia\Model\Customer or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Customer relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function joinCustomer($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Customer');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Customer');
}
return $this;
}
/**
* Use the Customer relation Customer object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\CustomerQuery A secondary query class using the current class as primary query
*/
public function useCustomerQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinCustomer($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Customer', '\Thelia\Model\CustomerQuery');
}
/**
* Filter the query by a related \Thelia\Model\Coupon object
*
* @param \Thelia\Model\Coupon|ObjectCollection $coupon The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function filterByCoupon($coupon, $comparison = null)
{
if ($coupon instanceof \Thelia\Model\Coupon) {
return $this
->addUsingAlias(CouponCustomerCountTableMap::COUPON_ID, $coupon->getId(), $comparison);
} elseif ($coupon instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(CouponCustomerCountTableMap::COUPON_ID, $coupon->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByCoupon() only accepts arguments of type \Thelia\Model\Coupon or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Coupon relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function joinCoupon($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Coupon');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Coupon');
}
return $this;
}
/**
* Use the Coupon relation Coupon object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\CouponQuery A secondary query class using the current class as primary query
*/
public function useCouponQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinCoupon($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Coupon', '\Thelia\Model\CouponQuery');
}
/**
* Exclude object from result
*
* @param ChildCouponCustomerCount $couponCustomerCount Object to remove from the list of results
*
* @return ChildCouponCustomerCountQuery The current query, for fluid interface
*/
public function prune($couponCustomerCount = null)
{
if ($couponCustomerCount) {
throw new \LogicException('ChildCouponCustomerCount class has no primary key');
}
return $this;
}
/**
* Deletes all rows from the coupon_customer_count table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CouponCustomerCountTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
CouponCustomerCountTableMap::clearInstancePool();
CouponCustomerCountTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildCouponCustomerCount or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildCouponCustomerCount object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CouponCustomerCountTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(CouponCustomerCountTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
CouponCustomerCountTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
CouponCustomerCountTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // CouponCustomerCountQuery

View File

@@ -34,6 +34,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCouponQuery orderByIsAvailableOnSpecialOffers($order = Criteria::ASC) Order by the is_available_on_special_offers column
* @method ChildCouponQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column
* @method ChildCouponQuery orderBySerializedConditions($order = Criteria::ASC) Order by the serialized_conditions column
* @method ChildCouponQuery orderByPerCustomerUsageCount($order = Criteria::ASC) Order by the per_customer_usage_count column
* @method ChildCouponQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildCouponQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
* @method ChildCouponQuery orderByVersion($order = Criteria::ASC) Order by the version column
@@ -50,6 +51,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCouponQuery groupByIsAvailableOnSpecialOffers() Group by the is_available_on_special_offers column
* @method ChildCouponQuery groupByIsUsed() Group by the is_used column
* @method ChildCouponQuery groupBySerializedConditions() Group by the serialized_conditions column
* @method ChildCouponQuery groupByPerCustomerUsageCount() Group by the per_customer_usage_count column
* @method ChildCouponQuery groupByCreatedAt() Group by the created_at column
* @method ChildCouponQuery groupByUpdatedAt() Group by the updated_at column
* @method ChildCouponQuery groupByVersion() Group by the version column
@@ -66,6 +68,10 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCouponQuery rightJoinCouponModule($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponModule relation
* @method ChildCouponQuery innerJoinCouponModule($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponModule relation
*
* @method ChildCouponQuery leftJoinCouponCustomerCount($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponCustomerCount relation
* @method ChildCouponQuery rightJoinCouponCustomerCount($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponCustomerCount relation
* @method ChildCouponQuery innerJoinCouponCustomerCount($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponCustomerCount relation
*
* @method ChildCouponQuery leftJoinCouponI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponI18n relation
* @method ChildCouponQuery rightJoinCouponI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponI18n relation
* @method ChildCouponQuery innerJoinCouponI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponI18n relation
@@ -89,6 +95,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method ChildCoupon findOneByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return the first ChildCoupon filtered by the is_available_on_special_offers column
* @method ChildCoupon findOneByIsUsed(boolean $is_used) Return the first ChildCoupon filtered by the is_used column
* @method ChildCoupon findOneBySerializedConditions(string $serialized_conditions) Return the first ChildCoupon filtered by the serialized_conditions column
* @method ChildCoupon findOneByPerCustomerUsageCount(boolean $per_customer_usage_count) Return the first ChildCoupon filtered by the per_customer_usage_count column
* @method ChildCoupon findOneByCreatedAt(string $created_at) Return the first ChildCoupon filtered by the created_at column
* @method ChildCoupon findOneByUpdatedAt(string $updated_at) Return the first ChildCoupon filtered by the updated_at column
* @method ChildCoupon findOneByVersion(int $version) Return the first ChildCoupon filtered by the version column
@@ -105,6 +112,7 @@ use Thelia\Model\Map\CouponTableMap;
* @method array findByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return ChildCoupon objects filtered by the is_available_on_special_offers column
* @method array findByIsUsed(boolean $is_used) Return ChildCoupon objects filtered by the is_used column
* @method array findBySerializedConditions(string $serialized_conditions) Return ChildCoupon objects filtered by the serialized_conditions column
* @method array findByPerCustomerUsageCount(boolean $per_customer_usage_count) Return ChildCoupon objects filtered by the per_customer_usage_count column
* @method array findByCreatedAt(string $created_at) Return ChildCoupon objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildCoupon objects filtered by the updated_at column
* @method array findByVersion(int $version) Return ChildCoupon objects filtered by the version column
@@ -203,7 +211,7 @@ abstract class CouponQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$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';
$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`, `PER_CUSTOMER_USAGE_COUNT`, `CREATED_AT`, `UPDATED_AT`, `VERSION` FROM `coupon` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -668,6 +676,33 @@ abstract class CouponQuery extends ModelCriteria
return $this->addUsingAlias(CouponTableMap::SERIALIZED_CONDITIONS, $serializedConditions, $comparison);
}
/**
* Filter the query on the per_customer_usage_count column
*
* Example usage:
* <code>
* $query->filterByPerCustomerUsageCount(true); // WHERE per_customer_usage_count = true
* $query->filterByPerCustomerUsageCount('yes'); // WHERE per_customer_usage_count = true
* </code>
*
* @param boolean|string $perCustomerUsageCount The value to use as filter.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponQuery The current query, for fluid interface
*/
public function filterByPerCustomerUsageCount($perCustomerUsageCount = null, $comparison = null)
{
if (is_string($perCustomerUsageCount)) {
$per_customer_usage_count = in_array(strtolower($perCustomerUsageCount), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}
return $this->addUsingAlias(CouponTableMap::PER_CUSTOMER_USAGE_COUNT, $perCustomerUsageCount, $comparison);
}
/**
* Filter the query on the created_at column
*
@@ -941,6 +976,79 @@ abstract class CouponQuery extends ModelCriteria
->useQuery($relationAlias ? $relationAlias : 'CouponModule', '\Thelia\Model\CouponModuleQuery');
}
/**
* Filter the query by a related \Thelia\Model\CouponCustomerCount object
*
* @param \Thelia\Model\CouponCustomerCount|ObjectCollection $couponCustomerCount the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponQuery The current query, for fluid interface
*/
public function filterByCouponCustomerCount($couponCustomerCount, $comparison = null)
{
if ($couponCustomerCount instanceof \Thelia\Model\CouponCustomerCount) {
return $this
->addUsingAlias(CouponTableMap::ID, $couponCustomerCount->getCouponId(), $comparison);
} elseif ($couponCustomerCount instanceof ObjectCollection) {
return $this
->useCouponCustomerCountQuery()
->filterByPrimaryKeys($couponCustomerCount->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByCouponCustomerCount() only accepts arguments of type \Thelia\Model\CouponCustomerCount or Collection');
}
}
/**
* Adds a JOIN clause to the query using the CouponCustomerCount relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildCouponQuery The current query, for fluid interface
*/
public function joinCouponCustomerCount($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('CouponCustomerCount');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'CouponCustomerCount');
}
return $this;
}
/**
* Use the CouponCustomerCount relation CouponCustomerCount object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\CouponCustomerCountQuery A secondary query class using the current class as primary query
*/
public function useCouponCustomerCountQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinCouponCustomerCount($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'CouponCustomerCount', '\Thelia\Model\CouponCustomerCountQuery');
}
/**
* Filter the query by a related \Thelia\Model\CouponI18n object
*
@@ -1121,6 +1229,23 @@ abstract class CouponQuery extends ModelCriteria
->endUse();
}
/**
* Filter the query by a related Customer object
* using the coupon_customer_count table as cross reference
*
* @param Customer $customer the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponQuery The current query, for fluid interface
*/
public function filterByCustomer($customer, $comparison = Criteria::EQUAL)
{
return $this
->useCouponCustomerCountQuery()
->filterByCustomer($customer, $comparison)
->endUse();
}
/**
* Exclude object from result
*

View File

@@ -127,6 +127,12 @@ abstract class CouponVersion implements ActiveRecordInterface
*/
protected $serialized_conditions;
/**
* The value for the per_customer_usage_count field.
* @var boolean
*/
protected $per_customer_usage_count;
/**
* The value for the created_at field.
* @var string
@@ -571,6 +577,17 @@ abstract class CouponVersion implements ActiveRecordInterface
return $this->serialized_conditions;
}
/**
* Get the [per_customer_usage_count] column value.
*
* @return boolean
*/
public function getPerCustomerUsageCount()
{
return $this->per_customer_usage_count;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -918,6 +935,35 @@ abstract class CouponVersion implements ActiveRecordInterface
return $this;
} // setSerializedConditions()
/**
* Sets the value of the [per_customer_usage_count] column.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
*
* @param boolean|integer|string $v The new value
* @return \Thelia\Model\CouponVersion The current object (for fluent API support)
*/
public function setPerCustomerUsageCount($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->per_customer_usage_count !== $v) {
$this->per_customer_usage_count = $v;
$this->modifiedColumns[CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT] = true;
}
return $this;
} // setPerCustomerUsageCount()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -1061,19 +1107,22 @@ abstract class CouponVersion implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponVersionTableMap::translateFieldName('SerializedConditions', TableMap::TYPE_PHPNAME, $indexType)];
$this->serialized_conditions = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponVersionTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponVersionTableMap::translateFieldName('PerCustomerUsageCount', TableMap::TYPE_PHPNAME, $indexType)];
$this->per_customer_usage_count = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CouponVersionTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CouponVersionTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CouponVersionTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CouponVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : CouponVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)];
$this->version = (null !== $col) ? (int) $col : null;
$this->resetModified();
@@ -1083,7 +1132,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 15; // 15 = CouponVersionTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 16; // 16 = CouponVersionTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\CouponVersion object", 0, $e);
@@ -1340,6 +1389,9 @@ abstract class CouponVersion implements ActiveRecordInterface
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) {
$modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
}
if ($this->isColumnModified(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT)) {
$modifiedColumns[':p' . $index++] = '`PER_CUSTOMER_USAGE_COUNT`';
}
if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = '`CREATED_AT`';
}
@@ -1396,6 +1448,9 @@ abstract class CouponVersion implements ActiveRecordInterface
case '`SERIALIZED_CONDITIONS`':
$stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
break;
case '`PER_CUSTOMER_USAGE_COUNT`':
$stmt->bindValue($identifier, (int) $this->per_customer_usage_count, PDO::PARAM_INT);
break;
case '`CREATED_AT`':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1497,12 +1552,15 @@ abstract class CouponVersion implements ActiveRecordInterface
return $this->getSerializedConditions();
break;
case 12:
return $this->getCreatedAt();
return $this->getPerCustomerUsageCount();
break;
case 13:
return $this->getUpdatedAt();
return $this->getCreatedAt();
break;
case 14:
return $this->getUpdatedAt();
break;
case 15:
return $this->getVersion();
break;
default:
@@ -1546,9 +1604,10 @@ abstract class CouponVersion implements ActiveRecordInterface
$keys[9] => $this->getIsAvailableOnSpecialOffers(),
$keys[10] => $this->getIsUsed(),
$keys[11] => $this->getSerializedConditions(),
$keys[12] => $this->getCreatedAt(),
$keys[13] => $this->getUpdatedAt(),
$keys[14] => $this->getVersion(),
$keys[12] => $this->getPerCustomerUsageCount(),
$keys[13] => $this->getCreatedAt(),
$keys[14] => $this->getUpdatedAt(),
$keys[15] => $this->getVersion(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@@ -1630,12 +1689,15 @@ abstract class CouponVersion implements ActiveRecordInterface
$this->setSerializedConditions($value);
break;
case 12:
$this->setCreatedAt($value);
$this->setPerCustomerUsageCount($value);
break;
case 13:
$this->setUpdatedAt($value);
$this->setCreatedAt($value);
break;
case 14:
$this->setUpdatedAt($value);
break;
case 15:
$this->setVersion($value);
break;
} // switch()
@@ -1674,9 +1736,10 @@ abstract class CouponVersion implements ActiveRecordInterface
if (array_key_exists($keys[9], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[9]]);
if (array_key_exists($keys[10], $arr)) $this->setIsUsed($arr[$keys[10]]);
if (array_key_exists($keys[11], $arr)) $this->setSerializedConditions($arr[$keys[11]]);
if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]);
if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setVersion($arr[$keys[14]]);
if (array_key_exists($keys[12], $arr)) $this->setPerCustomerUsageCount($arr[$keys[12]]);
if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]);
if (array_key_exists($keys[15], $arr)) $this->setVersion($arr[$keys[15]]);
}
/**
@@ -1700,6 +1763,7 @@ abstract class CouponVersion implements ActiveRecordInterface
if ($this->isColumnModified(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) $criteria->add(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $this->is_available_on_special_offers);
if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) $criteria->add(CouponVersionTableMap::IS_USED, $this->is_used);
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) $criteria->add(CouponVersionTableMap::SERIALIZED_CONDITIONS, $this->serialized_conditions);
if ($this->isColumnModified(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT)) $criteria->add(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT, $this->per_customer_usage_count);
if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) $criteria->add(CouponVersionTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(CouponVersionTableMap::UPDATED_AT)) $criteria->add(CouponVersionTableMap::UPDATED_AT, $this->updated_at);
if ($this->isColumnModified(CouponVersionTableMap::VERSION)) $criteria->add(CouponVersionTableMap::VERSION, $this->version);
@@ -1785,6 +1849,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$copyObj->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers());
$copyObj->setIsUsed($this->getIsUsed());
$copyObj->setSerializedConditions($this->getSerializedConditions());
$copyObj->setPerCustomerUsageCount($this->getPerCustomerUsageCount());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
$copyObj->setVersion($this->getVersion());
@@ -1883,6 +1948,7 @@ abstract class CouponVersion implements ActiveRecordInterface
$this->is_available_on_special_offers = null;
$this->is_used = null;
$this->serialized_conditions = null;
$this->per_customer_usage_count = null;
$this->created_at = null;
$this->updated_at = null;
$this->version = null;

View File

@@ -33,6 +33,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersionQuery orderByIsAvailableOnSpecialOffers($order = Criteria::ASC) Order by the is_available_on_special_offers column
* @method ChildCouponVersionQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column
* @method ChildCouponVersionQuery orderBySerializedConditions($order = Criteria::ASC) Order by the serialized_conditions column
* @method ChildCouponVersionQuery orderByPerCustomerUsageCount($order = Criteria::ASC) Order by the per_customer_usage_count column
* @method ChildCouponVersionQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildCouponVersionQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
* @method ChildCouponVersionQuery orderByVersion($order = Criteria::ASC) Order by the version column
@@ -49,6 +50,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersionQuery groupByIsAvailableOnSpecialOffers() Group by the is_available_on_special_offers column
* @method ChildCouponVersionQuery groupByIsUsed() Group by the is_used column
* @method ChildCouponVersionQuery groupBySerializedConditions() Group by the serialized_conditions column
* @method ChildCouponVersionQuery groupByPerCustomerUsageCount() Group by the per_customer_usage_count column
* @method ChildCouponVersionQuery groupByCreatedAt() Group by the created_at column
* @method ChildCouponVersionQuery groupByUpdatedAt() Group by the updated_at column
* @method ChildCouponVersionQuery groupByVersion() Group by the version column
@@ -76,6 +78,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method ChildCouponVersion findOneByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return the first ChildCouponVersion filtered by the is_available_on_special_offers column
* @method ChildCouponVersion findOneByIsUsed(boolean $is_used) Return the first ChildCouponVersion filtered by the is_used column
* @method ChildCouponVersion findOneBySerializedConditions(string $serialized_conditions) Return the first ChildCouponVersion filtered by the serialized_conditions column
* @method ChildCouponVersion findOneByPerCustomerUsageCount(boolean $per_customer_usage_count) Return the first ChildCouponVersion filtered by the per_customer_usage_count column
* @method ChildCouponVersion findOneByCreatedAt(string $created_at) Return the first ChildCouponVersion filtered by the created_at column
* @method ChildCouponVersion findOneByUpdatedAt(string $updated_at) Return the first ChildCouponVersion filtered by the updated_at column
* @method ChildCouponVersion findOneByVersion(int $version) Return the first ChildCouponVersion filtered by the version column
@@ -92,6 +95,7 @@ use Thelia\Model\Map\CouponVersionTableMap;
* @method array findByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return ChildCouponVersion objects filtered by the is_available_on_special_offers column
* @method array findByIsUsed(boolean $is_used) Return ChildCouponVersion objects filtered by the is_used column
* @method array findBySerializedConditions(string $serialized_conditions) Return ChildCouponVersion objects filtered by the serialized_conditions column
* @method array findByPerCustomerUsageCount(boolean $per_customer_usage_count) Return ChildCouponVersion objects filtered by the per_customer_usage_count column
* @method array findByCreatedAt(string $created_at) Return ChildCouponVersion objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildCouponVersion objects filtered by the updated_at column
* @method array findByVersion(int $version) Return ChildCouponVersion objects filtered by the version column
@@ -183,7 +187,7 @@ abstract class CouponVersionQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$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';
$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`, `PER_CUSTOMER_USAGE_COUNT`, `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);
@@ -662,6 +666,33 @@ abstract class CouponVersionQuery extends ModelCriteria
return $this->addUsingAlias(CouponVersionTableMap::SERIALIZED_CONDITIONS, $serializedConditions, $comparison);
}
/**
* Filter the query on the per_customer_usage_count column
*
* Example usage:
* <code>
* $query->filterByPerCustomerUsageCount(true); // WHERE per_customer_usage_count = true
* $query->filterByPerCustomerUsageCount('yes'); // WHERE per_customer_usage_count = true
* </code>
*
* @param boolean|string $perCustomerUsageCount The value to use as filter.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCouponVersionQuery The current query, for fluid interface
*/
public function filterByPerCustomerUsageCount($perCustomerUsageCount = null, $comparison = null)
{
if (is_string($perCustomerUsageCount)) {
$per_customer_usage_count = in_array(strtolower($perCustomerUsageCount), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}
return $this->addUsingAlias(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT, $perCustomerUsageCount, $comparison);
}
/**
* Filter the query on the created_at column
*

View File

@@ -21,6 +21,10 @@ use Thelia\Model\Address as ChildAddress;
use Thelia\Model\AddressQuery as ChildAddressQuery;
use Thelia\Model\Cart as ChildCart;
use Thelia\Model\CartQuery as ChildCartQuery;
use Thelia\Model\Coupon as ChildCoupon;
use Thelia\Model\CouponCustomerCount as ChildCouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery as ChildCouponCustomerCountQuery;
use Thelia\Model\CouponQuery as ChildCouponQuery;
use Thelia\Model\Customer as ChildCustomer;
use Thelia\Model\CustomerQuery as ChildCustomerQuery;
use Thelia\Model\CustomerTitle as ChildCustomerTitle;
@@ -182,6 +186,17 @@ abstract class Customer implements ActiveRecordInterface
protected $collCarts;
protected $collCartsPartial;
/**
* @var ObjectCollection|ChildCouponCustomerCount[] Collection to store aggregation of ChildCouponCustomerCount objects.
*/
protected $collCouponCustomerCounts;
protected $collCouponCustomerCountsPartial;
/**
* @var ChildCoupon[] Collection to store aggregation of ChildCoupon objects.
*/
protected $collCoupons;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@@ -190,6 +205,12 @@ abstract class Customer implements ActiveRecordInterface
*/
protected $alreadyInSave = false;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
*/
protected $couponsScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
@@ -208,6 +229,12 @@ abstract class Customer implements ActiveRecordInterface
*/
protected $cartsScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection
*/
protected $couponCustomerCountsScheduledForDeletion = null;
/**
* Initializes internal state of Thelia\Model\Base\Customer object.
*/
@@ -1169,6 +1196,9 @@ abstract class Customer implements ActiveRecordInterface
$this->collCarts = null;
$this->collCouponCustomerCounts = null;
$this->collCoupons = null;
} // if (deep)
}
@@ -1314,6 +1344,33 @@ abstract class Customer implements ActiveRecordInterface
$this->resetModified();
}
if ($this->couponsScheduledForDeletion !== null) {
if (!$this->couponsScheduledForDeletion->isEmpty()) {
$pks = array();
$pk = $this->getPrimaryKey();
foreach ($this->couponsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
$pks[] = array($pk, $remotePk);
}
CouponCustomerCountQuery::create()
->filterByPrimaryKeys($pks)
->delete($con);
$this->couponsScheduledForDeletion = null;
}
foreach ($this->getCoupons() as $coupon) {
if ($coupon->isModified()) {
$coupon->save($con);
}
}
} elseif ($this->collCoupons) {
foreach ($this->collCoupons as $coupon) {
if ($coupon->isModified()) {
$coupon->save($con);
}
}
}
if ($this->addressesScheduledForDeletion !== null) {
if (!$this->addressesScheduledForDeletion->isEmpty()) {
\Thelia\Model\AddressQuery::create()
@@ -1365,6 +1422,23 @@ abstract class Customer implements ActiveRecordInterface
}
}
if ($this->couponCustomerCountsScheduledForDeletion !== null) {
if (!$this->couponCustomerCountsScheduledForDeletion->isEmpty()) {
\Thelia\Model\CouponCustomerCountQuery::create()
->filterByPrimaryKeys($this->couponCustomerCountsScheduledForDeletion->getPrimaryKeys(false))
->delete($con);
$this->couponCustomerCountsScheduledForDeletion = null;
}
}
if ($this->collCouponCustomerCounts !== null) {
foreach ($this->collCouponCustomerCounts as $referrerFK) {
if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
@@ -1672,6 +1746,9 @@ abstract class Customer implements ActiveRecordInterface
if (null !== $this->collCarts) {
$result['Carts'] = $this->collCarts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
if (null !== $this->collCouponCustomerCounts) {
$result['CouponCustomerCounts'] = $this->collCouponCustomerCounts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
}
return $result;
@@ -1923,6 +2000,12 @@ abstract class Customer implements ActiveRecordInterface
}
}
foreach ($this->getCouponCustomerCounts() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addCouponCustomerCount($relObj->copy($deepCopy));
}
}
} // if ($deepCopy)
if ($makeNew) {
@@ -2024,6 +2107,9 @@ abstract class Customer implements ActiveRecordInterface
if ('Cart' == $relationName) {
return $this->initCarts();
}
if ('CouponCustomerCount' == $relationName) {
return $this->initCouponCustomerCounts();
}
}
/**
@@ -2980,6 +3066,432 @@ abstract class Customer implements ActiveRecordInterface
return $this->getCarts($query, $con);
}
/**
* Clears out the collCouponCustomerCounts collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addCouponCustomerCounts()
*/
public function clearCouponCustomerCounts()
{
$this->collCouponCustomerCounts = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Reset is the collCouponCustomerCounts collection loaded partially.
*/
public function resetPartialCouponCustomerCounts($v = true)
{
$this->collCouponCustomerCountsPartial = $v;
}
/**
* Initializes the collCouponCustomerCounts collection.
*
* By default this just sets the collCouponCustomerCounts collection to an empty array (like clearcollCouponCustomerCounts());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @param boolean $overrideExisting If set to true, the method call initializes
* the collection even if it is not empty
*
* @return void
*/
public function initCouponCustomerCounts($overrideExisting = true)
{
if (null !== $this->collCouponCustomerCounts && !$overrideExisting) {
return;
}
$this->collCouponCustomerCounts = new ObjectCollection();
$this->collCouponCustomerCounts->setModel('\Thelia\Model\CouponCustomerCount');
}
/**
* Gets an array of ChildCouponCustomerCount objects which contain a foreign key that references this object.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this ChildCustomer is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria optional Criteria object to narrow the query
* @param ConnectionInterface $con optional connection object
* @return Collection|ChildCouponCustomerCount[] List of ChildCouponCustomerCount objects
* @throws PropelException
*/
public function getCouponCustomerCounts($criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collCouponCustomerCountsPartial && !$this->isNew();
if (null === $this->collCouponCustomerCounts || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCouponCustomerCounts) {
// return empty collection
$this->initCouponCustomerCounts();
} else {
$collCouponCustomerCounts = ChildCouponCustomerCountQuery::create(null, $criteria)
->filterByCustomer($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collCouponCustomerCountsPartial && count($collCouponCustomerCounts)) {
$this->initCouponCustomerCounts(false);
foreach ($collCouponCustomerCounts as $obj) {
if (false == $this->collCouponCustomerCounts->contains($obj)) {
$this->collCouponCustomerCounts->append($obj);
}
}
$this->collCouponCustomerCountsPartial = true;
}
reset($collCouponCustomerCounts);
return $collCouponCustomerCounts;
}
if ($partial && $this->collCouponCustomerCounts) {
foreach ($this->collCouponCustomerCounts as $obj) {
if ($obj->isNew()) {
$collCouponCustomerCounts[] = $obj;
}
}
}
$this->collCouponCustomerCounts = $collCouponCustomerCounts;
$this->collCouponCustomerCountsPartial = false;
}
}
return $this->collCouponCustomerCounts;
}
/**
* Sets a collection of CouponCustomerCount objects related by a one-to-many relationship
* to the current object.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
*
* @param Collection $couponCustomerCounts A Propel collection.
* @param ConnectionInterface $con Optional connection object
* @return ChildCustomer The current object (for fluent API support)
*/
public function setCouponCustomerCounts(Collection $couponCustomerCounts, ConnectionInterface $con = null)
{
$couponCustomerCountsToDelete = $this->getCouponCustomerCounts(new Criteria(), $con)->diff($couponCustomerCounts);
$this->couponCustomerCountsScheduledForDeletion = $couponCustomerCountsToDelete;
foreach ($couponCustomerCountsToDelete as $couponCustomerCountRemoved) {
$couponCustomerCountRemoved->setCustomer(null);
}
$this->collCouponCustomerCounts = null;
foreach ($couponCustomerCounts as $couponCustomerCount) {
$this->addCouponCustomerCount($couponCustomerCount);
}
$this->collCouponCustomerCounts = $couponCustomerCounts;
$this->collCouponCustomerCountsPartial = false;
return $this;
}
/**
* Returns the number of related CouponCustomerCount objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param ConnectionInterface $con
* @return int Count of related CouponCustomerCount objects.
* @throws PropelException
*/
public function countCouponCustomerCounts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collCouponCustomerCountsPartial && !$this->isNew();
if (null === $this->collCouponCustomerCounts || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCouponCustomerCounts) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getCouponCustomerCounts());
}
$query = ChildCouponCustomerCountQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByCustomer($this)
->count($con);
}
return count($this->collCouponCustomerCounts);
}
/**
* Method called to associate a ChildCouponCustomerCount object to this object
* through the ChildCouponCustomerCount foreign key attribute.
*
* @param ChildCouponCustomerCount $l ChildCouponCustomerCount
* @return \Thelia\Model\Customer The current object (for fluent API support)
*/
public function addCouponCustomerCount(ChildCouponCustomerCount $l)
{
if ($this->collCouponCustomerCounts === null) {
$this->initCouponCustomerCounts();
$this->collCouponCustomerCountsPartial = true;
}
if (!in_array($l, $this->collCouponCustomerCounts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
$this->doAddCouponCustomerCount($l);
}
return $this;
}
/**
* @param CouponCustomerCount $couponCustomerCount The couponCustomerCount object to add.
*/
protected function doAddCouponCustomerCount($couponCustomerCount)
{
$this->collCouponCustomerCounts[]= $couponCustomerCount;
$couponCustomerCount->setCustomer($this);
}
/**
* @param CouponCustomerCount $couponCustomerCount The couponCustomerCount object to remove.
* @return ChildCustomer The current object (for fluent API support)
*/
public function removeCouponCustomerCount($couponCustomerCount)
{
if ($this->getCouponCustomerCounts()->contains($couponCustomerCount)) {
$this->collCouponCustomerCounts->remove($this->collCouponCustomerCounts->search($couponCustomerCount));
if (null === $this->couponCustomerCountsScheduledForDeletion) {
$this->couponCustomerCountsScheduledForDeletion = clone $this->collCouponCustomerCounts;
$this->couponCustomerCountsScheduledForDeletion->clear();
}
$this->couponCustomerCountsScheduledForDeletion[]= clone $couponCustomerCount;
$couponCustomerCount->setCustomer(null);
}
return $this;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Customer is new, it will return
* an empty collection; or if this Customer has previously
* been saved, it will retrieve related CouponCustomerCounts from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in Customer.
*
* @param Criteria $criteria optional Criteria object to narrow the query
* @param ConnectionInterface $con optional connection object
* @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
* @return Collection|ChildCouponCustomerCount[] List of ChildCouponCustomerCount objects
*/
public function getCouponCustomerCountsJoinCoupon($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
{
$query = ChildCouponCustomerCountQuery::create(null, $criteria);
$query->joinWith('Coupon', $joinBehavior);
return $this->getCouponCustomerCounts($query, $con);
}
/**
* Clears out the collCoupons collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addCoupons()
*/
public function clearCoupons()
{
$this->collCoupons = null; // important to set this to NULL since that means it is uninitialized
$this->collCouponsPartial = null;
}
/**
* Initializes the collCoupons collection.
*
* By default this just sets the collCoupons collection to an empty collection (like clearCoupons());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initCoupons()
{
$this->collCoupons = new ObjectCollection();
$this->collCoupons->setModel('\Thelia\Model\Coupon');
}
/**
* Gets a collection of ChildCoupon objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this ChildCustomer is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria Optional query object to filter the query
* @param ConnectionInterface $con Optional connection object
*
* @return ObjectCollection|ChildCoupon[] List of ChildCoupon objects
*/
public function getCoupons($criteria = null, ConnectionInterface $con = null)
{
if (null === $this->collCoupons || null !== $criteria) {
if ($this->isNew() && null === $this->collCoupons) {
// return empty collection
$this->initCoupons();
} else {
$collCoupons = ChildCouponQuery::create(null, $criteria)
->filterByCustomer($this)
->find($con);
if (null !== $criteria) {
return $collCoupons;
}
$this->collCoupons = $collCoupons;
}
}
return $this->collCoupons;
}
/**
* Sets a collection of Coupon objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
*
* @param Collection $coupons A Propel collection.
* @param ConnectionInterface $con Optional connection object
* @return ChildCustomer The current object (for fluent API support)
*/
public function setCoupons(Collection $coupons, ConnectionInterface $con = null)
{
$this->clearCoupons();
$currentCoupons = $this->getCoupons();
$this->couponsScheduledForDeletion = $currentCoupons->diff($coupons);
foreach ($coupons as $coupon) {
if (!$currentCoupons->contains($coupon)) {
$this->doAddCoupon($coupon);
}
}
$this->collCoupons = $coupons;
return $this;
}
/**
* Gets the number of ChildCoupon objects related by a many-to-many relationship
* to the current object by way of the coupon_customer_count cross-reference table.
*
* @param Criteria $criteria Optional query object to filter the query
* @param boolean $distinct Set to true to force count distinct
* @param ConnectionInterface $con Optional connection object
*
* @return int the number of related ChildCoupon objects
*/
public function countCoupons($criteria = null, $distinct = false, ConnectionInterface $con = null)
{
if (null === $this->collCoupons || null !== $criteria) {
if ($this->isNew() && null === $this->collCoupons) {
return 0;
} else {
$query = ChildCouponQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByCustomer($this)
->count($con);
}
} else {
return count($this->collCoupons);
}
}
/**
* Associate a ChildCoupon object to this object
* through the coupon_customer_count cross reference table.
*
* @param ChildCoupon $coupon The ChildCouponCustomerCount object to relate
* @return ChildCustomer The current object (for fluent API support)
*/
public function addCoupon(ChildCoupon $coupon)
{
if ($this->collCoupons === null) {
$this->initCoupons();
}
if (!$this->collCoupons->contains($coupon)) { // only add it if the **same** object is not already associated
$this->doAddCoupon($coupon);
$this->collCoupons[] = $coupon;
}
return $this;
}
/**
* @param Coupon $coupon The coupon object to add.
*/
protected function doAddCoupon($coupon)
{
$couponCustomerCount = new ChildCouponCustomerCount();
$couponCustomerCount->setCoupon($coupon);
$this->addCouponCustomerCount($couponCustomerCount);
// set the back reference to this object directly as using provided method either results
// in endless loop or in multiple relations
if (!$coupon->getCustomers()->contains($this)) {
$foreignCollection = $coupon->getCustomers();
$foreignCollection[] = $this;
}
}
/**
* Remove a ChildCoupon object to this object
* through the coupon_customer_count cross reference table.
*
* @param ChildCoupon $coupon The ChildCouponCustomerCount object to relate
* @return ChildCustomer The current object (for fluent API support)
*/
public function removeCoupon(ChildCoupon $coupon)
{
if ($this->getCoupons()->contains($coupon)) {
$this->collCoupons->remove($this->collCoupons->search($coupon));
if (null === $this->couponsScheduledForDeletion) {
$this->couponsScheduledForDeletion = clone $this->collCoupons;
$this->couponsScheduledForDeletion->clear();
}
$this->couponsScheduledForDeletion[] = $coupon;
}
return $this;
}
/**
* Clears the current object and sets all attributes to their default values
*/
@@ -3035,11 +3547,23 @@ abstract class Customer implements ActiveRecordInterface
$o->clearAllReferences($deep);
}
}
if ($this->collCouponCustomerCounts) {
foreach ($this->collCouponCustomerCounts as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collCoupons) {
foreach ($this->collCoupons as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
$this->collAddresses = null;
$this->collOrders = null;
$this->collCarts = null;
$this->collCouponCustomerCounts = null;
$this->collCoupons = null;
$this->aCustomerTitle = null;
}

View File

@@ -75,6 +75,10 @@ use Thelia\Model\Map\CustomerTableMap;
* @method ChildCustomerQuery rightJoinCart($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Cart relation
* @method ChildCustomerQuery innerJoinCart($relationAlias = null) Adds a INNER JOIN clause to the query using the Cart relation
*
* @method ChildCustomerQuery leftJoinCouponCustomerCount($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponCustomerCount relation
* @method ChildCustomerQuery rightJoinCouponCustomerCount($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponCustomerCount relation
* @method ChildCustomerQuery innerJoinCouponCustomerCount($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponCustomerCount relation
*
* @method ChildCustomer findOne(ConnectionInterface $con = null) Return the first ChildCustomer matching the query
* @method ChildCustomer findOneOrCreate(ConnectionInterface $con = null) Return the first ChildCustomer matching the query, or a new ChildCustomer object populated from the query conditions when no match is found
*
@@ -1124,6 +1128,96 @@ abstract class CustomerQuery extends ModelCriteria
->useQuery($relationAlias ? $relationAlias : 'Cart', '\Thelia\Model\CartQuery');
}
/**
* Filter the query by a related \Thelia\Model\CouponCustomerCount object
*
* @param \Thelia\Model\CouponCustomerCount|ObjectCollection $couponCustomerCount the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCustomerQuery The current query, for fluid interface
*/
public function filterByCouponCustomerCount($couponCustomerCount, $comparison = null)
{
if ($couponCustomerCount instanceof \Thelia\Model\CouponCustomerCount) {
return $this
->addUsingAlias(CustomerTableMap::ID, $couponCustomerCount->getCustomerId(), $comparison);
} elseif ($couponCustomerCount instanceof ObjectCollection) {
return $this
->useCouponCustomerCountQuery()
->filterByPrimaryKeys($couponCustomerCount->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByCouponCustomerCount() only accepts arguments of type \Thelia\Model\CouponCustomerCount or Collection');
}
}
/**
* Adds a JOIN clause to the query using the CouponCustomerCount relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildCustomerQuery The current query, for fluid interface
*/
public function joinCouponCustomerCount($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('CouponCustomerCount');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'CouponCustomerCount');
}
return $this;
}
/**
* Use the CouponCustomerCount relation CouponCustomerCount object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\CouponCustomerCountQuery A secondary query class using the current class as primary query
*/
public function useCouponCustomerCountQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinCouponCustomerCount($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'CouponCustomerCount', '\Thelia\Model\CouponCustomerCountQuery');
}
/**
* Filter the query by a related Coupon object
* using the coupon_customer_count table as cross reference
*
* @param Coupon $coupon the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCustomerQuery The current query, for fluid interface
*/
public function filterByCoupon($coupon, $comparison = Criteria::EQUAL)
{
return $this
->useCouponCustomerCountQuery()
->filterByCoupon($coupon, $comparison)
->endUse();
}
/**
* Exclude object from result
*

View File

@@ -143,6 +143,12 @@ abstract class OrderCoupon implements ActiveRecordInterface
*/
protected $serialized_conditions;
/**
* The value for the per_customer_usage_count field.
* @var boolean
*/
protected $per_customer_usage_count;
/**
* The value for the created_at field.
* @var string
@@ -624,6 +630,17 @@ abstract class OrderCoupon implements ActiveRecordInterface
return $this->serialized_conditions;
}
/**
* Get the [per_customer_usage_count] column value.
*
* @return boolean
*/
public function getPerCustomerUsageCount()
{
return $this->per_customer_usage_count;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -965,6 +982,35 @@ abstract class OrderCoupon implements ActiveRecordInterface
return $this;
} // setSerializedConditions()
/**
* Sets the value of the [per_customer_usage_count] column.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
*
* @param boolean|integer|string $v The new value
* @return \Thelia\Model\OrderCoupon The current object (for fluent API support)
*/
public function setPerCustomerUsageCount($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->per_customer_usage_count !== $v) {
$this->per_customer_usage_count = $v;
$this->modifiedColumns[OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT] = true;
}
return $this;
} // setPerCustomerUsageCount()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -1086,13 +1132,16 @@ abstract class OrderCoupon implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : OrderCouponTableMap::translateFieldName('SerializedConditions', TableMap::TYPE_PHPNAME, $indexType)];
$this->serialized_conditions = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : OrderCouponTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : OrderCouponTableMap::translateFieldName('PerCustomerUsageCount', TableMap::TYPE_PHPNAME, $indexType)];
$this->per_customer_usage_count = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : OrderCouponTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : OrderCouponTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : OrderCouponTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -1105,7 +1154,7 @@ abstract class OrderCoupon implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 15; // 15 = OrderCouponTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 16; // 16 = OrderCouponTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\OrderCoupon object", 0, $e);
@@ -1474,6 +1523,9 @@ abstract class OrderCoupon implements ActiveRecordInterface
if ($this->isColumnModified(OrderCouponTableMap::SERIALIZED_CONDITIONS)) {
$modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
}
if ($this->isColumnModified(OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT)) {
$modifiedColumns[':p' . $index++] = '`PER_CUSTOMER_USAGE_COUNT`';
}
if ($this->isColumnModified(OrderCouponTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = '`CREATED_AT`';
}
@@ -1530,6 +1582,9 @@ abstract class OrderCoupon implements ActiveRecordInterface
case '`SERIALIZED_CONDITIONS`':
$stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
break;
case '`PER_CUSTOMER_USAGE_COUNT`':
$stmt->bindValue($identifier, (int) $this->per_customer_usage_count, PDO::PARAM_INT);
break;
case '`CREATED_AT`':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1638,9 +1693,12 @@ abstract class OrderCoupon implements ActiveRecordInterface
return $this->getSerializedConditions();
break;
case 13:
return $this->getCreatedAt();
return $this->getPerCustomerUsageCount();
break;
case 14:
return $this->getCreatedAt();
break;
case 15:
return $this->getUpdatedAt();
break;
default:
@@ -1685,8 +1743,9 @@ abstract class OrderCoupon implements ActiveRecordInterface
$keys[10] => $this->getIsRemovingPostage(),
$keys[11] => $this->getIsAvailableOnSpecialOffers(),
$keys[12] => $this->getSerializedConditions(),
$keys[13] => $this->getCreatedAt(),
$keys[14] => $this->getUpdatedAt(),
$keys[13] => $this->getPerCustomerUsageCount(),
$keys[14] => $this->getCreatedAt(),
$keys[15] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@@ -1777,9 +1836,12 @@ abstract class OrderCoupon implements ActiveRecordInterface
$this->setSerializedConditions($value);
break;
case 13:
$this->setCreatedAt($value);
$this->setPerCustomerUsageCount($value);
break;
case 14:
$this->setCreatedAt($value);
break;
case 15:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1819,8 +1881,9 @@ abstract class OrderCoupon implements ActiveRecordInterface
if (array_key_exists($keys[10], $arr)) $this->setIsRemovingPostage($arr[$keys[10]]);
if (array_key_exists($keys[11], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[11]]);
if (array_key_exists($keys[12], $arr)) $this->setSerializedConditions($arr[$keys[12]]);
if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]);
if (array_key_exists($keys[13], $arr)) $this->setPerCustomerUsageCount($arr[$keys[13]]);
if (array_key_exists($keys[14], $arr)) $this->setCreatedAt($arr[$keys[14]]);
if (array_key_exists($keys[15], $arr)) $this->setUpdatedAt($arr[$keys[15]]);
}
/**
@@ -1845,6 +1908,7 @@ abstract class OrderCoupon implements ActiveRecordInterface
if ($this->isColumnModified(OrderCouponTableMap::IS_REMOVING_POSTAGE)) $criteria->add(OrderCouponTableMap::IS_REMOVING_POSTAGE, $this->is_removing_postage);
if ($this->isColumnModified(OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) $criteria->add(OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $this->is_available_on_special_offers);
if ($this->isColumnModified(OrderCouponTableMap::SERIALIZED_CONDITIONS)) $criteria->add(OrderCouponTableMap::SERIALIZED_CONDITIONS, $this->serialized_conditions);
if ($this->isColumnModified(OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT)) $criteria->add(OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT, $this->per_customer_usage_count);
if ($this->isColumnModified(OrderCouponTableMap::CREATED_AT)) $criteria->add(OrderCouponTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(OrderCouponTableMap::UPDATED_AT)) $criteria->add(OrderCouponTableMap::UPDATED_AT, $this->updated_at);
@@ -1922,6 +1986,7 @@ abstract class OrderCoupon implements ActiveRecordInterface
$copyObj->setIsRemovingPostage($this->getIsRemovingPostage());
$copyObj->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers());
$copyObj->setSerializedConditions($this->getSerializedConditions());
$copyObj->setPerCustomerUsageCount($this->getPerCustomerUsageCount());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
@@ -2918,6 +2983,7 @@ abstract class OrderCoupon implements ActiveRecordInterface
$this->is_removing_postage = null;
$this->is_available_on_special_offers = null;
$this->serialized_conditions = null;
$this->per_customer_usage_count = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;

View File

@@ -34,6 +34,7 @@ use Thelia\Model\Map\OrderCouponTableMap;
* @method ChildOrderCouponQuery orderByIsRemovingPostage($order = Criteria::ASC) Order by the is_removing_postage column
* @method ChildOrderCouponQuery orderByIsAvailableOnSpecialOffers($order = Criteria::ASC) Order by the is_available_on_special_offers column
* @method ChildOrderCouponQuery orderBySerializedConditions($order = Criteria::ASC) Order by the serialized_conditions column
* @method ChildOrderCouponQuery orderByPerCustomerUsageCount($order = Criteria::ASC) Order by the per_customer_usage_count column
* @method ChildOrderCouponQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildOrderCouponQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
@@ -50,6 +51,7 @@ use Thelia\Model\Map\OrderCouponTableMap;
* @method ChildOrderCouponQuery groupByIsRemovingPostage() Group by the is_removing_postage column
* @method ChildOrderCouponQuery groupByIsAvailableOnSpecialOffers() Group by the is_available_on_special_offers column
* @method ChildOrderCouponQuery groupBySerializedConditions() Group by the serialized_conditions column
* @method ChildOrderCouponQuery groupByPerCustomerUsageCount() Group by the per_customer_usage_count column
* @method ChildOrderCouponQuery groupByCreatedAt() Group by the created_at column
* @method ChildOrderCouponQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -85,6 +87,7 @@ use Thelia\Model\Map\OrderCouponTableMap;
* @method ChildOrderCoupon findOneByIsRemovingPostage(boolean $is_removing_postage) Return the first ChildOrderCoupon filtered by the is_removing_postage column
* @method ChildOrderCoupon findOneByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return the first ChildOrderCoupon filtered by the is_available_on_special_offers column
* @method ChildOrderCoupon findOneBySerializedConditions(string $serialized_conditions) Return the first ChildOrderCoupon filtered by the serialized_conditions column
* @method ChildOrderCoupon findOneByPerCustomerUsageCount(boolean $per_customer_usage_count) Return the first ChildOrderCoupon filtered by the per_customer_usage_count column
* @method ChildOrderCoupon findOneByCreatedAt(string $created_at) Return the first ChildOrderCoupon filtered by the created_at column
* @method ChildOrderCoupon findOneByUpdatedAt(string $updated_at) Return the first ChildOrderCoupon filtered by the updated_at column
*
@@ -101,6 +104,7 @@ use Thelia\Model\Map\OrderCouponTableMap;
* @method array findByIsRemovingPostage(boolean $is_removing_postage) Return ChildOrderCoupon objects filtered by the is_removing_postage column
* @method array findByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return ChildOrderCoupon objects filtered by the is_available_on_special_offers column
* @method array findBySerializedConditions(string $serialized_conditions) Return ChildOrderCoupon objects filtered by the serialized_conditions column
* @method array findByPerCustomerUsageCount(boolean $per_customer_usage_count) Return ChildOrderCoupon objects filtered by the per_customer_usage_count column
* @method array findByCreatedAt(string $created_at) Return ChildOrderCoupon objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildOrderCoupon objects filtered by the updated_at column
*
@@ -191,7 +195,7 @@ abstract class OrderCouponQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `ORDER_ID`, `CODE`, `TYPE`, `AMOUNT`, `TITLE`, `SHORT_DESCRIPTION`, `DESCRIPTION`, `EXPIRATION_DATE`, `IS_CUMULATIVE`, `IS_REMOVING_POSTAGE`, `IS_AVAILABLE_ON_SPECIAL_OFFERS`, `SERIALIZED_CONDITIONS`, `CREATED_AT`, `UPDATED_AT` FROM `order_coupon` WHERE `ID` = :p0';
$sql = 'SELECT `ID`, `ORDER_ID`, `CODE`, `TYPE`, `AMOUNT`, `TITLE`, `SHORT_DESCRIPTION`, `DESCRIPTION`, `EXPIRATION_DATE`, `IS_CUMULATIVE`, `IS_REMOVING_POSTAGE`, `IS_AVAILABLE_ON_SPECIAL_OFFERS`, `SERIALIZED_CONDITIONS`, `PER_CUSTOMER_USAGE_COUNT`, `CREATED_AT`, `UPDATED_AT` FROM `order_coupon` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -703,6 +707,33 @@ abstract class OrderCouponQuery extends ModelCriteria
return $this->addUsingAlias(OrderCouponTableMap::SERIALIZED_CONDITIONS, $serializedConditions, $comparison);
}
/**
* Filter the query on the per_customer_usage_count column
*
* Example usage:
* <code>
* $query->filterByPerCustomerUsageCount(true); // WHERE per_customer_usage_count = true
* $query->filterByPerCustomerUsageCount('yes'); // WHERE per_customer_usage_count = true
* </code>
*
* @param boolean|string $perCustomerUsageCount The value to use as filter.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildOrderCouponQuery The current query, for fluid interface
*/
public function filterByPerCustomerUsageCount($perCustomerUsageCount = null, $comparison = null)
{
if (is_string($perCustomerUsageCount)) {
$per_customer_usage_count = in_array(strtolower($perCustomerUsageCount), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}
return $this->addUsingAlias(OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT, $perCustomerUsageCount, $comparison);
}
/**
* Filter the query on the created_at column
*

View File

@@ -64,13 +64,15 @@ class Coupon extends BaseCoupon
* @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
*
* @throws \Exception
*/
public function createOrUpdate(
$code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description,
$isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule,
$locale, $freeShippingForCountries, $freeShippingForMethods)
$locale, $freeShippingForCountries, $freeShippingForMethods,
$perCustomerUsageCount)
{
$con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME);
@@ -87,10 +89,12 @@ class Coupon extends BaseCoupon
->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
->setIsCumulative($isCumulative)
->setMaxUsage($maxUsage)
->setPerCustomerUsageCount($perCustomerUsageCount)
->setLocale($locale)
->setTitle($title)
->setShortDescription($shortDescription)
->setDescription($description);
->setDescription($description)
;
// If no rule given, set default rule
if (null === $this->getSerializedConditions()) {
@@ -269,4 +273,32 @@ class Coupon extends BaseCoupon
public function getFreeShippingForModules() {
return CouponModuleQuery::create()->filterByCouponId($this->getId())->find();
}
/**
* Get coupon usage left, either overall, or per customer.
*
* @param int|null $customerId the ID of the ordering customer
*
* @return int the usage left.
*/
public function getUsagesLeft($customerId = null)
{
$usageLeft = $this->getMaxUsage();
if ($this->getPerCustomerUsageCount()) {
// Get usage left for current customer. If the record is not found,
// it means that the customer has not yes used this coupon.
if (null !== $couponCustomerCount = CouponCustomerCountQuery::create()
->filterByCouponId($this->getId())
->filterByCustomerId($customerId)
->findOne()) {
// The coupon has already been used -> remove this customer's usage count
$usageLeft -= $couponCustomerCount->getCount();
}
}
return $usageLeft;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\CouponCustomerCount as BaseCouponCustomerCount;
class CouponCustomerCount extends BaseCouponCustomerCount
{
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\CouponCustomerCountQuery as BaseCouponCustomerCountQuery;
/**
* Skeleton subclass for performing query and update operations on the 'coupon_customer_count' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class CouponCustomerCountQuery extends BaseCouponCustomerCountQuery
{
} // CouponCustomerCountQuery

View File

@@ -0,0 +1,416 @@
<?php
namespace Thelia\Model\Map;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\InstancePoolTrait;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\DataFetcher\DataFetcherInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Map\RelationMap;
use Propel\Runtime\Map\TableMap;
use Propel\Runtime\Map\TableMapTrait;
use Thelia\Model\CouponCustomerCount;
use Thelia\Model\CouponCustomerCountQuery;
/**
* This class defines the structure of the 'coupon_customer_count' table.
*
*
*
* This map class is used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
*/
class CouponCustomerCountTableMap extends TableMap
{
use InstancePoolTrait;
use TableMapTrait;
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'Thelia.Model.Map.CouponCustomerCountTableMap';
/**
* The default database name for this class
*/
const DATABASE_NAME = 'thelia';
/**
* The table name for this class
*/
const TABLE_NAME = 'coupon_customer_count';
/**
* The related Propel class for this table
*/
const OM_CLASS = '\\Thelia\\Model\\CouponCustomerCount';
/**
* A class that can be returned by this tableMap
*/
const CLASS_DEFAULT = 'Thelia.Model.CouponCustomerCount';
/**
* The total number of columns
*/
const NUM_COLUMNS = 3;
/**
* The number of lazy-loaded columns
*/
const NUM_LAZY_LOAD_COLUMNS = 0;
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 3;
/**
* the column name for the COUPON_ID field
*/
const COUPON_ID = 'coupon_customer_count.COUPON_ID';
/**
* the column name for the CUSTOMER_ID field
*/
const CUSTOMER_ID = 'coupon_customer_count.CUSTOMER_ID';
/**
* the column name for the COUNT field
*/
const COUNT = 'coupon_customer_count.COUNT';
/**
* The default string format for model objects of the related table
*/
const DEFAULT_STRING_FORMAT = 'YAML';
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('CouponId', 'CustomerId', 'Count', ),
self::TYPE_STUDLYPHPNAME => array('couponId', 'customerId', 'count', ),
self::TYPE_COLNAME => array(CouponCustomerCountTableMap::COUPON_ID, CouponCustomerCountTableMap::CUSTOMER_ID, CouponCustomerCountTableMap::COUNT, ),
self::TYPE_RAW_COLNAME => array('COUPON_ID', 'CUSTOMER_ID', 'COUNT', ),
self::TYPE_FIELDNAME => array('coupon_id', 'customer_id', 'count', ),
self::TYPE_NUM => array(0, 1, 2, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('CouponId' => 0, 'CustomerId' => 1, 'Count' => 2, ),
self::TYPE_STUDLYPHPNAME => array('couponId' => 0, 'customerId' => 1, 'count' => 2, ),
self::TYPE_COLNAME => array(CouponCustomerCountTableMap::COUPON_ID => 0, CouponCustomerCountTableMap::CUSTOMER_ID => 1, CouponCustomerCountTableMap::COUNT => 2, ),
self::TYPE_RAW_COLNAME => array('COUPON_ID' => 0, 'CUSTOMER_ID' => 1, 'COUNT' => 2, ),
self::TYPE_FIELDNAME => array('coupon_id' => 0, 'customer_id' => 1, 'count' => 2, ),
self::TYPE_NUM => array(0, 1, 2, )
);
/**
* Initialize the table attributes and columns
* Relations are not initialized by this method since they are lazy loaded
*
* @return void
* @throws PropelException
*/
public function initialize()
{
// attributes
$this->setName('coupon_customer_count');
$this->setPhpName('CouponCustomerCount');
$this->setClassName('\\Thelia\\Model\\CouponCustomerCount');
$this->setPackage('Thelia.Model');
$this->setUseIdGenerator(false);
$this->setIsCrossRef(true);
// columns
$this->addForeignKey('COUPON_ID', 'CouponId', 'INTEGER', 'coupon', 'ID', true, null, null);
$this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', true, null, null);
$this->addColumn('COUNT', 'Count', 'INTEGER', true, null, 0);
} // initialize()
/**
* Build the RelationMap objects for this table relationships
*/
public function buildRelations()
{
$this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('customer_id' => 'id', ), 'CASCADE', null);
$this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_ONE, array('coupon_id' => 'id', ), 'CASCADE', null);
} // buildRelations()
/**
* Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
*
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, a serialize()d version of the primary key will be returned.
*
* @param array $row resultset row.
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
*/
public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
return null;
}
/**
* Retrieves the primary key from the DB resultset row
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, an array of the primary key columns will be returned.
*
* @param array $row resultset row.
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
*
* @return mixed The primary key of the row
*/
public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
return '';
}
/**
* The class that the tableMap will make instances of.
*
* If $withPrefix is true, the returned path
* uses a dot-path notation which is translated into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @param boolean $withPrefix Whether or not to return the path with the class name
* @return string path.to.ClassName
*/
public static function getOMClass($withPrefix = true)
{
return $withPrefix ? CouponCustomerCountTableMap::CLASS_DEFAULT : CouponCustomerCountTableMap::OM_CLASS;
}
/**
* Populates an object of the default type or an object that inherit from the default.
*
* @param array $row row returned by DataFetcher->fetch().
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return array (CouponCustomerCount object, last column rank)
*/
public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
$key = CouponCustomerCountTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
if (null !== ($obj = CouponCustomerCountTableMap::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, $offset, true); // rehydrate
$col = $offset + CouponCustomerCountTableMap::NUM_HYDRATE_COLUMNS;
} else {
$cls = CouponCustomerCountTableMap::OM_CLASS;
$obj = new $cls();
$col = $obj->hydrate($row, $offset, false, $indexType);
CouponCustomerCountTableMap::addInstanceToPool($obj, $key);
}
return array($obj, $col);
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @param DataFetcherInterface $dataFetcher
* @return array
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(DataFetcherInterface $dataFetcher)
{
$results = array();
// set the class once to avoid overhead in the loop
$cls = static::getOMClass(false);
// populate the object(s)
while ($row = $dataFetcher->fetch()) {
$key = CouponCustomerCountTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
if (null !== ($obj = CouponCustomerCountTableMap::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, 0, true); // rehydrate
$results[] = $obj;
} else {
$obj = new $cls();
$obj->hydrate($row);
$results[] = $obj;
CouponCustomerCountTableMap::addInstanceToPool($obj, $key);
} // if key exists
}
return $results;
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param Criteria $criteria object containing the columns to add.
* @param string $alias optional table alias
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(CouponCustomerCountTableMap::COUPON_ID);
$criteria->addSelectColumn(CouponCustomerCountTableMap::CUSTOMER_ID);
$criteria->addSelectColumn(CouponCustomerCountTableMap::COUNT);
} else {
$criteria->addSelectColumn($alias . '.COUPON_ID');
$criteria->addSelectColumn($alias . '.CUSTOMER_ID');
$criteria->addSelectColumn($alias . '.COUNT');
}
}
/**
* Returns the TableMap related to this object.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getServiceContainer()->getDatabaseMap(CouponCustomerCountTableMap::DATABASE_NAME)->getTable(CouponCustomerCountTableMap::TABLE_NAME);
}
/**
* Add a TableMap instance to the database for this tableMap class.
*/
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(CouponCustomerCountTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(CouponCustomerCountTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new CouponCustomerCountTableMap());
}
}
/**
* Performs a DELETE on the database, given a CouponCustomerCount or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or CouponCustomerCount object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CouponCustomerCountTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \Thelia\Model\CouponCustomerCount) { // it's a model object
// create criteria based on pk value
$criteria = $values->buildCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(CouponCustomerCountTableMap::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey values
if (count($values) == count($values, COUNT_RECURSIVE)) {
// array is not multi-dimensional
$values = array($values);
}
foreach ($values as $value) {
$criteria->addOr($criterion);
}
}
$query = CouponCustomerCountQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) { CouponCustomerCountTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) { CouponCustomerCountTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
}
/**
* Deletes all rows from the coupon_customer_count table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll(ConnectionInterface $con = null)
{
return CouponCustomerCountQuery::create()->doDeleteAll($con);
}
/**
* Performs an INSERT on the database, given a CouponCustomerCount or Criteria object.
*
* @param mixed $criteria Criteria or CouponCustomerCount object containing data that is used to create the INSERT statement.
* @param ConnectionInterface $con the ConnectionInterface connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CouponCustomerCountTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from CouponCustomerCount object
}
// Set the correct dbName
$query = CouponCustomerCountQuery::create()->mergeWith($criteria);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = $query->doInsert($con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $pk;
}
} // CouponCustomerCountTableMap
// This is the static code needed to register the TableMap for this table with the main Propel class.
//
CouponCustomerCountTableMap::buildTableMap();

View File

@@ -58,7 +58,7 @@ class CouponTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 15;
const NUM_COLUMNS = 16;
/**
* The number of lazy-loaded columns
@@ -68,7 +68,7 @@ class CouponTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 15;
const NUM_HYDRATE_COLUMNS = 16;
/**
* the column name for the ID field
@@ -130,6 +130,11 @@ class CouponTableMap extends TableMap
*/
const SERIALIZED_CONDITIONS = 'coupon.SERIALIZED_CONDITIONS';
/**
* the column name for the PER_CUSTOMER_USAGE_COUNT field
*/
const PER_CUSTOMER_USAGE_COUNT = 'coupon.PER_CUSTOMER_USAGE_COUNT';
/**
* the column name for the CREATED_AT field
*/
@@ -166,12 +171,12 @@ class CouponTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
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, )
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'PerCustomerUsageCount', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'perCustomerUsageCount', '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::PER_CUSTOMER_USAGE_COUNT, 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', 'PER_CUSTOMER_USAGE_COUNT', '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', 'per_customer_usage_count', 'created_at', 'updated_at', 'version', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -181,12 +186,12 @@ 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, '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, )
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, 'PerCustomerUsageCount' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, 'Version' => 15, ),
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, 'perCustomerUsageCount' => 12, 'createdAt' => 13, 'updatedAt' => 14, 'version' => 15, ),
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::PER_CUSTOMER_USAGE_COUNT => 12, CouponTableMap::CREATED_AT => 13, CouponTableMap::UPDATED_AT => 14, CouponTableMap::VERSION => 15, ),
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, 'PER_CUSTOMER_USAGE_COUNT' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, 'VERSION' => 15, ),
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, 'per_customer_usage_count' => 12, 'created_at' => 13, 'updated_at' => 14, 'version' => 15, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -217,6 +222,7 @@ class CouponTableMap extends TableMap
$this->addColumn('IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IsAvailableOnSpecialOffers', 'BOOLEAN', true, 1, null);
$this->addColumn('IS_USED', 'IsUsed', 'BOOLEAN', true, 1, null);
$this->addColumn('SERIALIZED_CONDITIONS', 'SerializedConditions', 'LONGVARCHAR', true, null, null);
$this->addColumn('PER_CUSTOMER_USAGE_COUNT', 'PerCustomerUsageCount', 'BOOLEAN', true, 1, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0);
@@ -229,10 +235,12 @@ class CouponTableMap extends TableMap
{
$this->addRelation('CouponCountry', '\\Thelia\\Model\\CouponCountry', RelationMap::ONE_TO_MANY, array('id' => 'coupon_id', ), 'CASCADE', null, 'CouponCountries');
$this->addRelation('CouponModule', '\\Thelia\\Model\\CouponModule', RelationMap::ONE_TO_MANY, array('id' => 'coupon_id', ), 'CASCADE', null, 'CouponModules');
$this->addRelation('CouponCustomerCount', '\\Thelia\\Model\\CouponCustomerCount', RelationMap::ONE_TO_MANY, array('id' => 'coupon_id', ), 'CASCADE', null, 'CouponCustomerCounts');
$this->addRelation('CouponI18n', '\\Thelia\\Model\\CouponI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CouponI18ns');
$this->addRelation('CouponVersion', '\\Thelia\\Model\\CouponVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CouponVersions');
$this->addRelation('Country', '\\Thelia\\Model\\Country', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Countries');
$this->addRelation('Module', '\\Thelia\\Model\\Module', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Modules');
$this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Customers');
} // buildRelations()
/**
@@ -258,6 +266,7 @@ class CouponTableMap extends TableMap
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
CouponCountryTableMap::clearInstancePool();
CouponModuleTableMap::clearInstancePool();
CouponCustomerCountTableMap::clearInstancePool();
CouponI18nTableMap::clearInstancePool();
CouponVersionTableMap::clearInstancePool();
}
@@ -412,6 +421,7 @@ class CouponTableMap extends TableMap
$criteria->addSelectColumn(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS);
$criteria->addSelectColumn(CouponTableMap::IS_USED);
$criteria->addSelectColumn(CouponTableMap::SERIALIZED_CONDITIONS);
$criteria->addSelectColumn(CouponTableMap::PER_CUSTOMER_USAGE_COUNT);
$criteria->addSelectColumn(CouponTableMap::CREATED_AT);
$criteria->addSelectColumn(CouponTableMap::UPDATED_AT);
$criteria->addSelectColumn(CouponTableMap::VERSION);
@@ -428,6 +438,7 @@ class CouponTableMap extends TableMap
$criteria->addSelectColumn($alias . '.IS_AVAILABLE_ON_SPECIAL_OFFERS');
$criteria->addSelectColumn($alias . '.IS_USED');
$criteria->addSelectColumn($alias . '.SERIALIZED_CONDITIONS');
$criteria->addSelectColumn($alias . '.PER_CUSTOMER_USAGE_COUNT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
$criteria->addSelectColumn($alias . '.VERSION');

View File

@@ -58,7 +58,7 @@ class CouponVersionTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 15;
const NUM_COLUMNS = 16;
/**
* The number of lazy-loaded columns
@@ -68,7 +68,7 @@ class CouponVersionTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 15;
const NUM_HYDRATE_COLUMNS = 16;
/**
* the column name for the ID field
@@ -130,6 +130,11 @@ class CouponVersionTableMap extends TableMap
*/
const SERIALIZED_CONDITIONS = 'coupon_version.SERIALIZED_CONDITIONS';
/**
* the column name for the PER_CUSTOMER_USAGE_COUNT field
*/
const PER_CUSTOMER_USAGE_COUNT = 'coupon_version.PER_CUSTOMER_USAGE_COUNT';
/**
* the column name for the CREATED_AT field
*/
@@ -157,12 +162,12 @@ class CouponVersionTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
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, )
self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'PerCustomerUsageCount', 'CreatedAt', 'UpdatedAt', 'Version', ),
self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'perCustomerUsageCount', '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::PER_CUSTOMER_USAGE_COUNT, 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', 'PER_CUSTOMER_USAGE_COUNT', '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', 'per_customer_usage_count', 'created_at', 'updated_at', 'version', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -172,12 +177,12 @@ 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, '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, )
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, 'PerCustomerUsageCount' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, 'Version' => 15, ),
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, 'perCustomerUsageCount' => 12, 'createdAt' => 13, 'updatedAt' => 14, 'version' => 15, ),
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::PER_CUSTOMER_USAGE_COUNT => 12, CouponVersionTableMap::CREATED_AT => 13, CouponVersionTableMap::UPDATED_AT => 14, CouponVersionTableMap::VERSION => 15, ),
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, 'PER_CUSTOMER_USAGE_COUNT' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, 'VERSION' => 15, ),
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, 'per_customer_usage_count' => 12, 'created_at' => 13, 'updated_at' => 14, 'version' => 15, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -208,6 +213,7 @@ class CouponVersionTableMap extends TableMap
$this->addColumn('IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IsAvailableOnSpecialOffers', 'BOOLEAN', true, 1, null);
$this->addColumn('IS_USED', 'IsUsed', 'BOOLEAN', true, 1, null);
$this->addColumn('SERIALIZED_CONDITIONS', 'SerializedConditions', 'LONGVARCHAR', true, null, null);
$this->addColumn('PER_CUSTOMER_USAGE_COUNT', 'PerCustomerUsageCount', 'BOOLEAN', true, 1, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
$this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0);
@@ -288,11 +294,11 @@ class CouponVersionTableMap extends TableMap
public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
// If the PK cannot be derived from the row, return NULL.
if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 14 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) {
if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 15 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) {
return null;
}
return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 14 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]));
return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 15 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]));
}
/**
@@ -420,6 +426,7 @@ class CouponVersionTableMap extends TableMap
$criteria->addSelectColumn(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS);
$criteria->addSelectColumn(CouponVersionTableMap::IS_USED);
$criteria->addSelectColumn(CouponVersionTableMap::SERIALIZED_CONDITIONS);
$criteria->addSelectColumn(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT);
$criteria->addSelectColumn(CouponVersionTableMap::CREATED_AT);
$criteria->addSelectColumn(CouponVersionTableMap::UPDATED_AT);
$criteria->addSelectColumn(CouponVersionTableMap::VERSION);
@@ -436,6 +443,7 @@ class CouponVersionTableMap extends TableMap
$criteria->addSelectColumn($alias . '.IS_AVAILABLE_ON_SPECIAL_OFFERS');
$criteria->addSelectColumn($alias . '.IS_USED');
$criteria->addSelectColumn($alias . '.SERIALIZED_CONDITIONS');
$criteria->addSelectColumn($alias . '.PER_CUSTOMER_USAGE_COUNT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
$criteria->addSelectColumn($alias . '.VERSION');

View File

@@ -228,6 +228,8 @@ class CustomerTableMap extends TableMap
$this->addRelation('Address', '\\Thelia\\Model\\Address', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'CASCADE', 'RESTRICT', 'Addresses');
$this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'RESTRICT', 'RESTRICT', 'Orders');
$this->addRelation('Cart', '\\Thelia\\Model\\Cart', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'CASCADE', 'RESTRICT', 'Carts');
$this->addRelation('CouponCustomerCount', '\\Thelia\\Model\\CouponCustomerCount', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'CASCADE', null, 'CouponCustomerCounts');
$this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Coupons');
} // buildRelations()
/**
@@ -251,6 +253,7 @@ class CustomerTableMap extends TableMap
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
AddressTableMap::clearInstancePool();
CartTableMap::clearInstancePool();
CouponCustomerCountTableMap::clearInstancePool();
}
/**

View File

@@ -58,7 +58,7 @@ class OrderCouponTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 15;
const NUM_COLUMNS = 16;
/**
* The number of lazy-loaded columns
@@ -68,7 +68,7 @@ class OrderCouponTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 15;
const NUM_HYDRATE_COLUMNS = 16;
/**
* the column name for the ID field
@@ -135,6 +135,11 @@ class OrderCouponTableMap extends TableMap
*/
const SERIALIZED_CONDITIONS = 'order_coupon.SERIALIZED_CONDITIONS';
/**
* the column name for the PER_CUSTOMER_USAGE_COUNT field
*/
const PER_CUSTOMER_USAGE_COUNT = 'order_coupon.PER_CUSTOMER_USAGE_COUNT';
/**
* the column name for the CREATED_AT field
*/
@@ -157,12 +162,12 @@ class OrderCouponTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'OrderId', 'Code', 'Type', 'Amount', 'Title', 'ShortDescription', 'Description', 'ExpirationDate', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'orderId', 'code', 'type', 'amount', 'title', 'shortDescription', 'description', 'expirationDate', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'serializedConditions', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(OrderCouponTableMap::ID, OrderCouponTableMap::ORDER_ID, OrderCouponTableMap::CODE, OrderCouponTableMap::TYPE, OrderCouponTableMap::AMOUNT, OrderCouponTableMap::TITLE, OrderCouponTableMap::SHORT_DESCRIPTION, OrderCouponTableMap::DESCRIPTION, OrderCouponTableMap::EXPIRATION_DATE, OrderCouponTableMap::IS_CUMULATIVE, OrderCouponTableMap::IS_REMOVING_POSTAGE, OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, OrderCouponTableMap::SERIALIZED_CONDITIONS, OrderCouponTableMap::CREATED_AT, OrderCouponTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'ORDER_ID', 'CODE', 'TYPE', 'AMOUNT', 'TITLE', 'SHORT_DESCRIPTION', 'DESCRIPTION', 'EXPIRATION_DATE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'order_id', 'code', 'type', 'amount', 'title', 'short_description', 'description', 'expiration_date', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'serialized_conditions', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
self::TYPE_PHPNAME => array('Id', 'OrderId', 'Code', 'Type', 'Amount', 'Title', 'ShortDescription', 'Description', 'ExpirationDate', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'SerializedConditions', 'PerCustomerUsageCount', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'orderId', 'code', 'type', 'amount', 'title', 'shortDescription', 'description', 'expirationDate', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'serializedConditions', 'perCustomerUsageCount', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(OrderCouponTableMap::ID, OrderCouponTableMap::ORDER_ID, OrderCouponTableMap::CODE, OrderCouponTableMap::TYPE, OrderCouponTableMap::AMOUNT, OrderCouponTableMap::TITLE, OrderCouponTableMap::SHORT_DESCRIPTION, OrderCouponTableMap::DESCRIPTION, OrderCouponTableMap::EXPIRATION_DATE, OrderCouponTableMap::IS_CUMULATIVE, OrderCouponTableMap::IS_REMOVING_POSTAGE, OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, OrderCouponTableMap::SERIALIZED_CONDITIONS, OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT, OrderCouponTableMap::CREATED_AT, OrderCouponTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'ORDER_ID', 'CODE', 'TYPE', 'AMOUNT', 'TITLE', 'SHORT_DESCRIPTION', 'DESCRIPTION', 'EXPIRATION_DATE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'SERIALIZED_CONDITIONS', 'PER_CUSTOMER_USAGE_COUNT', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'order_id', 'code', 'type', 'amount', 'title', 'short_description', 'description', 'expiration_date', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'serialized_conditions', 'per_customer_usage_count', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -172,12 +177,12 @@ class OrderCouponTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'OrderId' => 1, 'Code' => 2, 'Type' => 3, 'Amount' => 4, 'Title' => 5, 'ShortDescription' => 6, 'Description' => 7, 'ExpirationDate' => 8, 'IsCumulative' => 9, 'IsRemovingPostage' => 10, 'IsAvailableOnSpecialOffers' => 11, 'SerializedConditions' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderId' => 1, 'code' => 2, 'type' => 3, 'amount' => 4, 'title' => 5, 'shortDescription' => 6, 'description' => 7, 'expirationDate' => 8, 'isCumulative' => 9, 'isRemovingPostage' => 10, 'isAvailableOnSpecialOffers' => 11, 'serializedConditions' => 12, 'createdAt' => 13, 'updatedAt' => 14, ),
self::TYPE_COLNAME => array(OrderCouponTableMap::ID => 0, OrderCouponTableMap::ORDER_ID => 1, OrderCouponTableMap::CODE => 2, OrderCouponTableMap::TYPE => 3, OrderCouponTableMap::AMOUNT => 4, OrderCouponTableMap::TITLE => 5, OrderCouponTableMap::SHORT_DESCRIPTION => 6, OrderCouponTableMap::DESCRIPTION => 7, OrderCouponTableMap::EXPIRATION_DATE => 8, OrderCouponTableMap::IS_CUMULATIVE => 9, OrderCouponTableMap::IS_REMOVING_POSTAGE => 10, OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 11, OrderCouponTableMap::SERIALIZED_CONDITIONS => 12, OrderCouponTableMap::CREATED_AT => 13, OrderCouponTableMap::UPDATED_AT => 14, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_ID' => 1, 'CODE' => 2, 'TYPE' => 3, 'AMOUNT' => 4, 'TITLE' => 5, 'SHORT_DESCRIPTION' => 6, 'DESCRIPTION' => 7, 'EXPIRATION_DATE' => 8, 'IS_CUMULATIVE' => 9, 'IS_REMOVING_POSTAGE' => 10, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 11, 'SERIALIZED_CONDITIONS' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, ),
self::TYPE_FIELDNAME => array('id' => 0, 'order_id' => 1, 'code' => 2, 'type' => 3, 'amount' => 4, 'title' => 5, 'short_description' => 6, 'description' => 7, 'expiration_date' => 8, 'is_cumulative' => 9, 'is_removing_postage' => 10, 'is_available_on_special_offers' => 11, 'serialized_conditions' => 12, 'created_at' => 13, 'updated_at' => 14, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
self::TYPE_PHPNAME => array('Id' => 0, 'OrderId' => 1, 'Code' => 2, 'Type' => 3, 'Amount' => 4, 'Title' => 5, 'ShortDescription' => 6, 'Description' => 7, 'ExpirationDate' => 8, 'IsCumulative' => 9, 'IsRemovingPostage' => 10, 'IsAvailableOnSpecialOffers' => 11, 'SerializedConditions' => 12, 'PerCustomerUsageCount' => 13, 'CreatedAt' => 14, 'UpdatedAt' => 15, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderId' => 1, 'code' => 2, 'type' => 3, 'amount' => 4, 'title' => 5, 'shortDescription' => 6, 'description' => 7, 'expirationDate' => 8, 'isCumulative' => 9, 'isRemovingPostage' => 10, 'isAvailableOnSpecialOffers' => 11, 'serializedConditions' => 12, 'perCustomerUsageCount' => 13, 'createdAt' => 14, 'updatedAt' => 15, ),
self::TYPE_COLNAME => array(OrderCouponTableMap::ID => 0, OrderCouponTableMap::ORDER_ID => 1, OrderCouponTableMap::CODE => 2, OrderCouponTableMap::TYPE => 3, OrderCouponTableMap::AMOUNT => 4, OrderCouponTableMap::TITLE => 5, OrderCouponTableMap::SHORT_DESCRIPTION => 6, OrderCouponTableMap::DESCRIPTION => 7, OrderCouponTableMap::EXPIRATION_DATE => 8, OrderCouponTableMap::IS_CUMULATIVE => 9, OrderCouponTableMap::IS_REMOVING_POSTAGE => 10, OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 11, OrderCouponTableMap::SERIALIZED_CONDITIONS => 12, OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT => 13, OrderCouponTableMap::CREATED_AT => 14, OrderCouponTableMap::UPDATED_AT => 15, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_ID' => 1, 'CODE' => 2, 'TYPE' => 3, 'AMOUNT' => 4, 'TITLE' => 5, 'SHORT_DESCRIPTION' => 6, 'DESCRIPTION' => 7, 'EXPIRATION_DATE' => 8, 'IS_CUMULATIVE' => 9, 'IS_REMOVING_POSTAGE' => 10, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 11, 'SERIALIZED_CONDITIONS' => 12, 'PER_CUSTOMER_USAGE_COUNT' => 13, 'CREATED_AT' => 14, 'UPDATED_AT' => 15, ),
self::TYPE_FIELDNAME => array('id' => 0, 'order_id' => 1, 'code' => 2, 'type' => 3, 'amount' => 4, 'title' => 5, 'short_description' => 6, 'description' => 7, 'expiration_date' => 8, 'is_cumulative' => 9, 'is_removing_postage' => 10, 'is_available_on_special_offers' => 11, 'serialized_conditions' => 12, 'per_customer_usage_count' => 13, 'created_at' => 14, 'updated_at' => 15, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
);
/**
@@ -209,6 +214,7 @@ class OrderCouponTableMap extends TableMap
$this->addColumn('IS_REMOVING_POSTAGE', 'IsRemovingPostage', 'BOOLEAN', true, 1, null);
$this->addColumn('IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IsAvailableOnSpecialOffers', 'BOOLEAN', true, 1, null);
$this->addColumn('SERIALIZED_CONDITIONS', 'SerializedConditions', 'LONGVARCHAR', true, null, null);
$this->addColumn('PER_CUSTOMER_USAGE_COUNT', 'PerCustomerUsageCount', 'BOOLEAN', true, 1, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -398,6 +404,7 @@ class OrderCouponTableMap extends TableMap
$criteria->addSelectColumn(OrderCouponTableMap::IS_REMOVING_POSTAGE);
$criteria->addSelectColumn(OrderCouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS);
$criteria->addSelectColumn(OrderCouponTableMap::SERIALIZED_CONDITIONS);
$criteria->addSelectColumn(OrderCouponTableMap::PER_CUSTOMER_USAGE_COUNT);
$criteria->addSelectColumn(OrderCouponTableMap::CREATED_AT);
$criteria->addSelectColumn(OrderCouponTableMap::UPDATED_AT);
} else {
@@ -414,6 +421,7 @@ class OrderCouponTableMap extends TableMap
$criteria->addSelectColumn($alias . '.IS_REMOVING_POSTAGE');
$criteria->addSelectColumn($alias . '.IS_AVAILABLE_ON_SPECIAL_OFFERS');
$criteria->addSelectColumn($alias . '.SERIALIZED_CONDITIONS');
$criteria->addSelectColumn($alias . '.PER_CUSTOMER_USAGE_COUNT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}

View File

@@ -16,9 +16,11 @@ use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Implementation\MatchForTotalAmount;
use Thelia\Condition\Operators;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\Type\RemoveXAmount;
use Thelia\Model\Coupon;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\Customer;
/**
* Unit Test CouponFactory Class
@@ -72,6 +74,13 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$customer = new Customer();
$customer->setId(1);
$stubFacade->expects($this->any())
->method('getCustomer')
->will($this->returnValue($customer));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
@@ -221,6 +230,75 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$this->assertEquals($expected, $actual);
}
/**
* @covers Thelia\Coupon\CouponFactory::buildCouponFromCode
* @expectedException \Thelia\Exception\CouponNoUsageLeftException
*/
public function testBuildCouponFromCodeUsageLimitCoupon()
{
$stubFacade = $this->generateFacadeStub();
$stubContainer = $this->getMock('\Symfony\Component\DependencyInjection\Container');
$conditionFactory = new ConditionFactory($stubContainer);
$couponModel = $this->generateCouponModel($stubFacade, $conditionFactory);
$date = new \DateTime();
$couponModel->setExpirationDate($date->setTimestamp(strtotime("today + 3 months")));
$couponModel->setMaxUsage(0);
$couponModel->setPerCustomerUsageCount(false);
$stubFacade->expects($this->any())
->method('findOneCouponByCode')
->will($this->returnValue($couponModel));
$couponManager = new RemoveXAmount($stubFacade);
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$condition2 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition2->setValidatorsFromForm($operators, $values);
$conditions = new ConditionCollection();
$conditions[] = $condition1;
$conditions[] = $condition2;
$stubConditionFactory = $this->getMockBuilder('\Thelia\Condition\ConditionFactory')
->disableOriginalConstructor()
->getMock();
$stubConditionFactory->expects($this->any())
->method('unserializeConditionCollection')
->will($this->returnValue($conditions));
$stubContainer->expects($this->any())
->method('get')
->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValue(true));
$dummy = new Translator($stubContainer);
$factory = new CouponFactory($stubContainer);
$factory->buildCouponFromCode('XMAS');
}
/**
* @covers Thelia\Coupon\CouponFactory::buildCouponFromCode
*/
@@ -312,6 +390,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
->method('has')
->will($this->returnValue(true));
$dummy = new Translator($stubContainer);
$factory = new CouponFactory($stubContainer);
$factory->buildCouponFromCode('XMAS');

View File

@@ -402,7 +402,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$stubFacade, 'XMAS', '', '', '', array('amount' => 21.00),
true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")),
new ObjectCollection(),
new ObjectCollection()
new ObjectCollection(),
false
);
$condition1 = new MatchForTotalAmount($stubFacade);
@@ -446,13 +447,13 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
->disableOriginalConstructor()
->getMock();
$stubModel->expects($this->any())
->method('getMaxUsage')
->method('getUsagesLeft')
->will($this->returnValue(21));
$stubModel->expects($this->any())
->method('setMaxUsage')
->will($this->returnValue(true));
$actual = $couponManager->decrementQuantity($stubModel);
$actual = $couponManager->decrementQuantity($stubModel, null);
$expected = 20;
$this->assertEquals($expected, $actual);
@@ -472,7 +473,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$stubFacade, 'XMAS', '', '', '', array('amount' => 21.00),
true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")),
new ObjectCollection(),
new ObjectCollection()
new ObjectCollection(),
false
);
$condition1 = new MatchForTotalAmount($stubFacade);
@@ -522,8 +524,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
->method('setMaxUsage')
->will($this->returnValue(true));
$actual = $couponManager->decrementQuantity($stubModel);
$expected = -1;
$actual = $couponManager->decrementQuantity($stubModel, null);
$expected = false;
$this->assertEquals($expected, $actual);
}

View File

@@ -119,7 +119,8 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
$stubFacade, 'XMAS', 'XMAS Coupon', 'Coupon for Springbreak removing 10€ if you have a cart between 40.00€ and 400.00€ (excluded)',
$description, array('amount' => 10.00), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")),
new ObjectCollection(),
new ObjectCollection()
new ObjectCollection(),
false
);
$condition1 = new MatchForTotalAmount($stubFacade);

View File

@@ -109,7 +109,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
$description, array('amount' => 0.00, 'percentage' => 10.00), true, true, true, true,
254, $date->setTimestamp(strtotime("today + 3 months")),
new ObjectCollection(),
new ObjectCollection()
new ObjectCollection(),
false
);
$condition1 = new MatchForTotalAmount($stubFacade);

View File

@@ -911,6 +911,7 @@
<column name="is_removing_postage" required="true" type="BOOLEAN" />
<column name="is_available_on_special_offers" required="true" type="BOOLEAN" />
<column name="is_used" required="true" type="BOOLEAN" />
<column name="serialized_conditions" required="true" type="LONGVARCHAR" />
<column name="per_customer_usage_count" required="true" type="BOOLEAN" />
<unique name="code_UNIQUE">
<unique-column name="code" />
@@ -1335,6 +1336,7 @@
<column name="is_cumulative" required="true" type="BOOLEAN" />
<column name="is_removing_postage" required="true" type="BOOLEAN" />
<column name="is_available_on_special_offers" required="true" type="BOOLEAN" />
<column name="serialized_conditions" required="true" type="LONGVARCHAR" />
<column name="per_customer_usage_count" required="true" type="BOOLEAN" />
<foreign-key foreignTable="order" name="fk_order_coupon_order_id" onDelete="CASCADE" onUpdate="RESTRICT">
<reference foreign="id" local="order_id" />
@@ -1395,4 +1397,21 @@
<index name="fk_module_id_idx">
<index-column name="module_id" />
</index>
</table>
<table isCrossRef="true" name="coupon_customer_count" namespace="Thelia\Model">
<column name="coupon_id" required="true" type="INTEGER" />
<column name="customer_id" required="true" type="INTEGER" />
<column defaultValue="0" name="count" required="true" type="INTEGER" />
<foreign-key foreignTable="customer" name="fk_coupon_customer_customer_id" onDelete="CASCADE">
<reference foreign="id" local="customer_id" />
</foreign-key>
<foreign-key foreignTable="coupon" name="fk_coupon_customer_coupon_id" onDelete="CASCADE">
<reference foreign="id" local="coupon_id" />
</foreign-key>
<index name="fk_coupon_customer_customer_id_idx">
<index-column name="customer_id" />
</index>
<index name="fk_coupon_customer_coupon_id_idx">
<index-column name="coupon_id" />
</index>
</table>

View File

@@ -1107,6 +1107,7 @@ CREATE TABLE `coupon`
`is_available_on_special_offers` TINYINT(1) NOT NULL,
`is_used` TINYINT(1) NOT NULL,
`serialized_conditions` TEXT NOT NULL,
`per_customer_usage_count` TINYINT(1) NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
`version` INTEGER DEFAULT 0,
@@ -1635,6 +1636,7 @@ CREATE TABLE `order_coupon`
`is_removing_postage` TINYINT(1) NOT NULL,
`is_available_on_special_offers` TINYINT(1) NOT NULL,
`serialized_conditions` TEXT NOT NULL,
`per_customer_usage_count` TINYINT(1) NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
@@ -1733,6 +1735,29 @@ CREATE TABLE `order_coupon_module`
ON DELETE CASCADE
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- coupon_customer_count
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `coupon_customer_count`;
CREATE TABLE `coupon_customer_count`
(
`coupon_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`count` INTEGER DEFAULT 0 NOT NULL,
INDEX `fk_coupon_customer_customer_id_idx` (`customer_id`),
INDEX `fk_coupon_customer_coupon_id_idx` (`coupon_id`),
CONSTRAINT `fk_coupon_customer_customer_id`
FOREIGN KEY (`customer_id`)
REFERENCES `customer` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_coupon_customer_coupon_id`
FOREIGN KEY (`coupon_id`)
REFERENCES `coupon` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- category_i18n
-- ---------------------------------------------------------------------
@@ -2506,6 +2531,7 @@ CREATE TABLE `coupon_version`
`is_available_on_special_offers` TINYINT(1) NOT NULL,
`is_used` TINYINT(1) NOT NULL,
`serialized_conditions` TEXT NOT NULL,
`per_customer_usage_count` TINYINT(1) NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
`version` INTEGER DEFAULT 0 NOT NULL,

View File

@@ -10,4 +10,108 @@ UPDATE `config` SET `value`='' WHERE `name`='thelia_extra_version';
ALTER TABLE `rewriting_url` DROP INDEX `idx_rewriting_url_view_updated_at`;
ALTER TABLE `rewriting_url` DROP INDEX `idx_rewriting_url_view_id_view_view_locale_updated_at`;
# Add coupon country/modules crossref tables
# ------------------------------------------
DROP TABLE IF EXISTS `coupon_country`;
CREATE TABLE `coupon_country`
(
`coupon_id` INTEGER NOT NULL,
`country_id` INTEGER NOT NULL,
PRIMARY KEY (`coupon_id`,`country_id`),
INDEX `fk_country_id_idx` (`country_id`),
CONSTRAINT `fk_coupon_country_country_id`
FOREIGN KEY (`country_id`)
REFERENCES `country` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_coupon_country_coupon_id`
FOREIGN KEY (`coupon_id`)
REFERENCES `coupon` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `coupon_module`;
CREATE TABLE `coupon_module`
(
`coupon_id` INTEGER NOT NULL,
`module_id` INTEGER NOT NULL,
PRIMARY KEY (`coupon_id`,`module_id`),
INDEX `fk_module_id_idx` (`module_id`),
CONSTRAINT `fk_coupon_module_coupon_id`
FOREIGN KEY (`coupon_id`)
REFERENCES `coupon` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_coupon_module_module_id`
FOREIGN KEY (`module_id`)
REFERENCES `module` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `order_coupon_country`;
CREATE TABLE `order_coupon_country`
(
`coupon_id` INTEGER NOT NULL,
`country_id` INTEGER NOT NULL,
PRIMARY KEY (`coupon_id`,`country_id`),
INDEX `fk_country_id_idx` (`country_id`),
CONSTRAINT `fk_order_coupon_country_country_id`
FOREIGN KEY (`country_id`)
REFERENCES `country` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_order_coupon_country_coupon_id`
FOREIGN KEY (`coupon_id`)
REFERENCES `order_coupon` (`id`)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `order_coupon_module`;
CREATE TABLE `order_coupon_module`
(
`coupon_id` INTEGER NOT NULL,
`module_id` INTEGER NOT NULL,
PRIMARY KEY (`coupon_id`,`module_id`),
INDEX `fk_module_id_idx` (`module_id`),
CONSTRAINT `fk_coupon_module_coupon_id0`
FOREIGN KEY (`coupon_id`)
REFERENCES `order_coupon` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_coupon_module_module_id0`
FOREIGN KEY (`module_id`)
REFERENCES `module` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
# Per customer usage count
# ------------------------
# Add new column to coupon tables (coupon, order_coupon, coupon_version)
ALTER TABLE `coupon` ADD `per_customer_usage_count` BOOLEAN NOT NULL DEFAULT FALSE AFTER `serialized_conditions`;
ALTER TABLE `order_coupon` ADD `per_customer_usage_count` BOOLEAN NOT NULL DEFAULT FALSE AFTER `serialized_conditions`;
ALTER TABLE `coupon_version` ADD `per_customer_usage_count` BOOLEAN NOT NULL DEFAULT FALSE AFTER `serialized_conditions`;
DROP TABLE IF EXISTS `coupon_customer_count`;
CREATE TABLE `coupon_customer_count`
(
`coupon_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`count` INTEGER DEFAULT 0 NOT NULL,
INDEX `fk_coupon_customer_customer_id_idx` (`customer_id`),
INDEX `fk_coupon_customer_coupon_id_idx` (`coupon_id`),
CONSTRAINT `fk_coupon_customer_customer_id`
FOREIGN KEY (`customer_id`)
REFERENCES `customer` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_coupon_customer_coupon_id`
FOREIGN KEY (`coupon_id`)
REFERENCES `coupon` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -61,6 +61,7 @@ return array(
'Amount' => 'Amount',
'An error occured' => 'An error occured',
'And' => 'And',
'Applies to products in categories :' => 'Applies to products in categories :',
'Apply' => 'Apply',
'Associated countries' => 'Associated countries',
'Associations' => 'Associations',
@@ -210,6 +211,7 @@ return array(
'Customer' => 'Customer',
'Customer export' => 'Customer export',
'Customer informations' => 'Customer information',
'Customer is' => 'Customer is',
'Customers' => 'Customers',
'Customers list' => 'Customers list',
'Cutomer Name' => 'Cutomer Name',
@@ -218,6 +220,7 @@ return array(
'Date of last order' => 'Date of last order',
'Days before expiration' => 'Days before expiration',
'Deactivate %title module' => 'Deactivate %title module',
'Decimal places' => 'Decimal places',
'Default' => 'Default',
'Default address' => 'Default address',
'Define here this product\'s accessories' => 'Define here this product\'s accessories',
@@ -281,6 +284,7 @@ return array(
'Details' => 'Details',
'Disabled' => 'Disabled',
'Discount' => 'Discount',
'Discount amount' => 'Discount amount',
'Do not use a product template' => 'Do not use a product template',
'Do you really want to add this attribute to all product templates ?' => 'Do you really want to add this attribute to all product templates ?',
'Do you really want to add this feature to all product templates ?' => 'Do you really want to add this feature to all product templates ?',
@@ -492,6 +496,8 @@ return array(
'Folders in %fold' => 'Folders in %fold',
'Format: %fmt' => 'Format: %fmt ',
'Format: %fmt, e.g. %date' => 'Format: %fmt, e.g. %date',
'Free shipping for methods :' => 'Free shipping for methods :',
'Free shipping to countries :' => 'Free shipping to countries :',
'French 19.6% VAT is a tax which add a 19.6% tax to the product price.' => 'French 19.6% VAT is a tax which add a 19.6% tax to the product price.',
'French 19.6% VAT with ecotax is the applicance of the ecotax (on the product price) then the applicance of the 19.6% tax (on the product price + the ecotax amount).' => 'French 19.6% VAT with ecotax is the applicance of the ecotax (on the product price) then the applicance of the 19.6% tax (on the product price + the ecotax amount).',
'From' => 'From',
@@ -570,7 +576,7 @@ return array(
'Manage resource rights' => 'Manage resource rights',
'Manage taxes' => 'Manage taxes',
'Manage the tax rule taxes appliance order' => 'Manage the tax rule taxes appliance order',
'Maximum usage count :' => 'Maximum usage count :',
'Maximum usage count :' => 'Number of usages left:',
'Message created on %date_create. Last modification: %date_change' => 'Message created on %date_create. Last modification: %date_change',
'Message level' => 'Message level',
'Messages which have a level greater or equal to the selected level will be added to the log destinations. ' => 'Messages which have a level greater or equal to the selected level will be added to the log destinations. ',
@@ -682,6 +688,7 @@ return array(
'Product title' => 'Product title',
'Product weight' => 'Product weight',
'Products' => 'Products',
'Products are :' => 'Products are :',
'Products in %cat' => 'Products in %cat',
'Profil' => 'Profile',
'Profile' => 'Profile',
@@ -760,6 +767,8 @@ return array(
'Send files' => 'Send files',
'Sequential number of log line' => 'Sequential number of log line',
'Set as default tax rule' => 'Set as default tax rule',
'Sets the separator for the decimal point' => 'Sets the separator for the decimal point',
'Sets the thousands separator.' => 'Sets the thousands separator.',
'Shipping configuration' => 'Shipping configuration',
'Shipping configuration of delivery module "%title"' => 'Shipping configuration of delivery module "%title"',
'Shipping zone' => 'Shipping zone',
@@ -826,7 +835,10 @@ return array(
'The mailing template in text-only format.' => 'The mailing template in text-only format.',
'The page you\'ve requested was not found. Please check the page address, and try again.' => 'The page you\'ve requested was not found. Please check the page address, and try again.',
'The rate from Euro (Price in Euro * rate = Price in this currency)' => 'The rate from Euro (Price in Euro * rate = Price in this currency)',
'The selected categories :' => 'The selected categories :',
'The selected countries :' => 'Les pays sélectionnés :',
'The selected customer :' => 'The selected customer :',
'The selected products :' => 'The selected products :',
'The server returned a "404 Not Found"' => 'The server returned a "404 Not Found"',
'The symbol, such as &#36;, £, &euro;...' => 'The symbol, such as $, £, €...',
'The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function' => 'The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function',
@@ -919,9 +931,12 @@ return array(
'Update rates' => 'Update rates',
'Update tax rule taxes' => 'Update tax rule taxes',
'Update this image' => 'Update this image',
'Usage count' => 'Usage count',
'Usage count' => 'Usages left',
'Usages left' => 'Usages left',
'Use Ctrl+click to select (or deselect) more that one category' => 'Use Ctrl+click to select (or deselect) more that one category',
'Use Ctrl+click to select (or deselect) more that one country' => 'Utiliser Ctrl+clic pour sélectionner (ou dé-sélectionner) plusieurs pays.',
'Use Ctrl+click to select (or deselect) more that one product' => 'Use Ctrl+click to select (or deselect) more that one product',
'Use Ctrl+click to select (or deselect) more that one shipping method' => 'Use Ctrl+click to select (or deselect) more that one shipping method',
'Use Ctrl+click to select more than one value. You can also <a href="#" class="clear_feature_value" data-id="%id">clear selected values</a>.' => 'Use Ctrl+click to select more than one value. You can also <a href="#" class="clear_feature_value" data-id="%id">clear selected values</a>.',
'Use HTML message defined below' => 'Use HTML message defined below',
'Use Text message defined below' => 'Use Text message defined below',
@@ -980,6 +995,7 @@ return array(
'deactivate' => 'deactivate',
'deactivation' => 'deactivation',
'delete image' => 'delete image',
'eg: . or ,' => 'eg: . or ,',
'en_US' => 'en_US',
'firstname & lastname' => 'firstname & lastname',
'hour in hh:mm:ss format' => 'hour in hh:mm:ss format',

View File

@@ -279,26 +279,21 @@ $(function($){
$.couponManager.onUsageUnlimitedChange = function() {
var $isUnlimited = $('#is-unlimited');
var $maxUsage = $('#max-usage');
if ($maxUsage.val() == -1) {
if ($('#max-usage').val() == -1) {
$isUnlimited.prop('checked', true);
$maxUsage.hide();
$('#max-usage-label').hide();
$('#max-usage-data').hide();
} else {
$isUnlimited.prop('checked', false);
$maxUsage.show();
$('#max-usage-label').show();
$('#max-usage-data').show();
}
$isUnlimited.change(function(){
var $this = $(this);
if ($this.is(':checked')) {
$('#max-usage').hide().val('-1');
$('#max-usage-label').hide();
if ($(this).is(':checked')) {
$('#max-usage-data').hide();
$('#max-usage').val('-1');
} else {
$('#max-usage').show().val('');
$('#max-usage-label').show();
$('#max-usage').val('');
$('#max-usage-data').show();
}
});
};

View File

@@ -101,13 +101,30 @@
<input id="is-unlimited" type="checkbox" name="is-unlimited" {if $value == '' || $value == -1}checked="checked"{/if}>
{intl l='Unlimited number of uses'}
</label>
<label id="max-usage-label" for="max-usage" class="control-label">{intl l='Maximum usage count :'}</label>
<input id="max-usage" type="text" class="form-control" name="{$name}" value="{if $value == ''}-1{else}{$value}{/if}" placeholder="{intl l='Usage count'}">
{if $error}{$message}{/if}
</div>
{/form_field}
<div class="well well-sm" id="max-usage-data">
{form_field form=$form field='maxUsage'}
<div class="form-group {if $error}has-error{/if}">
<label id="max-usage-label" for="max-usage" class="control-label">{intl l='Maximum usage count :'}</label>
<input id="max-usage" type="text" class="form-control" name="{$name}" value="{if $value == ''}-1{else}{$value}{/if}" placeholder="{intl l='Usage count'}">
{if $error}{$message}{/if}
</div>
{/form_field}
{form_field form=$form field='perCustomerUsageCount'}
<div class="form-group {if $error}has-error{/if}" style="margin-bottom: 0;">
{foreach $choices as $choice}
<label class="radio-inline">
<input type="radio" name="{$name}" value="{$choice->value}" {if $value == $choice->data}checked="checked"{/if}>
{$choice->label}
</label>
{/foreach}
</div>
{/form_field}
</div>
{form_field form=$form field='isRemovingPostage'}
<div class="form-group {if $error}has-error{/if}">
<label for="is-removing-postage" class="checkbox control-label">
@@ -118,7 +135,7 @@
</div>
{/form_field}
<div class="free-postage-conditions" style="display: none">
<div class="free-postage-conditions well well-sm" " style="display: none">
{form_field form=$form field='freeShippingForCountries'}
<div class="form-group {if $error}has-error{/if}">
<label for="for-countries-only">{intl l="Free shipping to countries :"}</label>
@@ -132,7 +149,7 @@
{/form_field}
{form_field form=$form field='freeShippingForModules'}
<div class="form-group {if $error}has-error{/if}">
<div class="form-group {if $error}has-error{/if}" style="margin-bottom: 0;">
<label for="for-modules-only">{intl l="Free shipping for methods :"}</label>
<select multiple size="5" class="form-control" id="for-modules-only" name="{$name}">
{foreach $choices as $choice}