Merge pull request #543 from roadster31/sales
in_use parameter added to the coupon loop
This commit is contained in:
@@ -270,6 +270,6 @@ class Session extends BaseSession
|
|||||||
*/
|
*/
|
||||||
public function getConsumedCoupons()
|
public function getConsumedCoupons()
|
||||||
{
|
{
|
||||||
return $this->get('thelia.consumed_coupons');
|
return $this->get('thelia.consumed_coupons', array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use Thelia\Type\TypeCollection;
|
|||||||
abstract class BaseLoop
|
abstract class BaseLoop
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\HttpFoundation\Request
|
* @var \Thelia\Core\HttpFoundation\Request
|
||||||
*/
|
*/
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
return new ArgumentCollection(
|
return new ArgumentCollection(
|
||||||
Argument::createIntListTypeArgument('id'),
|
Argument::createIntListTypeArgument('id'),
|
||||||
Argument::createBooleanOrBothTypeArgument('is_enabled'),
|
Argument::createBooleanOrBothTypeArgument('is_enabled'),
|
||||||
|
Argument::createBooleanTypeArgument('in_use'),
|
||||||
new Argument(
|
new Argument(
|
||||||
'order',
|
'order',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
@@ -86,6 +87,18 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
$search->filterByIsEnabled($isEnabled ? true : false);
|
$search->filterByIsEnabled($isEnabled ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$inUse = $this->getInUse();
|
||||||
|
|
||||||
|
if ($inUse !== null) {
|
||||||
|
// Get the code of coupons currently in use
|
||||||
|
$consumedCoupons = $this->request->getSession()->getConsumedCoupons();
|
||||||
|
|
||||||
|
// Get only matching coupons.
|
||||||
|
$criteria = $inUse ? Criteria::IN : Criteria::NOT_IN;
|
||||||
|
|
||||||
|
$search->filterByCode($consumedCoupons, $criteria);
|
||||||
|
}
|
||||||
|
|
||||||
$search->addAsColumn('days_left', 'DATEDIFF('.CouponTableMap::EXPIRATION_DATE.', CURDATE()) - 1');
|
$search->addAsColumn('days_left', 'DATEDIFF('.CouponTableMap::EXPIRATION_DATE.', CURDATE()) - 1');
|
||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
@@ -202,6 +215,12 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
$freeShippingForModulesIds[] = $couponModule->getModuleId();
|
$freeShippingForModulesIds[] = $couponModule->getModuleId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If and only if the coupon is currently in use, get the coupon discount. Calling exec() on a coupon
|
||||||
|
// which is not currently in use may apply coupon on the cart. This is true for coupons such as FreeProduct,
|
||||||
|
// which adds a product to the cart.
|
||||||
|
$discount = $couponManager->isInUse() ? $couponManager->exec() : 0;
|
||||||
|
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID", $coupon->getId())
|
->set("ID", $coupon->getId())
|
||||||
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
|
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
|
||||||
@@ -224,6 +243,7 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
->set("SERVICE_ID", $couponManager->getServiceId())
|
->set("SERVICE_ID", $couponManager->getServiceId())
|
||||||
->set("FREE_SHIPPING_FOR_COUNTRIES_LIST", implode(',', $freeShippingForCountriesIds))
|
->set("FREE_SHIPPING_FOR_COUNTRIES_LIST", implode(',', $freeShippingForCountriesIds))
|
||||||
->set("FREE_SHIPPING_FOR_MODULES_LIST", implode(',', $freeShippingForModulesIds))
|
->set("FREE_SHIPPING_FOR_MODULES_LIST", implode(',', $freeShippingForModulesIds))
|
||||||
|
->set("DISCOUNT_AMOUNT", $discount)
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param true $perCustomerUsageCount
|
* @param true $perCustomerUsageCount
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setPerCustomerUsageCount($perCustomerUsageCount)
|
public function setPerCustomerUsageCount($perCustomerUsageCount)
|
||||||
{
|
{
|
||||||
@@ -425,14 +426,14 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
* This methods checks a field value. If the field has a correct value, this value is returned
|
* This methods checks a field value. If the field has a correct value, this value is returned
|
||||||
* Otherwise, an InvalidArgumentException describing the problem should be thrown.
|
* Otherwise, an InvalidArgumentException describing the problem should be thrown.
|
||||||
*
|
*
|
||||||
* This method should be ovveriden to be useful.
|
* This method should be overriden to be useful.
|
||||||
*
|
*
|
||||||
* @param $fieldName
|
* @param string $fieldName
|
||||||
* @param $fieldValue
|
* @param string $fieldValue
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \InvalidArgumentException if the field valiue is not valid.
|
* @throws \InvalidArgumentException if the field value is not valid.
|
||||||
*/
|
*/
|
||||||
protected function checkCouponFieldValue($fieldName, $fieldValue)
|
protected function checkCouponFieldValue(/** @noinspection PhpUnusedParameterInspection */ $fieldName, $fieldValue)
|
||||||
{
|
{
|
||||||
return $fieldValue;
|
return $fieldValue;
|
||||||
}
|
}
|
||||||
@@ -507,4 +508,11 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
{
|
{
|
||||||
// Does nothing. Override this function as needed.
|
// Does nothing. Override this function as needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isInUse() {
|
||||||
|
return in_array(
|
||||||
|
$this->code,
|
||||||
|
$this->facade->getRequest()->getSession()->getConsumedCoupons()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,15 +192,15 @@ interface CouponInterface
|
|||||||
public function isExpired();
|
public function isExpired();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return effects generated by the coupon
|
* Return an amount thant will be subtracted to the cart total, or zero.
|
||||||
* A positive value
|
|
||||||
*
|
*
|
||||||
* Effects could also affect something else than the final Checkout price
|
* This method could also perform something else than the calculating an amount to subtract from the cart. It may
|
||||||
* FacadeInterface $facade could be used to directly pass a Session value
|
* add a product to the cart, for example. In this case, an amount of 0 will be returned.
|
||||||
* some would wish to modify
|
|
||||||
* Hence affecting a wide variety of Thelia elements
|
|
||||||
*
|
*
|
||||||
* @return float Amount removed from the Total Checkout
|
* WARNING: this method could be called several times, so perform suitable checks before performing cart
|
||||||
|
* manipulations, so that the coupon effect will not be applied several times.
|
||||||
|
*
|
||||||
|
* @return float Amount removed from the cart total
|
||||||
*/
|
*/
|
||||||
public function exec();
|
public function exec();
|
||||||
|
|
||||||
@@ -244,4 +244,8 @@ interface CouponInterface
|
|||||||
*/
|
*/
|
||||||
public function clear();
|
public function clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool true if the coupon is currently in use in the current order process, false otherwise
|
||||||
|
*/
|
||||||
|
public function isInUse();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
</caption>
|
</caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>{intl l="ID"}</th>
|
||||||
<th colspan="2">{intl l="Language name"}</th>
|
<th colspan="2">{intl l="Language name"}</th>
|
||||||
<th>{intl l="ISO 639 Code"}</th>
|
<th>{intl l="ISO 639 Code"}</th>
|
||||||
<th>{intl l="Locale"}</th>
|
<th>{intl l="Locale"}</th>
|
||||||
@@ -58,6 +59,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{loop type="lang" name="lang.list" backend_context="1"}
|
{loop type="lang" name="lang.list" backend_context="1"}
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>{$ID}</td>
|
||||||
<td class="text-center"><img src="{image file="assets/img/flags/{$CODE}.png"}" alt="{$CODE}" /></td>
|
<td class="text-center"><img src="{image file="assets/img/flags/{$CODE}.png"}" alt="{$CODE}" /></td>
|
||||||
<td>{$TITLE}</td>
|
<td>{$TITLE}</td>
|
||||||
<td>{$CODE}</td>
|
<td>{$CODE}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user