PHP-CS fixer
This commit is contained in:
@@ -633,8 +633,9 @@ class CouponController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = new ResponseRest($couponManager->drawBackOfficeInputs());
|
$response = new ResponseRest($couponManager->drawBackOfficeInputs());
|
||||||
}
|
} else {
|
||||||
else {
|
// Return an empty response if the service ID is not defined
|
||||||
|
// Typically, when the user chooses "Please select a coupon type"
|
||||||
$response = new ResponseRest('');
|
$response = new ResponseRest('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace Thelia\Core\Event;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SessionEvent
|
* Class SessionEvent
|
||||||
* @package Thelia\Core\Event
|
* @package Thelia\Core\Event
|
||||||
@@ -71,5 +70,4 @@ class SessionEvent extends ActionEvent
|
|||||||
return $this->session;
|
return $this->session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
|||||||
use Thelia\Core\TheliaKernelEvents;
|
use Thelia\Core\TheliaKernelEvents;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SessionListener
|
* Class SessionListener
|
||||||
* @package Thelia\Core\EventListener
|
* @package Thelia\Core\EventListener
|
||||||
@@ -79,4 +78,4 @@ class SessionListener implements EventSubscriberInterface
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Core;
|
namespace Thelia\Core;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TheliaKernelEvents
|
* Class TheliaKernelEvents
|
||||||
* @package Thelia\Core
|
* @package Thelia\Core
|
||||||
@@ -23,4 +22,4 @@ final class TheliaKernelEvents
|
|||||||
|
|
||||||
const SESSION = "thelia_kernel.session";
|
const SESSION = "thelia_kernel.session";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,7 +402,8 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getInputName() {
|
public function getInputName()
|
||||||
|
{
|
||||||
return "Please override getInputName() method";
|
return "Please override getInputName() method";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,33 +435,32 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \InvalidArgumentException if the field valiue is not valid.
|
* @throws \InvalidArgumentException if the field valiue is not valid.
|
||||||
*/
|
*/
|
||||||
protected function checkCouponFieldValue($fieldName, $fieldValue) {
|
protected function checkCouponFieldValue($fieldName, $fieldValue)
|
||||||
|
{
|
||||||
return $fieldValue;
|
return $fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper to get the value of a standard field name
|
* A helper to get the value of a standard field name
|
||||||
*
|
*
|
||||||
* @param string $fieldName the field name
|
* @param string $fieldName the field name
|
||||||
* @param array $data the input form data (e.g. $form->getData())
|
* @param array $data the input form data (e.g. $form->getData())
|
||||||
* @param mixed $defaultValue the default value if the field is not found.
|
* @param mixed $defaultValue the default value if the field is not found.
|
||||||
*
|
*
|
||||||
* @return mixed the input value, or the default one
|
* @return mixed the input value, or the default one
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the field is not found, and no default value has been defined.
|
* @throws \InvalidArgumentException if the field is not found, and no default value has been defined.
|
||||||
*/
|
*/
|
||||||
protected function getCouponFieldValue($fieldName, $data, $defaultValue = null) {
|
protected function getCouponFieldValue($fieldName, $data, $defaultValue = null)
|
||||||
|
{
|
||||||
if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) {
|
if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) {
|
||||||
|
|
||||||
return $this->checkCouponFieldValue(
|
return $this->checkCouponFieldValue(
|
||||||
$fieldName,
|
$fieldName,
|
||||||
$data[self::COUPON_DATASET_NAME][$fieldName]
|
$data[self::COUPON_DATASET_NAME][$fieldName]
|
||||||
);
|
);
|
||||||
}
|
} elseif (null !== $defaultValue) {
|
||||||
else if (null !== $defaultValue) {
|
|
||||||
return $defaultValue;
|
return $defaultValue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName));
|
throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -468,10 +468,11 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
/**
|
/**
|
||||||
* A helper to create an standard field name that will be used in the coupon form
|
* A helper to create an standard field name that will be used in the coupon form
|
||||||
*
|
*
|
||||||
* @param string $fieldName the field name
|
* @param string $fieldName the field name
|
||||||
* @return string the complete name, ready to be used in a form.
|
* @return string the complete name, ready to be used in a form.
|
||||||
*/
|
*/
|
||||||
protected function makeCouponFieldName($fieldName) {
|
protected function makeCouponFieldName($fieldName)
|
||||||
|
{
|
||||||
return sprintf("%s[%s][%s]", CouponCreationForm::COUPON_CREATION_FORM_NAME, self::COUPON_DATASET_NAME, $fieldName);
|
return sprintf("%s[%s][%s]", CouponCreationForm::COUPON_CREATION_FORM_NAME, self::COUPON_DATASET_NAME, $fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,20 +481,22 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getFieldList() {
|
protected function getFieldList()
|
||||||
|
{
|
||||||
return [self::AMOUNT_FIELD_NAME];
|
return [self::AMOUNT_FIELD_NAME];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the effect array from the list of fields
|
* Create the effect array from the list of fields
|
||||||
*
|
*
|
||||||
* @param array $data the input form data (e.g. $form->getData())
|
* @param array $data the input form data (e.g. $form->getData())
|
||||||
* @return array a filedName => fieldValue array
|
* @return array a filedName => fieldValue array
|
||||||
*/
|
*/
|
||||||
public function getEffects($data) {
|
public function getEffects($data)
|
||||||
|
{
|
||||||
$effects = [];
|
$effects = [];
|
||||||
|
|
||||||
foreach($this->getFieldList() as $fieldName) {
|
foreach ($this->getFieldList() as $fieldName) {
|
||||||
$effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data);
|
$effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace Thelia\Coupon\Type;
|
|||||||
use Propel\Runtime\Collection\ObjectCollection;
|
use Propel\Runtime\Collection\ObjectCollection;
|
||||||
use Thelia\Condition\ConditionCollection;
|
use Thelia\Condition\ConditionCollection;
|
||||||
use Thelia\Coupon\FacadeInterface;
|
use Thelia\Coupon\FacadeInterface;
|
||||||
use Thelia\Form\CouponCreationForm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Coupon ready to be processed in a Checkout process
|
* Represents a Coupon ready to be processed in a Checkout process
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace Thelia\Coupon\Type;
|
|||||||
|
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\Coupon\FacadeInterface;
|
use Thelia\Coupon\FacadeInterface;
|
||||||
|
use Thelia\Model\CartItem;
|
||||||
|
use Thelia\Model\Category;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow to remove an amount from the checkout total
|
* Allow to remove an amount from the checkout total
|
||||||
@@ -29,7 +31,7 @@ class RemoveAmountOnCategories extends CouponAbstract
|
|||||||
/** @var string Service Id */
|
/** @var string Service Id */
|
||||||
protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories';
|
protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories';
|
||||||
|
|
||||||
var $category_list = array();
|
public $category_list = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
@@ -105,8 +107,29 @@ class RemoveAmountOnCategories extends CouponAbstract
|
|||||||
*/
|
*/
|
||||||
public function exec()
|
public function exec()
|
||||||
{
|
{
|
||||||
// TODO !!!
|
// This coupon subtracts the specified amount from the order total
|
||||||
return $this->amount;
|
// for each product of the selected categories.
|
||||||
|
$discount = 0;
|
||||||
|
|
||||||
|
$cartItems = $this->facade->getCart()->getCartItems();
|
||||||
|
|
||||||
|
/** @var CartItem $cartItem */
|
||||||
|
foreach ($cartItems as $cartItem) {
|
||||||
|
|
||||||
|
$categories = $cartItem->getProduct()->getCategories();
|
||||||
|
|
||||||
|
/** @var Category $category */
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
|
||||||
|
if (in_array($category->getId(), $this->category_list)) {
|
||||||
|
$discount += $cartItem->getQuantity() * $this->amount;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $discount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function drawBackOfficeInputs()
|
public function drawBackOfficeInputs()
|
||||||
@@ -131,11 +154,11 @@ class RemoveAmountOnCategories extends CouponAbstract
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getFieldList() {
|
protected function getFieldList()
|
||||||
|
{
|
||||||
return [self::AMOUNT_FIELD_NAME, self::CATEGORIES_LIST];
|
return [self::AMOUNT_FIELD_NAME, self::CATEGORIES_LIST];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@@ -151,8 +174,7 @@ class RemoveAmountOnCategories extends CouponAbstract
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
} elseif ($fieldName === self::CATEGORIES_LIST) {
|
||||||
else if ($fieldName === self::CATEGORIES_LIST) {
|
|
||||||
if (empty($fieldValue)) {
|
if (empty($fieldValue)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
Translator::getInstance()->trans(
|
Translator::getInstance()->trans(
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ class RemoveXAmount extends CouponAbstract
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getFieldList() {
|
protected function getFieldList()
|
||||||
|
{
|
||||||
return [self::AMOUNT_FIELD_NAME];
|
return [self::AMOUNT_FIELD_NAME];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,4 +94,4 @@ class RemoveXAmount extends CouponAbstract
|
|||||||
return $fieldValue;
|
return $fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,8 @@ class RemoveXPercent extends CouponAbstract
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getFieldList() {
|
protected function getFieldList()
|
||||||
|
{
|
||||||
return [self::INPUT_PERCENTAGE_NAME];
|
return [self::INPUT_PERCENTAGE_NAME];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user