Skip to content

Commit

Permalink
Merge pull request #1167 from shreesh-webkul/gli-2202
Browse files Browse the repository at this point in the history
Added: Confirmation modal when deleting cart rules and while changes credit slip status
  • Loading branch information
rohit053 authored Aug 14, 2024
2 parents 114d53a + 9cb17de commit 1588e4d
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title"><i class="icon icon-exclamation-triangle"></i>&nbsp;{l s='Confirm Delete'}</h4>
{if isset($cartRules)}
<p>{l s='The following cart rules in your selection were created dynamically from refunds or credit slips. Please confirm if you also intend to delete these cart rules?'}</p>
{else}
<p>{l s='Are you sure, you want to delete the selected cart rules?'}</p>

{/if}
</div>
{if isset($cartRules)}
<div class="modal-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>
</th>
<th>
{l s='Cart Rule'}
</th>
<th>
{l s='Reason'}
</th>
<th>
{l s='Order'}
</th>
<th>
{l s='Amount'}
</th>
</tr>
</thead>
{foreach $cartRules as $cartRule}
<tr>
<td>
<input type="checkbox" class="cart_rule_to_delete" value="{$cartRule['id_cart_rule']}" checked>
</td>
<td>
<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$cartRule['id_cart_rule']}" target="_blank">#{$cartRule['id_cart_rule']}</a>
</td>
<td>
{if $cartRule['generated_by'] == CartRule::GENERATED_BY_REFUND}
<b>{l s='Generated against refund'}</b>
(<a href="{$link->getAdminLink('AdminOrderRefundRequests')}&vieworder_return&id_order_return={$cartRule['id_generated_by']}" target="_blank">#{$cartRule['id_generated_by']}</a>)
{else if $cartRule['generated_by'] == CartRule::GENERATED_BY_ORDER_SLIP}
<b>{l s='Generated against credit slip'}</b>
(<a href="{$link->getAdminLink('AdminPdf')}&submitAction=generateOrderSlipPDF&id_order_slip={$cartRule['id_generated_by']}" target="_blank">#{$cartRule['id_generated_by']}</a>)
{/if}
{if !$cartRule['cart_rule']->quantity}
<span class="badge badge-danger">{l s='Used'}</span>
{/if}
</td>
<td>
<a href="{$link->getAdminLink('AdminOrders')}&vieworder&id_order={$cartRule['order']->id}" target="_blank">#{$cartRule['order']->id}</a>
</td>
<td>
{displayPrice price=$cartRule['cart_rule']->reduction_amount currency=$cartRule['cart_rule']->reduction_currency}
</td>

</tr>
{/foreach}
</table>
</div>
</div>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title"><i class="icon icon-exclamation-triangle"></i> {l s='Confirm Delete'}</h4>
<p>{l s='Are you sure, you want to delete this cart rule?'}</p>
</div>
{if isset($cartRule)}
<div class="modal-body">
<div class="row">
<div class="col-sm-4">
<label>{l s='Voucher'}</label>
<p class="control-value">
{$cartRule->code} (<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$cartRule->id}" target="_blank">#{$cartRule->id}</a>)
</p>
</div>
<div class="col-sm-4">
<label>{l s='Reason'}</label>
<p class="control-value">
{if $generatedBy == CartRule::GENERATED_BY_REFUND}
{l s='Generated against refund'}
(<a href="{$link->getAdminLink('AdminOrderRefundRequests')}&vieworder_return&id_order_return={$generatedById}" target="_blank">#{$generatedById}</a>)
{else if $generatedBy == CartRule::GENERATED_BY_ORDER_SLIP}
{l s='Generated against credit slip'}
(<a href="{$link->getAdminLink('AdminPdf')}&submitAction=generateOrderSlipPDF&id_order_slip={$generatedById}" target="_blank">#{$generatedById}</a>)
{/if}
</p>
</div>
<div class="col-sm-4">
<label>{l s='Amount'}</label>
<p class="control-value">{displayPrice price=$cartRule->reduction_amount currency=$cartRule->reduction_currency}</p>
</div>
<div class="col-sm-4">
<label>{l s='Customer'}</label>
<p class="control-value">
{$customer->firstname} {$customer->lastname} (<a href="{$link->getAdminLink('AdminCustomers')}&viewcustomer&id_customer={$customer->id}" target="_blank">#{$customer->id}</a>)
</p>
</div>
<div class="col-sm-4">
<label>{l s='Order'}</label>
<p class="control-value">
{$order->reference} (<a href="{$link->getAdminLink('AdminOrders')}&vieworder&id_order={$order->id}" target="_blank">#{$order->id}</a>)
</p>
</div>
{if !$cartRule->quantity}
<div class="col-sm-4">
<label>{l s='Status'}</label>
<p class="control-value">
<span class="badge badge-danger">{l s='Used'}</span>
</p>
</div>
{/if}
</div>
</div>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @license LICENSE.txt
*}

<a href="{$status_change_link|escape:'html':'UTF-8'}" title="{l s='Change Status'}">
<a href="{$status_change_link|escape:'html':'UTF-8'}" title="{l s='Change Status'}" class="change_status">
<i class="icon-refresh"></i>
{l s='Change Status'}
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title"><i class="icon icon-exclamation-triangle"></i>&nbsp;{l s='Confirm Update'}</h4>
<p>{l s='This action is irreversable, Are you sure you want to change the status?'}</p>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-6">
<label>{l s='Credit Slip'}</label>
<p class="control-value">
<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$orderSlip->id}" target="_blank">#{$orderSlip->id}</a>
</p>
</div>
<div class="col-sm-6">
<label>{l s='Amount'}</label>
<p class="control-value">{displayPrice price=$orderSlip->amount currency=$order->id_currency}</p>
</div>
<div class="col-sm-6">
<label>{l s='Customer'}</label>
<p class="control-value">
{$customer->firstname} {$customer->lastname} (<a href="{$link->getAdminLink('AdminCustomers')}&viewcustomer&id_customer={$customer->id}" target="_blank">#{$customer->id}</a>)
</p>
</div>
<div class="col-sm-6">
<label>{l s='Order'}</label>
<p class="control-value">
{$order->reference} (<a href="{$link->getAdminLink('AdminOrders')}&vieworder&id_order={$order->id}" target="_blank">#{$order->id}</a>)
</p>
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions admin/themes/default/template/modal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<div class="modal-dialog {if isset($modal_class)}{$modal_class}{/if}">
<div class="modal-content">
{if isset($modal_title)}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title">{$modal_title}</h4>
</div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title">{$modal_title}</h4>
</div>
{/if}

{$modal_content}
Expand Down
24 changes: 24 additions & 0 deletions classes/CartRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class CartRuleCore extends ObjectModel
public $date_add;
public $date_upd;

const GENERATED_BY_REFUND = 1;
const GENERATED_BY_ORDER_SLIP = 2;

/**
* @see ObjectModel::$definition
*/
Expand Down Expand Up @@ -1498,4 +1501,25 @@ public static function getCartsRuleByCode($name, $id_lang, $extended = false, $i
return Db::getInstance()->executeS($sql_base.' AND code LIKE \'%'.pSQL($name).'%\'');
}
}

public static function getGeneratedBy($id)
{
if (!$id) {
return false;
}
$response = array();
$sql = 'SELECT `id_order_slip` FROM '._DB_PREFIX_.'order_slip os
WHERE os.`id_cart_rule` = '.(int)$id;
if ($result = Db::getInstance()->getValue($sql)) {
$response['generated_by'] = self::GENERATED_BY_ORDER_SLIP;
$response['id_generated_by'] = $result;
}
$sql = 'SELECT `id_order_return` FROM '._DB_PREFIX_.'order_return o
WHERE o.`return_type` = '.OrderReturn::RETURN_TYPE_CART_RULE.' AND o.`id_return_type` = '.(int)$id;
if ($result = Db::getInstance()->getValue($sql)) {
$response['generated_by'] = self::GENERATED_BY_REFUND;
$response['id_generated_by'] = $result;
}
return $response;
}
}
105 changes: 104 additions & 1 deletion controllers/admin/AdminCartRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function __construct()

$this->context = Context::getContext();

$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'),'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?')));
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'),'icon' => 'icon-trash'));
$this->specificConfirmDelete = false;

$this->fields_list = array(
'id_cart_rule' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
Expand Down Expand Up @@ -143,15 +144,117 @@ public function ajaxProcessLoadCartRules()
echo json_encode(array('html' => $html, 'next_link' => $next_link));
}

public function ajaxProcessInitCartRuleDeleteModal()
{
$response = array('success' => false);
$modalConfirmDelete = $this->createTemplate('modal_confirm_delete.tpl');
$modalClass = 'modal-md';
if ($idCartRule = Tools::getValue('id_cart_rule')) {
if ($generatedByDetails = CartRule::getGeneratedBy($idCartRule)) {
if (Validate::isLoadedObject($objCartRule = new CartRule($idCartRule, $this->context->language->id))) {
if ($generatedByDetails['generated_by'] == CartRule::GENERATED_BY_REFUND) {
$obj = new OrderReturn($generatedByDetails['id_generated_by']);
} else {
$obj = new OrderSlip($generatedByDetails['id_generated_by']);
}
$objOrder = new Order($obj->id_order);
$objCustomer = new Customer($objOrder->id_customer);

$modalConfirmDelete->assign(array(
'generatedBy' => $generatedByDetails['generated_by'],
'generatedById' => $generatedByDetails['id_generated_by'],
'customer' => $objCustomer,
'order' => $objOrder,
'cartRule' => $objCartRule,
'link' => $this->context->link
));
$modalClass = 'modal-lg';
}
}
}
$tpl = $this->createTemplate('modal.tpl');
$tpl->assign(array(
'modal_id' => 'moduleConfirmDelete',
'modal_class' => $modalClass,
'modal_content' => $modalConfirmDelete->fetch(),
'modal_actions' => array(
array(
'type' => 'button',
'class' => 'process_delete btn-primary',
'label' => $this->l('Delete'),
),
),

));
$response['confirm_delete'] = true;
$response['modalHtml'] = $tpl->fetch();
$response['confirm_delete'] = true;
$response['success'] = true;

die(Tools::jsonEncode($response));
}

public function ajaxProcessInitCartRuleBulkDeleteModal()
{
$response = array('success' => false);
$modalConfirmDelete = $this->createTemplate('modal_confirm_bulk_delete.tpl');
if ($idCartRules = Tools::getValue('id_cart_rules')) {
$toConfirm = array();
foreach($idCartRules as $idCartRule) {
if ($ruleDetails = CartRule::getGeneratedBy($idCartRule)) {
$ruleDetails['id_cart_rule'] = $idCartRule;
$objCartRule = new CartRule($idCartRule, $this->context->language->id);
$ruleDetails['cart_rule'] = $objCartRule;
if ($ruleDetails['generated_by'] == CartRule::GENERATED_BY_REFUND) {
$obj = new OrderReturn($ruleDetails['id_generated_by']);
} else {
$obj = new OrderSlip($ruleDetails['id_generated_by']);
}
$objOrder = new Order($obj->id_order);
$ruleDetails['order'] = $objOrder;
$toConfirm[] = $ruleDetails;
}
}
if (count($toConfirm)) {
$modalConfirmDelete->assign(array(
'cartRules' => $toConfirm,
'link' => $this->context->link
));

}
}
$tpl = $this->createTemplate('modal.tpl');
$tpl->assign(array(
'modal_id' => 'moduleConfirmDelete',
'modal_class' => 'modal-md',
'modal_content' => $modalConfirmDelete->fetch(),
'modal_actions' => array(
array(
'type' => 'button',
'class' => 'process_delete btn-primary',
'label' => $this->l('Delete'),
),
),

));
$response['confirm_delete'] = true;
$response['modalHtml'] = $tpl->fetch();
$response['success'] = true;

die(Tools::jsonEncode($response));
}

public function setMedia()
{
parent::setMedia();
Media::addJsDef(
array(
'admin_cart_rule_tab_link' => $this->context->link->getAdminLink('AdminCartRules'),
'room_access_err' => $this->l('You can only select room types which hotel(s) access is provided to this employee.'),
'room_rmv_txt' => $this->l('Unselect below room types'),
)
);
$this->addJS(_PS_JS_DIR_.'admin/cart-rules.js');
$this->addJqueryPlugin(array('typewatch', 'fancybox', 'autocomplete'));
}

Expand Down
Loading

0 comments on commit 1588e4d

Please sign in to comment.