Mini Cart quantity/price calculation error

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99007

Just upgraded to latest Hikashop 2.1.2.

An anonymous user, on adding an item to the shopping cart sees the mini cart module in the sidebar showing no items. As soon as a user logs-in those items are there and waiting for that user to proceed to checkout. It used to be the case that anonymous users could add to cart and this would be reflected in the mini-cart contents.

This change in behaviour occurred after upgrading to 2.1.2 today. I have checked all the settings and can see nothing unexpected. Anonymous users, on visiting the shop, need to see their cart contents so that they can proceed to checkout. The way I have configured the system is that the mini cart is the ONLY way to proceed to checkout.

What could be the problem?

Thanks,
Ric

Added after further tests:


It looks as though the problem was nothing to do with the upgrade to 2.1.2. The problem is that to improve performance I had turned caching on. Joomla does not appear to handle caching selectively: it's all or nothing.

However there is now a problem that may be due to the 2.1.2 upgrade. When items are added or deleted from the cart, the mini-module displays the items. If the item quantity is changed in the mini cart (and the update button clicked) the total price is calculated incorrectly.

If the option proceed to checkout is taken then quantities can also be changed during the latter stages of checkout. Changing quantities there does calculate amounts correctly. However the correct amount is not displayed correctly in the mini-cart.



All caching is off, system cache plugin didabled, browser cache cleared. Problem persists

Attachments:
Last edit: 11 years 1 month ago by ricm. Reason: Additional Info

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

  • Posts: 81677
  • Thank you received: 13102
  • MODERATOR
11 years 1 month ago #99206

mmm. I've never heard of that.

The mini cart and the checkout normally use the same data so I don't see why you would get different results.

Could you provide the product URL so that we can try to reproduce the problem ?

Also, a backend access would be great in order to check your settings.

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99260

Hello,
The URL is:

science-learning.co.uk/index.php/ordering .

I'll pm the credentials separately.

Thanks,
Ric

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

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #99363

Hi,

The problem has been corrected on our end and will be available in the next release.

To correct it, thanks to edit the file "components/com_hikashop/views/product/view.html.php" function "cart()" and comment all the content of the if condition "if(!empty($rows)){".

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99379

Hello, Thanks for having a look.

I eventually used notepad++ to make sure I got the right closing brace. I had:

if(!empty($rows)){
/*			$ids = array();

			....

$currencyClass->getListingPrices($rows,$pageInfo->zone_id,$pageInfo->currency_id,$pageInfo->filter->price_display_type); */
}

as the content to comment out. Unfortunately when I did this all the product images reverted to the default and all the items were suddenly free. If anyone wants to grab a bargain before the next fix, now's the time! :)





Maybe I commented-out the wrong bit?

Thanks,
Ric

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #99393

Can you try to use this cart function:

	function cart(){
		$module = hikashop_get('helper.module');
		$module->initialize($this);

		if(!HIKASHOP_PHP5) {
			$app =& JFactory::getApplication();
			$database =& JFactory::getDBO();
			$config =& hikashop_config();
		} else {
			$app = JFactory::getApplication();
			$database = JFactory::getDBO();
			$config = hikashop_config();
		}
		$currencyClass = hikashop_get('class.currency');
		$class = hikashop_get('class.cart');
		$productClass = hikashop_get('class.product');
		$main_currency = (int)$config->get('main_currency',1);
		$currency_id = hikashop_getCurrency();
		//$currency_id = $app->getUserStateFromRequest( HIKASHOP_COMPONENT.'.currency_id', 'currency_id', $main_currency, 'int' );
		if($config->get('tax_zone_type','shipping')=='billing'){
			$zone_id = hikashop_getZone('billing');
		}else{
			$zone_id = hikashop_getZone('shipping');
		}
		$discount_before_tax = (int)$config->get('discount_before_tax',0);

		$cart_type = $this->params->get('cart_type','cart');
		$cart_id =$app->getUserState( HIKASHOP_COMPONENT.'.'.$cart_type.'_id', 0, 'int' );
		//$rows = $class->get($cart_id,false,$cart_type);

		$full = $class->loadFullCart(true);
		$rows = $full->products;

		$total = new stdClass();
		/*
		if(!empty($rows)){
			//add variants inside main products as reference for tax calculus
			$variants = false;
			$ids = array();
			foreach($rows as $k => $row){
				$ids[]=$row->product_id;
				if($row->product_type=='variant'){
					$variants = true;
					foreach($rows as $k2 => $row2){
						if($row->product_parent_id==$row2->product_id){
							$rows[$k2]->variants[]=&$rows[$k];
						//	break;
						}
					}
				}
			}

			if($variants){
				$this->selected_variant_id = 0;
				//add the characteristics infos
				$query = 'SELECT a.*,b.* FROM '.hikashop_table('variant').' AS a LEFT JOIN '.hikashop_table('characteristic').' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN ('.implode(',',$ids).') ORDER BY a.ordering ASC,b.characteristic_value ASC';
				$database->setQuery($query);
				$characteristics = $database->loadObjectList();
				if(!empty($characteristics)){
					foreach($rows as $k => $row){
						$element =& $rows[$k];
						$product_id=$row->product_id;
						if($row->product_type=='variant'){
							continue;
						}
						$mainCharacteristics = array();
						foreach($characteristics as $characteristic){
							if($product_id==$characteristic->variant_product_id){
								$mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
							}
							if(!empty($element->options)){
								foreach($element->options as $k => $optionElement){
									if($optionElement->product_id==$characteristic->variant_product_id){
										$mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
									}
								}
							}
						}
						if(!empty($element->variants)){
							$this->addCharacteristics($element,$mainCharacteristics,$characteristics);
						}

						if(!empty($element->options)){
							foreach($element->options as $k => $optionElement){
								if(!empty($optionElement->variants)){
									$this->addCharacteristics($element->options[$k],$mainCharacteristics,$characteristics);
								}
							}
						}
					}
				}
			}

			//calculate prices
			$product_quantities = array();
			foreach($rows as $row){
				if(empty($product_quantities[$row->product_id])){
					$product_quantities[$row->product_id] = (int)@$row->cart_product_quantity;
				}else{
					$product_quantities[$row->product_id]+=(int)@$row->cart_product_quantity;
				}
				if(empty($product_quantities[$row->product_parent_id])){
					$product_quantities[$row->product_parent_id] = (int)@$row->cart_product_quantity;
				}else{
					$product_quantities[$row->product_parent_id] += (int)@$row->cart_product_quantity;
				}
			}
			foreach($rows as $k => $row){
				$rows[$k]->cart_product_total_quantity = $product_quantities[$row->product_id];
				if($row->product_parent_id){
					$rows[$k]->cart_product_total_variants_quantity = $product_quantities[$row->product_parent_id];
				}else{
					$rows[$k]->cart_product_total_variants_quantity = $rows[$k]->cart_product_total_quantity;
				}
			}
			//calculate prices
			$currencyClass->getPrices($rows,$ids,$currency_id,$main_currency,$zone_id,$discount_before_tax);
			foreach($rows as $k => $row){
				if(!empty($row->variants)){
					foreach($row->variants as $k2 => $variant){
						$productClass->checkVariant($rows[$k]->variants[$k2],$row);
					}
				}
			}
			foreach($rows as $k => $row){
				$currencyClass->calculateProductPriceForQuantity($rows[$k]);

				//If row_type = variant, the oldest is a main > hide the main
				$rows[$k]->hide = 0;
				if($row->product_type == 'variant'){
					$rows[--$k]->hide = 1;
				}
			}

			$total=new stdClass();
			$currencyClass->calculateTotal($rows,$total,$currency_id);

		}
		*/
		$this->assignRef('total',$total);
		$this->assignRef('rows',$rows);
		$this->assignRef('config',$config);
		$cart=hikashop_get('helper.cart');
		$this->assignRef('cart',$cart);
		$this->assignRef('currencyHelper',$currencyClass);
		$cart->cartCount(true);
		$url = $this->init(true);

		$this->params->set('url',$url);
		ob_start();
		$cart->getJS($url,false);
		$notice_html = ob_get_clean();
		$this->assignRef('notice_html',$notice_html);
		if(hikashop_level(2)){
			$null=null;
			$fieldsClass=hikashop_get('class.field');
			$itemFields = $fieldsClass->getFields('frontcomp',$null,'item','checkout&task=state');
			$this->assignRef('itemFields',$itemFields);
			$this->assignRef('fieldsClass',$fieldsClass);
		}
		//$this->addJS();
	}

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99399

Hi again,

I replaced that function and there have been great improvements. The mini cart now responds with the correct amount. However one problem remains.

The related products are still displayed as free:



Ric

Attachments:

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

  • Posts: 81677
  • Thank you received: 13102
  • MODERATOR
11 years 1 month ago #99407

You probably have messed up something else in the file.

Please download again HikaShop and install it again and that will put the new file with the fix.

The following user(s) said Thank You: ricm

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99423

Yes, that did it.

many thanks for the fix.

Regards,
Ric

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99491

Hi,

I spoke too soon. Unfortunately the mini-cart total does not display correctly (the individual items do and the recalculation of price is correct when quantities are changed):



I think it's a display problem because the correct prices are transfered to payPal during the payment cycle.

Thanks,
Ric

Attachments:

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

  • Posts: 36
  • Thank you received: 0
11 years 1 month ago #99492

You probably have messed up something else in the file.

Please download again HikaShop and install it again and that will put the new file with the fix.


Yes, I attempted to edit the file through "views" first, but couldn't locate the correct file so gave up and edited the file on the server directly. However the file I first tried to edit showed an override in place even though nothing had changed. I guess this file was used in preference to the new file from the latest download.

It occurs to me this sort of problem will always occur - what it the best practice to make sure overrides to not endure when the original file has genuine updates/fixes, etc? Is it a matter of making a note of the override, removing it, allowing new files to be used and then re-applying overrides to the new version?

Ric

Last edit: 11 years 1 month ago by ricm.

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

  • Posts: 81677
  • Thank you received: 13102
  • MODERATOR
11 years 1 month ago #99536

Hi,

I was able to reproduce the issue indeed. It was another glitch due to a modification for the 2.1.2 release.

That's fixed now. Please download hikashop again and install it again on your website and that will work.

The best is to avoid overrides as much as possible. A lot of the customization can actually be done with CSS or the options already there.
If you need to override a view, then the best is to actually try to only add code to it and remove the rest and use an include to call the original view file so that your code simply modify the data before it is used.
Also, we have view triggers which allow you to modify the data before the display and another one to modify the HTML after the display of a view and thus you can use plugins to modify the views without overrides.
Finally, if you really have no other way to do the modification, you need to mark your modifications clearly in the file so that if you have a problem with that view after the update, you can delete your customization and reapply it to the new version of the view.

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

Time to create page: 0.104 seconds
Powered by Kunena Forum