Added RemoveAmountOnCategories coupon type
This commit is contained in:
81
core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php
Normal file
81
core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
/**
|
||||
* Allow to remove an amount from the checkout total
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveAmountOnCategories extends CouponAbstract
|
||||
{
|
||||
const CATEGORIES_LIST = 'categories';
|
||||
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories';
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->facade
|
||||
->getTranslator()
|
||||
->trans('Fixed amount discount on selected categories', array(), 'coupon');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->facade
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'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.',
|
||||
array(),
|
||||
'coupon'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return effects generated by the coupon
|
||||
* A negative value
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/type-fragments/remove-amount-on-categories.html', [
|
||||
'amount_field_name' => self::INPUT_AMOUNT_NAME,
|
||||
'amount_value' => $this->amount,
|
||||
|
||||
'categories_field_name' => self::CATEGORIES_LIST,
|
||||
'categories_values' => isset($this->values[self::CATEGORIES_LIST]) ? $this->values[self::CATEGORIES_LIST] : array()
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<div class="form-group input-{$fieldName}">
|
||||
<label for="{$amount_field_name}" class="control-label">{intl l="Discount amount"}</label>
|
||||
<div class="input-group">
|
||||
<input id="{$amount_field_name}" type="money" class="form-control" name="thelia_coupon_creation[{$amount_field_name}]" value="{$amount_value}" placeholder="14.50">
|
||||
{loop type="currency" name="get-symbol" default_only="true"}
|
||||
<div class="input-group-addon">{$SYMBOL}</div>
|
||||
{/loop}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="{$categories_field_name}-value">{intl l="Applies to products in categories :"}</label>
|
||||
<select required multiple size="5" class="form-control" id="{$categories_field_name}-value" name="{$categories_field_name}[value][]">
|
||||
{loop type="category-tree" category=0 name="list-of-categories" backend_context="1"}
|
||||
<option style="padding-left: {$LEVEL * 20}px" value="{$ID}" {if in_array($ID, $categories_values)}selected="selected"{/if}>{$TITLE}</option>
|
||||
{/loop}
|
||||
</select>
|
||||
<span class="label-help-block">{intl l='Use Ctrl+click to select (or deselect) more that one category'}</span>
|
||||
</div>
|
||||
Reference in New Issue
Block a user