is it possible to insert coupon in cart module?

  • Posts: 170
  • Thank you received: 7
2 years 2 months ago #339577

hi
i want my user can insert his coupon in a field in cart module. it seems this is not possible in current hikashop cart module. can i do that with some php code change?

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
2 years 2 months ago #339581

Hi,

There is indeed no option for that.

You can try to do itt with such code :

<?php
$cartClass= hikashop_get('class.cart');
$cart = $cartClass->getFullCart();
if(empty($cart->coupon)) {
global $Itemid;
$url_itemid= '';
if(!empty($Itemid)) $url_itemid = '&Itemid='.$Itemid;
 ?>
<form action="<?php echo hikashop_completeLink('product&task=updatecart'.$url_itemid); ?>">
<input type="text" name="coupon" value="" onchange="this.form.submit();" />
</form>
<?php } ?>

You'll want to place this outside of the form in the product / cart view file via the menu Display>views

The following user(s) said Thank You: sadaf3d

Please Log in or Create an account to join the conversation.

  • Posts: 170
  • Thank you received: 7
2 years 2 months ago #339600

1-can you check your code? i copy your code to correct path but it is not work. it is render empty field for input coupon and when i enter the valid coupon and press Enter or click on the cart , it is only redirect to hikashop checkout link without change total price or do anythink. it is maybe i set some hikashop property or configuration incompatible with your code?
simply i want my user can input his coupon in cart module and then change the total price and then redirect user to payment gateway.
2-is it possible add another button to redirect to payment directly without go to check out?

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
2 years 2 months ago #339606

Hi,

1. The code I wrote to you is fine. However, while trying it, I found that there is some code that needs to be changed in HikaShop for this to work.
The code:

$used_data = array('form' => $formData, 'type' => $type);
				$status = $cartClass->update($formData, 0, $add, $type, true, false, $cart_id);
needs to change to:
if(count($formData)) {
				$used_data = array('form' => $formData, 'type' => $type);
				$status = $cartClass->update($formData, 0, $add, $type, true, false, $cart_id);
			}
in the file components/com_hikashop/controllers/product.php and then it works fine and add the coupon to the cart.
We'll add that change on our end for the next version of HikaShop.

2. It depends on how your checkout workflow is configured.
If the user has to fill the guest form or login or register, then it won't be possible.
Otherwise, you can do so like that:
<?php
global $Itemid;
$url_itemid= '';
if(!empty($Itemid)) $url_itemid = '&Itemid='.$Itemid;
 ?>
<a href="<?php echo hikashop_completeLink('checkout&task=confirm'.$url_itemid); ?>" class="hikabtn">go to payment</a>

The following user(s) said Thank You: sadaf3d

Please Log in or Create an account to join the conversation.

  • Posts: 170
  • Thank you received: 7
2 years 2 months ago #339629

1- i do all that you say and it is not work yet. please see this screencast:
www.screencast.com/users/samansamani2/fo...42-9607-61008edf205b
2- it is work correctlly and thank you

Last edit: 2 years 2 months ago by sadaf3d.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
2 years 2 months ago #339636

Hi,

1. As I said in my first message, you need to put that code "outside of the form". However, in your screencast, I can see the </form> tag after my code, which means that this code is inside the form of the view. That's why it doesn't work. You need to move the code after the </form> tag

The following user(s) said Thank You: sadaf3d

Please Log in or Create an account to join the conversation.

  • Posts: 170
  • Thank you received: 7
2 years 2 months ago #339667

thank you @nicolas and excuse me for my mistake.
i was put it out of form tag in my previous test. i put it now out of form tag. it is work correctly and thank you.
for better UX is it possible change the total price via ajax in the Cart? now it is effect on total price but it is redirect to checkout progress. i want my user can see change the total price change in cart module after they enter coupon exactly such as checkout step.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
2 years 2 months ago #339668

Hi,

With custom javascript code in the code I gave it should be possible.
Please understand however that the code I've given you so far is already beyond normal user support.
If you want me to work on the modifications necessary to make it AJAX, please use our contact form to request a quote and I can do.
www.hikashop.com/support/contact-us.html

Please Log in or Create an account to join the conversation.

  • Posts: 170
  • Thank you received: 7
2 years 1 month ago #339774

nicolas wrote: Please understand however that the code I've given you so far is already beyond normal user support.

I understand that and thank a lot for your reply and i am very grateful to you. I have to thank you for your kindness .
i use this code and it work for me maybe have benefit for future users. Take a look at these codes if your time allows.
with this code coupon can add ajaxify or remove in cart module in every page except hikashop checkout page.
in view product>cart i put these code:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	4.4.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2020 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
$tmpl = hikaInput::get()->getWord('tmpl', '');
$module_id = (int)$this->params->get('id', 0);

if(!in_array($tmpl, array('component', 'ajax', 'raw'))) {
	$events = ($this->cart_type == 'cart') ? '["cart.updated","checkout.cart.updated"]' : '"wishlist.updated"';
?>
<script type="text/javascript">
window.Oby.registerAjax(<?php echo $events; ?>, function(params) {
	var o = window.Oby, el = document.getElementById('hikashop_cart_<?php echo $module_id; ?>');
	if(!el) return;
	if(params && params.resp && (params.resp.ret === 0 || params.resp.module == <?php echo (int)$module_id; ?>)) return;
	if(params && params.type && params.type != '<?php echo $this->cart_type; ?>') return;
	o.addClass(el, "hikashop_checkout_loading");
	o.xRequest("<?php echo hikashop_completeLink('product&task=cart&module_id='.$module_id . '&module_type='.$this->cart_type, true, false, true); ?>", {update: el, mode:'POST', data:'return_url=<?php echo urlencode(base64_encode(hikashop_currentURL('return_url'))); ?>'}, function(xhr){
		o.removeClass(el, "hikashop_checkout_loading");
	});
});
</script>
<?php
} elseif(!headers_sent()){
	header('X-Robots-Tag: noindex');
}

$group = (int)$this->config->get('group_options', 0);
$small_cart = (int)$this->params->get('small_cart', 0);
$link_to_product = (int)$this->params->get('link_to_product_page', 1);
$spinner_css="";
if (!empty($small_cart)) $spinner_css="small_spinner small_cart";

if(empty($this->rows)) {
	$hidecart = (int)$this->params->get('hide_cart', 0);
	$desc = trim($this->params->get('msg'));
	if((empty($desc) && $desc != '0') || $hidecart == 0)
		$desc = ($this->cart_type == 'cart') ? JText::_('CART_EMPTY') : JText::_('WISHLIST_EMPTY');
	if($hidecart == 2)
		$desc = '';

	if(empty($desc) && $desc != '0' && $tmpl == 'component') {
		if(!headers_sent())
			header('Content-Type: text/css; charset=utf-8');
		exit;
	}

	if(!empty($desc))
		echo $this->notice_html;

	if(!in_array($tmpl, array('component', 'ajax', 'raw'))) {
?>
<div id="hikashop_cart_<?php echo $module_id; ?>" class="hikashop_cart">
<?php
	}
?>
	<div class="hikashop_checkout_loading_elem"></div>
	<div class="hikashop_checkout_loading_spinner <?php echo $spinner_css ?>"></div>
<?php
	if(!empty($desc))
		echo $desc;

	if(!in_array($tmpl, array('component', 'ajax', 'raw'))) {
?>
</div>
<div class="clear_both"></div>
<?php
	}

	return;
}


$css_button = $this->config->get('css_button', 'hikabtn');
$css_button_checkout = $this->config->get('css_button_checkout', 'hikashop_cart_proceed_to_checkout');

if($this->params->get('print_cart', 0)) {
	$print_button = $this->popup->display(
		'<i class="fas fa-print"></i>',
		'HIKA_PRINT', hikashop_completeLink('cart&task=printcart&cid='.$this->element->cart_id, true),
		'hikashop_print_popup', 760, 480, 'title="'.JText::_('HIKA_PRINT').'"', '', 'link'
	);
}
$this->setLayout('listing_price');
$this->params->set('show_quantity_field', 0);

if(!in_array($tmpl, array('component', 'ajax', 'raw'))) {
?>
<div id="hikashop_cart_<?php echo $module_id; ?>" class="hikashop_cart">
<?php
}
?>
	<div class="hikashop_checkout_loading_elem"></div>
	<div class="hikashop_checkout_loading_spinner <?php echo $spinner_css ?>"></div>
<?php

echo $this->notice_html;
if(!empty($this->element->messages)) {
	foreach($this->element->messages as $msg) {
		if(empty($msg['type']))
			$msg['type'] = 'success';
		hikashop_display($msg['msg'], $msg['type']);
	}
}
$text = '';
if(!empty($small_cart)) {
	$price_name  = '';
	if(!$this->params->get('show_shipping', 0) && isset($this->total->prices[0]->price_value_without_shipping)){
		$price_name = '_without_shipping';
	}
	if(!$this->params->get('show_coupon', 0) && isset($this->total->prices[0]->price_value_without_discount)){
		$price_name = '_without_discount';
	}
	$price = '';
	if($this->params->get('price_with_tax')){
		$var_name = 'price_value'.$price_name.'_with_tax';
		$price .= $this->currencyClass->format(@$this->total->prices[0]->$var_name, $this->total->prices[0]->price_currency_id);
	}
	if($this->params->get('price_with_tax')==2){
		$price .= JText::_('PRICE_BEFORE_TAX');
	}
	if($this->params->get('price_with_tax')==2||!$this->params->get('price_with_tax')){
		$var_name = 'price_value'.$price_name;
		$price .= $this->currencyClass->format(@$this->total->prices[0]->price_value, $this->total->prices[0]->price_currency_id);
	}
	if($this->params->get('price_with_tax')==2){
		$price .= JText::_('PRICE_AFTER_TAX');
	}
	if((int)$this->params->get('show_cart_quantity', 1)) {
		$qty = 0;
		foreach($this->element->cart_products as $i => $row) {
			if(empty($row->cart_product_quantity) && $this->element->cart_type == 'cart')
				continue;
			if($group && $row->cart_product_option_parent_id)
				continue;

			$qty += $row->cart_product_quantity;
		}

		if($this->params->get('show_price')){
			if($qty == 1 && JText::_('X_ITEM_FOR_X') != 'X_ITEM_FOR_X') {
				$text = JText::sprintf('X_ITEM_FOR_X', $qty, $price);
			} else {
				$text = JText::sprintf('X_ITEMS_FOR_X', $qty, $price);
			}
		}else{
			if($qty == 1)
				$text = JText::sprintf('X_ITEM', $qty);
			else
				$text = JText::sprintf('X_ITEMS', $qty);
		}
	} else {
		if($this->params->get('show_price'))
			$text = JText::sprintf('TOTAL_IN_CART_X', $price);
		else
			$text = JText::_('MINI_CART_PROCEED_TO_CHECKOUT');
	}
	unset($this->row);

	$extra_data = '';
	if($this->element->cart_type == 'cart') {
		$link = $this->url_checkout;
	} else {
		$link = hikashop_completeLink('cart&task=showcart&cart_id='.$this->element->cart_id.'&cart_type='.$this->element->cart_type . $this->cart_itemid);
	}
	if($small_cart == 2) {
		$extra_data .= ' onclick="if(window.hikashop.toggleOverlayBlock(\'hikashop_cart_dropdown_'.$module_id.'\')) return false;"';
	}elseif($small_cart == 3) {
		$extra_data .= ' ontouchend="window.hikashop.toggleOverlayBlock(\'hikashop_cart_dropdown_'.$module_id.'\', \'hover\'); return false;" onmouseover="window.hikashop.toggleOverlayBlock(\'hikashop_cart_dropdown_'.$module_id.'\', \'hover\'); return false;"';
	}
?>
	<a class="hikashop_small_cart_checkout_link" href="<?php echo $link; ?>"<?php echo $extra_data; ?>>
		<span class="hikashop_small_cart_total_title"><?php echo $text; ?></span>
	</a>
<?php
	if($this->element->cart_type == 'cart' && $small_cart == 1 && $this->params->get('print_cart', 0)) {
?>		<span class="hikashop_checkout_cart_print_link">
<?php		echo $print_button;
?>		</span>
<?php
	}

	if($this->element->cart_type == 'cart' && $small_cart == 1 && $this->params->get('show_cart_delete', 1)) {
		$delete = hikashop_completeLink('product&task=cleancart');
?>
	<a class="hikashop_small_cart_clean_link" title="<?php echo JText::_('EMPTY_THE_CART'); ?>" href="<?php echo $delete; ?>" onclick="window.location='<?php echo $delete. (strpos($delete, '?') ? '&amp;' : '?') .'return_url='; ?>'+window.btoa(window.location); return false;">
		<i class="fa fa-times-circle"></i>
	</a>
<?php
	}

	if($this->element->cart_type == 'cart' && $small_cart == 1 && $this->params->get('show_cart_proceed', 1)) {
?>
	<a class="<?php echo $css_button . ' ' . $css_button_checkout; ?>" href="<?php echo $this->url_checkout; ?>" onclick="if(this.disable) return false; this.disable = true;"><span><?php
		echo JText::_('PROCEED_TO_CHECKOUT');
	?></span></a>
<?php
	}

	if($small_cart == 1) {
?>
</div>
<div class="clear_both"></div>
<?php
		return;
	}

	$alignment = '';
	$v = (int)$this->params->get('dropdown_left', 0);
	if($v != 0) $alignment .= 'left:'.(-$v).'px;';
	$v = (int)$this->params->get('dropdown_right', 0);
	if($v != 0) $alignment .= 'right:'.(-$v).'px;';
?>
	<div class="hikashop_cart_dropdown_container">
	<div class="hikashop_cart_dropdown_content" id="hikashop_cart_dropdown_<?php echo $module_id; ?>" style="display:none;<?php echo $alignment; ?>">
<?php
}
$shows = array(
	'price' => (int)$this->params->get('show_price', 1),
	'coupon' => (int)$this->params->get('show_coupon', 0),
	'shipping' => (int)$this->params->get('show_shipping', 0),
	'payment' => (int)$this->params->get('show_payment', 0),
	'taxes' => (int)$this->params->get('show_taxes', 0),
);
$columns = array(
	'image' => (int)$this->params->get('image_in_cart', 0),
	'name' => (int)$this->params->get('show_cart_product_name', 1),
	'quantity' => (int)$this->params->get('show_cart_quantity', 1),
	'price' => (int)$shows['price'],
	'delete' => (int)$this->params->get('show_cart_delete', 1)
);
$nb_columns = 0;
foreach($columns as $c) {
	if(!empty($c))
		$nb_columns++;
}

?>
	<form action="<?php echo hikashop_completeLink('product&task=updatecart'.$this->url_itemid, false, true); ?>" method="post" name="hikashop_<?php echo $this->element->cart_type; ?>_form" onsubmit="if(window.hikashop) return window.hikashop.submitCartModule(this, 'hikashop_cart_<?php echo $module_id; ?>', '<?php echo $this->element->cart_type; ?>');">
		<table class="hikashop_cart" width="100%">
		<thead>
			<tr>
<?php if(!empty($columns['image'])) { ?>
				<th class="hikashop_cart_module_product_image_title hikashop_cart_title"><?php
					echo JText::_('CART_PRODUCT_IMAGE');
				?></th>
<?php } ?>
<?php if(!empty($columns['name'])) { ?>
				<th class="hikashop_cart_module_product_name_title hikashop_cart_title"><?php
					echo JText::_('CART_PRODUCT_NAME');
				?></th>
<?php } ?>
<?php if(!empty($columns['quantity'])) { ?>
				<th class="hikashop_cart_module_product_quantity_title hikashop_cart_title"><?php
					echo JText::_('CART_PRODUCT_QUANTITY');
				?></th>
<?php } ?>
<?php if(!empty($columns['price'])) { ?>
				<th class="hikashop_cart_module_product_price_title hikashop_cart_title"><?php
					echo JText::_('CART_PRODUCT_PRICE');
				?></th>
<?php } ?>
<?php if($nb_columns == 0) { ?>
				<th></th>
<?php }
if($this->params->get('print_cart', 0)) {
?>				<th class="hikashop_cart_module_product_image_title hikashop_cart_title">
					<span class="hikashop_checkout_cart_print_link" style="width: 16px; display: inline-block;">
<?php					echo $print_button;
?>					</span>
				</th>
<?php }  ?>
			</tr>
		</thead>
<?php
if(!empty($shows['price']) && $this->element->cart_type == 'cart') {
	$colspan = $nb_columns - (empty($columns['delete']) ? 1 : 2);
?>
		<tfoot>
<?php if(!empty($shows['coupon']) && !empty($this->element->coupon)) { ?>
			<tr>
<?php if($colspan > 0) { ?>
				<td class="hikashop_cart_module_coupon_title" colspan="<?php echo $colspan; ?>"><?php
					echo JText::_('HIKASHOP_COUPON');
				?></td>
<?php } ?>
				<td class="hikashop_cart_module_coupon_value"><?php
					if(!$this->params->get('price_with_tax'))
						echo $this->currencyClass->format(@$this->element->coupon->discount_value_without_tax * -1, @$this->element->coupon->discount_currency_id);
					else
						echo $this->currencyClass->format(@$this->element->coupon->discount_value * -1, @$this->element->coupon->discount_currency_id);
				?></td>
<?php if(!empty($columns['delete'])) { ?>
				<td></td>
<?php } ?>
			</tr>
<?php } ?>
<?php
if(!empty($shows['payment']) && !empty($this->element->payment) && $this->element->payment->payment_price !== null) { ?>
			<tr>
<?php if($colspan > 0) { ?>
				<td class="hikashop_cart_module_payment_title" colspan="<?php echo $colspan; ?>"><?php
					echo JText::_('HIKASHOP_PAYMENT');
				?></td>
<?php } ?>
				<td class="hikashop_cart_module_payment_value"><?php
					echo $this->currencyClass->format($this->payment_price, $this->total->prices[0]->price_currency_id);
				?></td>
<?php if(!empty($columns['delete'])) { ?>
				<td></td>
<?php } ?>
			</tr>
<?php } ?>
<?php if(!empty($shows['shipping']) && !empty($this->element->shipping) && $this->shipping_price !== null) { ?>
			<tr>
<?php if($colspan > 0) { ?>
				<td class="hikashop_cart_module_shipping_title" colspan="<?php echo $colspan; ?>"><?php
					echo JText::_('HIKASHOP_SHIPPING');
				?></td>
<?php } ?>
				<td class="hikashop_cart_module_shipping_value"><?php
					echo $this->currencyClass->format($this->shipping_price, $this->total->prices[0]->price_currency_id);
				?></td>
<?php if(!empty($columns['delete'])) { ?>
				<td></td>
<?php } ?>
			</tr>
<?php } ?>
<?php
if(!empty($shows['taxes']) && isset($this->total->prices[0])) {
	if ($this->config->get('detailed_tax_display') && !empty($this->total->prices[0]->taxes)) {
		foreach($this->displayingPrices->taxes as $taxname => $taxdata){
?>
			<tr>
<?php
			if($colspan > 0) { ?>
				<td class="hikashop_cart_module_tax_title" colspan="<?php echo $colspan; ?>"><?php
					echo hikashop_translate($taxname);
				?></td>
<?php 		} ?>
				<td class="hikashop_cart_module_tax_value"><?php
					echo $this->currencyClass->format($taxdata->tax_amount, $this->displayingPrices->price_currency_id);
				?></td>
<?php 		if(!empty($columns['delete'])) { ?>
				<td></td>
<?php 		} ?>
			</tr>
<?php 	}
	}else{
?>
			<tr>
<?php
			if($colspan > 0) { ?>
				<td class="hikashop_cart_module_tax_title" colspan="<?php echo $colspan; ?>"><?php
					echo JText::_('TAXES');
				?></td>
<?php 		} ?>
				<td class="hikashop_cart_module_tax_value"><?php
					$taxes = round($this->displayingPrices->total->price_value_with_tax - $this->displayingPrices->total->price_value, $this->currencyClass->getRounding($this->displayingPrices->price_currency_id));
					echo $this->currencyClass->format($taxes, $this->displayingPrices->price_currency_id);
				?></td>
<?php 		if(!empty($columns['delete'])) { ?>
				<td></td>
<?php 		} ?>
			</tr>
<?php
	}
}
?>
			<tr>
<?php if($colspan > 0) { ?>
				<td class="hikashop_cart_module_product_total_title" colspan="<?php echo $colspan; ?>"><?php
					echo JText::_('HIKASHOP_TOTAL');
				?></td>
<?php } ?>
				<td class="hikashop_cart_module_product_total_value"><?php
					if($this->params->get('price_with_tax', 3) == 3) {
						$this->params->set('price_with_tax', (int)$this->config->get('price_with_tax'));
					}
					$total_price = '';
					if($this->params->get('price_with_tax')){
						$total_price .= $this->currencyClass->format($this->displayingPrices->total->price_value_with_tax, $this->displayingPrices->price_currency_id);
					}
					if($this->params->get('price_with_tax')==2){
						$total_price .= JText::_('PRICE_BEFORE_TAX');
					}
					if($this->params->get('price_with_tax')==2||!$this->params->get('price_with_tax')){
						$total_price .= $this->currencyClass->format($this->displayingPrices->total->price_value, $this->displayingPrices->price_currency_id);
					}
					if($this->params->get('price_with_tax')==2){
						$total_price .= JText::_('PRICE_AFTER_TAX');
					}
					?>
					<span class="hikashop_product_price_full">
						<span class="hikashop_product_price hikashop_product_price_0">
							<?php echo $total_price; ?>
						</span>
					</span>
				</td>
<?php //exit; ?>
<?php if(!empty($columns['delete'])) { ?>
				<td></td>
<?php } ?>
			</tr>
		</tfoot>
<?php } ?>
		<tbody>
<?php
$group = $this->config->get('group_options', 0);
$width = (int)$this->config->get('cart_thumbnail_x', 50);
$height = (int)$this->config->get('cart_thumbnail_y', 50);
$image_options = array(
	'default' => true,
	'forcesize' => $this->config->get('image_force_size', true),
	'scale' => $this->config->get('image_scale_mode','inside')
);

$k = 0;
foreach($this->element->products as $k => $product) {
	if($group && !empty($product->cart_product_option_parent_id))
		continue;
	if(empty($product->cart_product_quantity) || substr($k,0,1) === 'p')
		continue;

	$cart_product = $this->element->cart_products[$k];
?>
			<tr class="row<?php echo $k; ?>">
<?php
	if(!empty($columns['image'])) {
?>
				<td class="hikashop_cart_module_product_image hikashop_cart_value" style="vertical-align:middle !important;text-align:center;"><?php
		$img = $this->imageHelper->getThumbnail(@$product->images[0]->file_path, array('width' => $width, 'height' => $height), $image_options);
		if($img->success) {
			$attributes = '';
			if($img->external)
				$attributes = ' width="'.$img->req_width.'" height="'.$img->req_height.'"';
			?><img class="hikashop_product_cart_image" title="<?php echo $this->escape(@$product->images[0]->file_description); ?>" alt="<?php echo $this->escape(@$product->images[0]->file_name); ?>" src="<?php echo $img->url; ?>" <?php echo $attributes; ?>/><?php
		}
				?></td>
<?php
	}
?>
<?php
	if(!empty($columns['name'])) {
?>
				<td class="hikashop_cart_module_product_name_value hikashop_cart_value">
<?php
		if($link_to_product == 1) {
			?><a href="<?php echo hikashop_contentLink('product&task=show&cid='.$product->product_id.'&name='.$product->alias.$this->url_itemid, $product);?>"><?php
		}
?>
<?php
		echo $product->product_name;
?>
<?php
		if ($this->config->get('show_code')) {
			?><span class="hikashop_product_code_cart"><?php echo $product->product_code; ?></span><?php
		}
?>
<?php
		if($link_to_product == 1) {
			?></a><?php
		}
?>
<?php
		$html = '';
		if(hikashop_level(2) && !empty($this->itemFields)) {
			foreach($this->itemFields as $field) {
				$namekey = $field->field_namekey;
				if(empty($cart_product->$namekey) || !strlen($cart_product->$namekey))
					continue;
				$html .= '<p class="hikashop_cart_item_'.$namekey.'">' .
					$this->fieldsClass->getFieldName($field) . ': ' .
					$this->fieldsClass->show($field, $cart_product->$namekey) .
					'</p>';
			}
		}
		if($group) {
			foreach($this->element->products as $j => $optionElement) {
				if($optionElement->cart_product_option_parent_id != $product->cart_product_id)
					continue;
				if(!empty($optionElement->variant_name)) {
					$text = $optionElement->variant_name;
				} elseif(empty($optionElement->characteristics_text)){
					$text = $optionElement->product_name;
				} else {
					$text = $optionElement->characteristics_text;
				}
				$html .= '<p class="hikashop_cart_option_name">'. $text . '</p>';
			}
		}
		if(!empty($html)) {
?>
					<div class="hikashop_cart_product_custom_item_fields"><?php
						echo $html;
					?></div>
<?php
		}
?>
				</td>
<?php
	}
?>
<?php
	if(!empty($columns['quantity'])) {
?>
				<td class="hikashop_cart_module_product_quantity_value hikashop_cart_value"><?php
		$this->row =& $product;
		$this->quantityLayout = $this->cartHelper->getProductQuantityLayout($this->row);
		if(!in_array($this->quantityLayout, array('show_simple','show_select','show_select_price','show_none')))
			$this->quantityLayout = 'show_simple';
		echo $this->loadHkLayout('quantity', array(
			'quantity_fieldname' => 'item['.$product->cart_product_id.'][cart_product_quantity]',
			'onchange_script' => 'window.hikashop.checkQuantity(this); if(this.value == '.(int)$product->cart_product_quantity.'){ return; } if(this.form.onsubmit && !this.form.onsubmit()) return; this.form.submit();',
		));
				?></td>
<?php
	}
?>
<?php
	if(!empty($columns['price'])) {
		if($group) {
			foreach($this->element->products as $j => $optionElement) {
				if($optionElement->cart_product_option_parent_id != $product->cart_product_id)
					continue;
				if(empty($optionElement->prices[0]))
					continue;
				if(!isset($product->prices[0])) {
					$product->prices[0] = new stdClass();
					$product->prices[0]->price_value = 0;
					$product->prices[0]->price_value_with_tax = 0;
					$product->prices[0]->price_currency_id = hikashop_getCurrency();
				}
				foreach(get_object_vars($product->prices[0]) as $key => $value) {
					if(strpos($key, 'price_value') === false)
						continue;
					if(is_object($value)) {
						foreach(get_object_vars($value) as $key2 => $var2) {
							$product->prices[0]->$key->$key2 += @$optionElement->prices[0]->$key->$key2;
						}
					} else {
						$product->prices[0]->$key += @$optionElement->prices[0]->$key;
					}
				}
			}
		}
?>
				<td class="hikashop_cart_module_product_price_value hikashop_cart_value"><?php
		$this->row =& $product;
		$this->unit = false;
		$this->cart_product_price = true;

		$price_with_tax_option = $this->params->get('price_with_tax');
		if(!empty($shows['taxes']) && $this->params->get('price_with_tax') == 1)
			$this->params->set('price_with_tax',0);

		if($this->params->get('show_discount', 3) == 3 && isset($this->default_params['show_discount'])) {
			$this->params->set('show_discount', (int)$this->default_params['show_discount']);
		}

		echo $this->loadTemplate();

		if(!empty($shows['taxes']) && $price_with_tax_option == 1)
			$this->params->set('price_with_tax',$price_with_tax_option);
				?></td>
<?php } ?>
<?php
	if(!empty($columns['delete'])) {
		$delete_url = hikashop_completeLink('product&task=updatecart&cart_id='.(int)$this->element->cart_id.'&cart_product_id='.(int)$product->cart_product_id.'&quantity=0');
		$delete_url .= ((strpos($delete_url, '?') === false) ? '?' : '&') . 'return_url='.urlencode(base64_encode(urldecode($this->params->get('url'))));
?>
				<td class="hikashop_cart_module_product_delete_value hikashop_cart_value">
					<a href="<?php echo $delete_url; ?>" data-cart-id="<?php echo (int)$this->element->cart_id; ?>" data-cart-type="<?php echo $this->escape($this->element->cart_type); ?>" data-cart-product-id="<?php echo (int)$product->cart_product_id; ?>" onclick="if(window.hikashop) { return window.hikashop.deleteFromCart(this, null, 'hikashop_cart_<?php echo $module_id; ?>'); }" title="<?php echo JText::_('HIKA_DELETE'); ?>">
						<i class="fa fa-times-circle"></i>
					</a>
				</td>
<?php
	}
?>
<?php
	if($nb_columns == 0) {
?>
				<td></td>
<?php
	}
?>
			</tr>
<?php
	$k = 1 - $k;
}
?>
		</tbody>
		</table>
		<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>"/>
		<input type="hidden" name="ctrl" value="product"/>
		<input type="hidden" name="task" value="updatecart"/>
		<input type="hidden" name="cart_type" value="<?php echo $this->cart_type; ?>"/>
		<input type="hidden" name="url" value="<?php echo $this->escape($this->params->get('url')); ?>"/>
<?php
if($this->params->get('show_cart_quantity', 1)) {
?>
		<noscript>
			<input type="submit" class="<?php echo $css_button; ?>" name="refresh" value="<?php echo JText::_('REFRESH_CART');?>"/>
		</noscript>
<?php
}
?>
      
      
      
      
      
      

 
      
      
      
      
	</form>
      
      
      
      
      
      
      
      
<?php
$cartClass= hikashop_get('class.cart');
$cart = $cartClass->getFullCart();
if(empty($cart->coupon)) {
global $Itemid;
$url_itemid= '';
if(!empty($Itemid)) $url_itemid = '&Itemid='.$Itemid;
 ?>

<?php } ?>
      
      
      
       
      
      <?php
global $Itemid;
$url_itemid= '';
if(!empty($Itemid)) $url_itemid = '&Itemid='.$Itemid;
 ?>

        <?php

        require_once JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/checkout.php';
        $checkoutHelper = hikashopCheckoutHelper::get();
        $workflow = $checkoutHelper->checkout_workflow;

        foreach ($workflow['steps'] as $index1 => $stp) {

            foreach ($stp['content'] as $index2 => $pos) {

                if ($pos['task'] == 'coupon') {
                    $step = $index1;
                    $position = $index2;
                    break 2;
                }
            }
        }

        $hikashop_checkout_coupon= 'hikashop_checkout_coupon_'. ($step + 1). '_'. ($position);
        $hikashop_checkout_coupon_input= 'hikashop_checkout_coupon_input_'. ($step + 1). '_'. ($position);

        $app = jfactory::getapplication();
        $document = jfactory::getdocument();
        $input = $app->input;
        $view = $input->get('view');
        if (!in_array($view, ['checkout'])) {
            $cartClass = hikashop_get('class.cart');
            $cart = $cartClass->getFullCart();
            $document->addScript(juri::root() . 'media/com_hikashop/js/checkout.js')
            ?>

            <script>
                jQuery(document).ready(function ($) {

                    window.checkout.token = Joomla.getOptions('csrf.token');
                    window.checkout.urls.show = "/customer-order/checkout/showblock/tmpl-raw";
                    window.checkout.urls.submit = "/customer-order/checkout/submitblock/tmpl-raw";
                    window.checkout.urls.submitstep = "/customer-order/checkout/submitstep/tmpl-raw";

                    if (!window.checkout) window.checkout = {};
                    window.Oby.registerAjax(['checkout.coupon.updated', 'cart.updated'], function (params) {
                        if (params && (params.cart_empty || (params.resp && params.resp.empty))) return;
                        window.checkout.refreshCoupon(1, 2);
                    });
                    window.checkout.refreshCoupon = function (step, id) {
                        return window.checkout.refreshBlock('coupon', step, id);
                    };
                    window.checkout.submitCoupon = function (step, id) {
                        var el = document.getElementById('hikashop_checkout_coupon_input_' + step + '_' + id);
                        if (!el)
                            return false;
                        if (el.value == '') {
                            window.Oby.addClass(el, 'hikashop_red_border');
                            return false;
                        }
                        return window.checkout.submitBlock('coupon', step, id);
                    };
                    window.checkout.removeCoupon = function (step, id) {
                        window.checkout.submitBlock('coupon', step, id, {'checkout[removecoupon]': 1});
                        return false;
                    };
                })
            </script>

        <?php if (!empty($cart->coupon)): ?>
            <style>
                .hikashop_checkout_coupon .fa-trash {
                    color: #439a86 !important;
                }

                .hikashop_checkout_coupon a {
                    color: #000 !important;
                }
            </style>
            <div id="<?= $hikashop_checkout_coupon;?>" data-checkout-step="<?= ($step+1)?>" data-checkout-pos="<?= ($position)?>"
                 class="hikashop_checkout_coupon">
                <div class="hikashop_checkout_loading_elem"></div>
                <div class="hikashop_checkout_loading_spinner"></div>
                <a href="#removeCoupon"
                   onclick="return window.checkout.removeCoupon(<?= ($step + 1) ?>,<?= ($position) ?>);"
                   title="حذف کوپن">
                    حذف کوپن
                    <i class="fas fa-trash"></i>
                </a>
            </div>

        <?php else: ?>

            <div id="<?= $hikashop_checkout_coupon;?>" data-checkout-step="<?= ($step + 1) ?>"
                 data-checkout-pos="<?= ($position) ?>" class="hikashop_checkout_coupon">
                <div class="hikashop_checkout_loading_elem"></div>
                <div class="hikashop_checkout_loading_spinner"></div>

                <label for="<?= $hikashop_checkout_coupon_input;?>">کوپن خود را وارد کنيد</label>
                <div class="input-append">
                    <input class="hikashop_checkout_coupon_field" id="<?= $hikashop_checkout_coupon_input;?>" type="text"
                           name="checkout[coupon]" value="">
                    <button type="submit"
                            onclick="return window.checkout.submitCoupon(<?= ($step + 1) ?>,<?= ($position) ?>);"
                            id="farhad" class="hikabtn hikabtn-primary">اضافه کردن
                    </button>
                </div>
            </div>
        <?php endif; ?>

            <?php
        }
        ?>

      
<?php
if($this->element->cart_type == 'cart' && $this->params->get('show_cart_proceed', 1)) {
?>
	<a class="<?php echo $css_button . ' ' . $css_button_checkout; ?>" href="<?php echo $this->url_checkout; ?>" onclick="if(this.disable) return false; this.disable = true;"><span><?php
		echo JText::_('PROCEED_TO_CHECKOUT');
	?></span></a>
    <a href="<?php echo hikashop_completeLink('checkout&task=confirm'.$url_itemid); ?>" class="hikabtn hikabtn-success hikabtn_checkout_next"><?= JText::_('CHECKOUT_BUTTON_FINISH');?></a>
<?php
}

if(!empty($this->extraData->bottom)) { echo implode("\r\n", $this->extraData->bottom); }

if(in_array($small_cart, array(2, 3))) {
?>
	</div>
	</div>
<?php
}

if(!in_array($tmpl, array('component', 'ajax', 'raw'))) {
?>
</div>
<div class="clear_both"></div>
<?php
}

Last edit: 2 years 1 month ago by sadaf3d.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
2 years 1 month ago #339777

Hi,

I would have done it a lot simpler by just submitting the this.form in ajax and then refreshing the cart module after the response from the server. I suppose it would have been a few lines of javascript to add the code I had provided so far.

Importing the whole code from the checkout coupon view sure is possible. If it works for you then it's all good.

The following user(s) said Thank You: sadaf3d

Please Log in or Create an account to join the conversation.

Time to create page: 0.075 seconds
Powered by Kunena Forum