Products sometimes not added to cart

  • Posts: 45
  • Thank you received: 0
8 years 9 months ago #229320

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.3.10

Hi,

I'm using the listing_table to show products in rows. Because it is a long list I also wanted to place the Add to cart-button at the top of the page, instead of only at the bottom.

So i copied the code of the button to the top of listing_table.php. But it seems that occasionally, maybe only the first time someone uses this button, the products are not added to the cart. Everything seems to go right, but if you go to the cart it is empty. People complain this is happening, I only could reproduce it one time. So not sure where to look.

Have any of you got any idea what could be the issue here?

The code I placed at the top of listing_table.php is:

<?php if ($this->config->get('show_quantity_field')>=2) {
				$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form_'.$this->params->get('main_div_name').'\')){ return hikashopModifyQuantity(\'\',field,1,\'hikashop_product_form_'.$this->params->get('main_div_name').'\'); } return false;';
				$this->row = null;
				$this->row->product_quantity = -1;
				$this->row->product_min_per_order = 0;
				$this->row->product_max_per_order = -1;
				$this->row->product_sale_start = 0;
				$this->row->product_sale_end = 0;
				$this->row->prices = array('filler');
				$this->setLayout('quantity');
				echo $this->loadTemplate();
				if(!empty($this->ajax) && $this->config->get('redirect_url_after_add_cart','stay_if_cart')=='ask_user'){ ?>
					<input type="hidden" name="popup" value="1"/>
				<?php } ?>
				<input type="hidden" name="hikashop_cart_type_0" id="hikashop_cart_type_0" value="cart"/>
				<input type="hidden" name="add" value="1"/>
				<input type="hidden" name="ctrl" value="product"/>
				<input type="hidden" name="task" value="updatecart"/>
				<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url)));?>"/>
				</form>
		<?php }
		if(in_array($pagination,array('bottom','both')) && $this->params->get('show_limit') && $this->pageInfo->elements->total){ $this->pagination->form = '_bottom'; ?>
			<form action="<?php echo hikashop_currentURL(); ?>" method="post" name="adminForm_<?php echo $this->params->get('main_div_name').$this->category_selected;?>_bottom">
				<div class="hikashop_products_pagination hikashop_products_pagination_bottom">
				<?php echo $this->pagination->getListFooter($this->params->get('limit')); ?>
				<span class="hikashop_results_counter"><?php echo $this->pagination->getResultsCounter(); ?></span>
				</div>
				<input type="hidden" name="filter_order_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
				<input type="hidden" name="filter_order_Dir_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
				<?php echo JHTML::_( 'form.token' ); ?>
			</form>
		<?php } ?>   

Thanks!

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

  • Posts: 12953
  • Thank you received: 1778
8 years 9 months ago #229351

Hello,
Your issue will depend on where you exactly moved that code on the "listing_table" file, so can you give us more information about it ?
Also, note that it won't work if you have moved these lines above these lines :

<?php foreach($this->rows as $row){
	$this->row =& $row;
If you want to debug your customization, the best solution will probably be to enable the Joomla debug mode and error reporting.

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

  • Posts: 45
  • Thank you received: 0
8 years 9 months ago #229408

Hi Mohamed,

I placed the full code at the top of the page, so right after

defined('_JEXEC') or die('Restricted access');
?>

I want it to show at the top of the page. To be clear: it works most of the time.

Thanks again.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 9 months ago #229427

That's the problem.
The quantity inputs and the button needs to be inside the <form> and </form> tags.

If you look at the code you gave you can see that it's not the case:
take.ms/xLWsU
The add to cart button is now outside the form tags and the </form> tag should be left at the end of the listing.

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

  • Posts: 45
  • Thank you received: 0
8 years 9 months ago #229563

Hi Nicolas,

I'm sorry, I don't understand your answer. The given code is exactly the same as the original code at the bottom of the page of listing_table.php. I only copied it to the top.

But, to take another approach, what do I need to do if I want the button on the top also?

Thanks again!

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 9 months ago #229571

Hi,

What you did is a good idea, but you need to remove the </form> tag from the code that you copy/paste and you need to put your code after the <form> tag of the view.
That's basically what I hinted at in my previous message.

The following user(s) said Thank You: Squashtoppertje

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

  • Posts: 45
  • Thank you received: 0
8 years 9 months ago #229733

Hi Nicolas,

Thanks, I think I solved it by copying the complete code to after the form-tags. Not completely sure yet, but I will see if any users still got the problem.

This is wat I got now:

			<form action="<?php echo hikashop_currentURL(); ?>" method="post" name="adminForm_<?php echo $this->params->get('main_div_name').$this->category_selected;?>_bottom">
				<input type="hidden" name="filter_order_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
				<input type="hidden" name="filter_order_Dir_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
				<?php echo JHTML::_( 'form.token' ); ?>

			</form>
            <?php if ($this->config->get('show_quantity_field')>=2) {
				$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form_'.$this->params->get('main_div_name').'\')){ return hikashopModifyQuantity(\'\',field,1,\'hikashop_product_form_'.$this->params->get('main_div_name').'\'); } return false;';
				$this->row = null;
				$this->row->product_quantity = -1;
				$this->row->product_min_per_order = 0;
				$this->row->product_max_per_order = -1;
				$this->row->product_sale_start = 0;
				$this->row->product_sale_end = 0;
				$this->row->prices = array('filler');
				$this->setLayout('quantity');
				echo $this->loadTemplate();
				if(!empty($this->ajax) && $this->config->get('redirect_url_after_add_cart','stay_if_cart')=='ask_user'){ ?>
					<input type="hidden" name="popup" value="1"/>
				<?php } ?>
				<input type="hidden" name="hikashop_cart_type_0" id="hikashop_cart_type_0" value="cart"/>
				<input type="hidden" name="add" value="1"/>
				<input type="hidden" name="ctrl" value="product"/>
				<input type="hidden" name="task" value="updatecart"/>
				<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url)));?>"/>
				
		<?php }
		 if(in_array($pagination,array('bottom','both')) && $this->params->get('show_limit') && $this->pageInfo->elements->total){ $this->pagination->form = '_bottom'; ?>
		<?php } ?>  

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

Time to create page: 0.099 seconds
Powered by Kunena Forum