MAJ en Thelia 2.3.4

This commit is contained in:
2020-05-03 08:14:07 +02:00
parent 72ddf49e60
commit 35a800ca0e
328 changed files with 9560 additions and 14163 deletions

View File

@@ -85,7 +85,6 @@ class CouponFactory
// Check coupon usage count
if (! $couponModel->isUsageUnlimited()) {
if (null === $customer = $this->facade->getCustomer()) {
throw new UnmatchableConditionException($couponCode);
}

View File

@@ -219,13 +219,10 @@ class CouponManager
/** @var CouponInterface $coupon */
foreach ($coupons as $coupon) {
try {
if ($coupon->isMatching()) {
$couponsKept[] = $coupon;
}
} catch (UnmatchableConditionException $e) {
// ignore unmatchable coupon
continue;
@@ -319,10 +316,8 @@ class CouponManager
public function decrementQuantity(Coupon $coupon, $customerId = null)
{
if ($coupon->isUsageUnlimited()) {
$ret = true;
return true;
} else {
$ret = false;
try {
$usageLeft = $coupon->getUsagesLeft($customerId);
@@ -355,15 +350,13 @@ class CouponManager
->save()
;
$ret = $usageLeft - $newCount;
return $usageLeft - $newCount;
} else {
$usageLeft--;
$coupon->setMaxUsage($usageLeft);
$coupon->setMaxUsage(--$usageLeft);
$coupon->save();
$ret = $usageLeft;
return $usageLeft;
}
}
} catch (\Exception $ex) {
@@ -372,6 +365,58 @@ class CouponManager
}
}
return $ret;
return false;
}
/**
* Add a coupon usage, for the case the related order is canceled.
*
* @param Coupon $coupon
* @param int $customerId
*/
public function incrementQuantity(Coupon $coupon, $customerId = null)
{
if ($coupon->isUsageUnlimited()) {
return true;
} else {
try {
$usageLeft = $coupon->getUsagesLeft($customerId);
// If the coupon usage is per user, remove an entry from coupon customer usage count table
if ($coupon->getPerCustomerUsageCount()) {
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->getCount() > 0) {
$newCount = $ccc->getCount() - 1;
$ccc
->setCount($newCount)
->save();
return $usageLeft - $newCount;
}
} else {
// Ad one usage to coupon
$coupon->setMaxUsage(++$usageLeft);
$coupon->save();
return $usageLeft;
}
} catch (\Exception $ex) {
// Just log the problem.
Tlog::getInstance()->addError(sprintf("Failed to increment coupon %s: %s", $coupon->getCode(), $ex->getMessage()));
}
}
return false;
}
}

View File

@@ -14,7 +14,6 @@ namespace Thelia\Coupon\Type;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\CartItem;
use Thelia\Model\Category;
/**
* Allow to remove an amount from the checkout total
@@ -27,7 +26,7 @@ abstract class AbstractRemove extends CouponAbstract implements AmountAndPercent
/**
* Set the value of specific coupon fields.
*
* @param Array $effects the Coupon effects params
* @param array $effects the Coupon effects params
*/
abstract public function setFieldsValue($effects);
@@ -81,35 +80,6 @@ abstract class AbstractRemove extends CouponAbstract implements AmountAndPercent
return $this;
}
/**
* @inheritdoc
*/
public function exec()
{
// This coupon subtracts the specified amount from the order total
// for each product of the selected categories.
$discount = 0;
$cartItems = $this->facade->getCart()->getCartItems();
/** @var CartItem $cartItem */
foreach ($cartItems as $cartItem) {
if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) {
$categories = $cartItem->getProduct()->getCategories();
/** @var Category $category */
foreach ($categories as $category) {
if (in_array($category->getId(), $this->category_list)) {
$discount += $this->getCartItemDiscount($cartItem);
break;
}
}
}
}
return $discount;
}
/**
* @inheritdoc

View File

@@ -33,7 +33,7 @@ abstract class AbstractRemoveOnAttributeValues extends CouponAbstract implements
/**
* Set the value of specific coupon fields.
* @param Array $effects the Coupon effects params
* @param array $effects the Coupon effects params
*/
abstract public function setFieldsValue($effects);

View File

@@ -15,6 +15,7 @@ namespace Thelia\Coupon\Type;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\CartItem;
use Thelia\Model\Category;
/**
* Allow to remove an amount from the checkout total
@@ -31,7 +32,7 @@ abstract class AbstractRemoveOnCategories extends CouponAbstract implements Amou
/**
* Set the value of specific coupon fields.
*
* @param Array $effects the Coupon effects params
* @param array $effects the Coupon effects params
*/
abstract public function setFieldsValue($effects);

View File

@@ -33,7 +33,7 @@ abstract class AbstractRemoveOnProducts extends CouponAbstract implements Amount
/**
* Set the value of specific coupon fields.
*
* @param Array $effects the Coupon effects params
* @param array $effects the Coupon effects params
*/
abstract public function setFieldsValue($effects);

View File

@@ -25,7 +25,7 @@ interface AmountAndPercentageCouponInterface
{
/**
* Set the value of specific coupon fields.
* @param Array $effects the Coupon effects params
* @param array $effects the Coupon effects params
*/
public function setFieldsValue($effects);
@@ -54,7 +54,13 @@ interface AmountAndPercentageCouponInterface
public function getBaseFieldList($otherFields);
/**
* Check the value of a coupon configuration field
*
* @param string $fieldName
* @param string $fieldValue
* @return string the field value
*
* @throws \InvalidArgumentException is field value is not valid.
*/
public function checkBaseCouponFieldValue($fieldName, $fieldValue);
}

View File

@@ -61,6 +61,12 @@ class RemoveXAmount extends AbstractRemove
*/
public function exec()
{
$cartTotal = $this->facade->getCartTotalTaxPrice($this->isAvailableOnSpecialOffers());
if ($this->amount > $cartTotal) {
return $cartTotal;
}
return $this->amount;
}

View File

@@ -64,7 +64,7 @@ class RemoveXPercent extends AbstractRemove
*/
public function exec()
{
return round($this->facade->getCartTotalTaxPrice($this->isAvailableOnSpecialOffers()) * $this->percentage/100, 2);
return ($this->facade->getCartTotalTaxPrice($this->isAvailableOnSpecialOffers()) * $this->percentage/100);
}
/**