Merge branch 'ticket-12197-NewDiscountAdminOrder' into develop

This commit is contained in:
Marion Muszynski 2017-01-09 12:04:13 +01:00
commit 1146df59c8
2 changed files with 27 additions and 10 deletions

View File

@ -344,7 +344,7 @@ class AdminOrders extends AdminTab
$this->_errors[] = Tools::displayError('An error occurred during deletion of product customization.').' '.$id_customization;
}
// E-mail params
if ((isset($_POST['generateCreditSlip']) OR isset($_POST['generateDiscount'])) AND !sizeof($this->_errors))
if ((isset($_POST['generateCreditSlip']) OR isset($_POST['generateDiscount']) OR isset($_POST['generateDiscount2'])) AND !sizeof($this->_errors))
{
$customer = new Customer((int)($order->id_customer));
$params['{lastname}'] = $customer->lastname;
@ -416,6 +416,22 @@ class AdminOrders extends AdminTab
}
}
// Generate voucher 2 @Addition Antadis
if (isset($_POST['generateDiscount2']) AND !sizeof($this->_errors))
{
if (!$voucher = Discount::createOrderDiscount($order, $full_product_list, $full_quantity_list, $this->l('Geste commercial concernant la commande '), isset($_POST['shippingBack']),0,0,5))
$this->_errors[] = Tools::displayError('Cannot generate voucher');
else
{
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
$params['{voucher_num}'] = $voucher->name;
@Mail::Send((int)($order->id_lang), 'refundorder', Mail::l('New voucher regarding your order'),
$params, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL,
NULL, _PS_MAIL_DIR_, true);
}
}
// Generate credit slip
if (isset($_POST['generateCreditSlip']) AND !sizeof($this->_errors))
{
@ -1103,6 +1119,7 @@ class AdminOrders extends AdminTab
echo '
<input type="checkbox" id="generateCreditSlip" name="generateCreditSlip" class="button" onclick="toogleShippingCost(this)" />&nbsp;<label for="generateCreditSlip" style="float:none; font-weight:normal;">'.$this->l('Generate a credit slip').'</label><br />
<input type="checkbox" id="generateDiscount" name="generateDiscount" class="button" onclick="toogleShippingCost(this)" />&nbsp;<label for="generateDiscount" style="float:none; font-weight:normal;">'.$this->l('Bon 10 pour produit manquant').'</label><br />
<input type="checkbox" id="generateDiscount2" name="generateDiscount2" class="button" onclick="toogleShippingCost(this)" />&nbsp;<label for="generateDiscount2" style="float:none; font-weight:normal;">'.$this->l('Bon 5 pour produit manquant').'</label><br />
<span id="spanShippingBack" style="display:none;"><input type="checkbox" id="shippingBack" name="shippingBack" class="button" />&nbsp;<label for="shippingBack" style="float:none; font-weight:normal;">'.$this->l('Repay shipping costs').'</label><br /></span>';
if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Configuration::get('PS_ORDER_RETURN')))
echo '

View File

@ -3,7 +3,7 @@ class Discount extends DiscountCore
{
public $orders;
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0)
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0, $value = 10)
{
$languages = Language::getLanguages($order);
@ -19,7 +19,7 @@ class Discount extends DiscountCore
// elseif ($discount['id_discount_type'] == 2)
// $total -= ($discount['value'] * ($total_tmp / $order->total_products_wt));
// }
$total = 10;
// $total = 10;
// if ($shipping_cost)
// $total += $order->total_shipping;
@ -28,7 +28,7 @@ class Discount extends DiscountCore
$voucher->id_discount_type = 2;
foreach ($languages as $language)
$voucher->description[$language['id_lang']] = strval($name).(int)($order->id);
$voucher->value = (float)($total);
$voucher->value = (float)($value);
$voucher->name = 'V0C'.(int)($order->id_customer).'O'.(int)($order->id);
$voucher->id_customer = (int)($order->id_customer);
$voucher->id_currency = (int)($order->id_currency);
@ -67,7 +67,7 @@ class Discount extends DiscountCore
{
if ( $admDisplay )
return parent::getCategories($id_discount);
$categories = parent::getCategories($id_discount);
// if only root category is checked return all categories.
if ( count($categories == 1) ){
@ -102,8 +102,8 @@ class Discount extends DiscountCore
if ((time() < $date_start OR time() > $date_end) AND !$cart->OrderExists()) return 0;
$products = $cart->getProducts();
foreach ($products AS $product)
foreach ($products AS $product)
$totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
if ($this->minimal > 0 AND $totalAmount < $this->minimal)
@ -114,7 +114,7 @@ class Discount extends DiscountCore
case 1:
$amount = 0;
$percentage = $this->value / 100;
foreach ($products AS $product)
foreach ($products AS $product)
if ($this->cumulable_reduction OR (!$product['reduction_applies'] AND !$product['on_sale']))
$amount += ($useTax? $product['total_wt'] : $product['total']) * $percentage;
return $amount;
@ -133,7 +133,7 @@ class Discount extends DiscountCore
// Main return
$value = 0;
foreach ($products AS $product)
$value = $this->value;
$value = $this->value;
// Return 0 if there are no applicable categories
return $value;
@ -143,5 +143,5 @@ class Discount extends DiscountCore
}
return 0;
}
}