Instantly share code, notes, and snippets.
Created
October 19, 2022 09:56
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save AshlinRejo/0c0f7826ec6ca46f381e0c65dcb86c1b to your computer and use it in GitHub Desktop.
J2Store subscription: Alert box for Subscription cancel button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('_JEXEC') or die('Restricted access'); | |
unset ( $listOrder ); | |
$listOrder = $vars->data->state->get ( 'filter_order', 'tbl.user_id' ); | |
$listDirn = $vars->data->state->get ( 'filter_order_Dir' ); | |
$items = $vars->data->subscription; | |
$j2_params = J2Store::config(); | |
$app = JFactory::getApplication(); | |
$subsStatusObj = \J2Store\Subscription\Helper\SubscriptionStatus::getInstance(); | |
?> | |
<div class="tab-pane" id="subscription-tab"> | |
<div class="j2store_subscriptions_con table-responsive"> | |
<div class="j2store_susbcription_message hide"> | |
</div> | |
<form class="form-horizontal" method="post" action="" name="adminForm" id="adminForm" > | |
<br/> | |
<br /> | |
<table class="table table-striped table-bordered"> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_STATUS'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_NAME'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_USER'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_START_ON'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_END_ON'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_APP_SUBSCRIPTIONPRODUCT_NEXT_RENEWAL_ON'); ?> | |
</th> | |
<th><?php echo JText::_('J2STORE_ACTIONS'); ?> | |
</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
if(!empty($items)): | |
foreach ($items as $item):?> | |
<tr> | |
<td> | |
<?php $viewUrl = JUri::base().'index.php?option=com_j2store&view=app&task=view&appTask=viewMySubscription&tmpl=component&id='.$vars->id.'&sid='.$item->j2store_subscription_id; ?> | |
<?php //fa fa-list-alt | |
echo J2StorePopup::popup($viewUrl, $item->j2store_subscription_id, array('class'=>'')); ?> | |
</td> | |
<td><?php | |
$status = $subsStatusObj->getStatus($item->status); | |
if(isset($status->status_name)){ | |
?> | |
<span class="label <?php echo $status->status_cssclass; ?> order-state-label"> | |
<?php echo JText::_($status->status_name); ?> | |
</span> | |
<?php | |
} else { | |
echo $item->status; | |
} | |
?></td> | |
<td><?php | |
echo $item->orderitem_name; | |
echo J2Store::plugin()->eventWithHtml('DisplayAdditionalContentInSubscriptionList', array($item) ); | |
?> | |
</td> | |
<td><?php | |
$userDetails = JFactory::getUser($item->user_id); | |
echo $userDetails->get('name'); | |
echo "<br>"; | |
echo $userDetails->get('email'); | |
?></td> | |
<td><?php | |
$tz = JFactory::getConfig()->get('offset'); | |
$date = JFactory::getDate($item->start_on, $tz); | |
echo $date->format($j2_params->get('date_format', JText::_('DATE_FORMAT_LC1')), true); | |
?> | |
</td> | |
<td><?php | |
if($item->subscription_length > 0) { | |
$tz = JFactory::getConfig()->get('offset'); | |
$date = JFactory::getDate($item->end_on, $tz); | |
echo $date->format($j2_params->get('date_format', JText::_('DATE_FORMAT_LC1')), true); | |
} else { | |
echo JText::_('COM_J2STORE_PRODUCT_SUBSCRIPTION_NEVER_EXPIRE'); | |
} | |
?> | |
</td> | |
<td><?php | |
if ($item->next_payment_on < $item->end_on || $item->subscription_length == 0) { | |
$tz = JFactory::getConfig()->get('offset'); | |
$date = JFactory::getDate($item->next_payment_on, $tz); | |
echo $date->format($j2_params->get('date_format', JText::_('DATE_FORMAT_LC1')), true); | |
echo "<br>"; | |
$renewal_amount = $vars->model->getRenewalAmount($item); | |
echo J2Store::currency()->format($renewal_amount['renewal_amount'], $item->currency_code, $item->currency_value); | |
} else { | |
echo '-'; | |
} | |
?> | |
</td> | |
<td data-app_id="<?php echo $vars->id; ?>"> | |
<?php | |
$support_trial = $vars->model->hasTrialSupport($item->payment_method); | |
$display_card_update = $vars->model->isDisplayCardUpdate($item); | |
if(($item->status == 'card_expired' || $display_card_update) && $support_trial){ | |
?> | |
<?php $link = JURI::root().'index.php?option=com_j2store&view=app&task=view&appTask=updateSubscriptionPaymentCard&id='.$vars->id.'&sid='.$item->j2store_subscription_id; ?> | |
<a class="btn btn-primary subscription_update_card_btn" href="<?php echo $link; ?>"> | |
<?php echo JText::_('J2STORE_SUBSCRIPTION_UPDATE_CARD_DETAILS_BUTTON_LABEL'); ?> | |
</a> | |
<?php | |
} | |
$variant_table = F0FTable::getAnInstance('Variant','J2StoreTable')->getClone(); | |
$variant_table->load(array( | |
'j2store_variant_id' => $item->variant_id | |
)); | |
$disable_cancel = false; | |
if(isset($variant_table->params)){ | |
$registry = new JRegistry(); | |
$registry->loadString($variant_table->params); | |
$subscriptionproduct = $registry->get('subscriptionproduct',array()); | |
$disable_cancel = isset($subscriptionproduct->disable_cancel)? $subscriptionproduct->disable_cancel: false; | |
} | |
if(!$disable_cancel && ($item->status == 'active' || $item->status == 'in_trial')){ | |
?> | |
<button type="button" class="btn btn-warning" onclick="cancelSubscription('<?php echo $item->j2store_subscription_id; ?>')"><?php echo JText::_('J2STORE_SUBSCRIPTIONAPP_CANCEL'); ?></button> | |
<?php | |
} | |
$showRenewalBtn = $vars->model->hasRenew($item); | |
if($showRenewalBtn){ | |
?> | |
<?php $link = JRoute::_('index.php?option=com_j2store&view=myprofile&profileTask=renew&sid='.$item->j2store_subscription_id); ?> | |
<a class="btn btn-primary" href="<?php echo $link;?>"><?php echo JText::_('J2STORE_SUBSCRIPTIONAPP_RENEW'); ?></a> | |
<?php | |
} | |
// To load additional action through plugin | |
$subscriptionOrder = F0FTable::getAnInstance('Order' ,'J2StoreTable')->getClone(); | |
$subscriptionOrder->load(array('order_id' => $item->subscription_order_id)); | |
$parentOrder = F0FTable::getAnInstance('Order' ,'J2StoreTable')->getClone(); | |
$parentOrder->load(array('order_id' => $item->order_id)); | |
echo J2Store::plugin()->eventWithHtml('DisplayAdditionalActionInSubscription', array( $subscriptionOrder, $parentOrder, $item ) ); //$item => Subscription | |
?> | |
</td> | |
</tr> | |
<?php endforeach;?> | |
<?php else:?> | |
<tr> | |
<td colspan="4"><?php echo JText::_('J2STORE_NO_ITEMS_FOUND');?></td> | |
</tr> | |
<?php endif;?> | |
</tbody> | |
</table> | |
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" /> | |
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" /> | |
<input type="hidden" name="task" value="view" /> | |
</form> | |
</div> | |
<script type="text/javascript"> | |
if(typeof(j2store) == 'undefined') { | |
var j2store = {}; | |
} | |
if(typeof(jQuery) != 'undefined') { | |
jQuery.noConflict(); | |
} | |
if(typeof(j2store.jQuery) == 'undefined') { | |
j2store.jQuery = jQuery.noConflict(); | |
} | |
function cancelSubscription(id){ | |
(function($) { | |
let text = "You are canceling the subscription. Are you sure?"; | |
if (confirm(text) == true) { | |
$.ajax({ | |
type : 'post', | |
url : '<?php echo JUri::root(); ?>index.php', | |
data : { | |
'option': 'com_j2store', | |
'view': 'apps', | |
'task': 'view', | |
'appTask': 'cancelSubscription', | |
'id': '<?php echo $vars->id; ?>', | |
'sid': id | |
}, | |
dataType : 'json', | |
success : function(data) { | |
if(data.status == '1'){ | |
$('.j2store_susbcription_message').html(data.message); | |
$('.j2store_susbcription_message').show(); | |
location.reload(); | |
} else { | |
$('.j2store_susbcription_message').html(data.message); | |
$('.j2store_susbcription_message').show(); | |
} | |
} | |
}); | |
} | |
})(j2store.jQuery); | |
} | |
</script> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment