Count the items in mini cart

  • Posts: 129
  • Thank you received: 0
7 years 10 months ago #272201

it only shows the variants and options as a separate and independent product in checkout cart view and in card module!
my question is how can I remove options and variants from cart module counting and display the main product count inside module!

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 10 months ago #272208

Hi,

That's not the case. As Philippe explained, if you have the setting "Group options with product" activated in the HikaShop configuration, the variants and options will be grouped with the main products and the counting will only be done on the main products.
So that should do what you want already.
Here is an example on a test website of mine:
monosnap.com/file/ZgUlNFTWyHCb1pdqQfvUTCXhK57tCo
As you can see, I have one main product with one option with a quantity of 2 in my cart and the mini module on the right side properly displays "2" and not "4" since I have the "group options with products" setting activated.

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

  • Posts: 129
  • Thank you received: 0
7 years 10 months ago #272661

Hi, Nicolas.
i think i've explained bad or you have been misunderstood.
i have turned off the quantitiy option in mini cart module.

i just want to load an string of line inside an span tag to only show the total amount of main product inside cart.
for example if i have an iphone with software and another iphone with waranty i want that string at bottom of my cart to show 2
but it shows 4 even when i turn on the "Group options with product" !

i just want to count and show the total amount of main products it has nothing to do with hichashop mini cart quantity option i think !

Check this photo please

Attachments:

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 10 months ago #272675

Hi,

Then you should use such code:

		<?php 	
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php'))
				return true;

			$cartClass = hikashop_get('class.cart');
			$fullCart = $cartClass->loadFullCart();
			$nbProducts = 0;
			foreach($fullCart->products as $product){
			    if($product->cart_product_option_parent_id) continue;
			    $nbProducts += $product->cart_product_quantity;
			}
			echo $nbProducts;
		?>

Last edit: 7 years 10 months ago by nicolas.

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

  • Posts: 129
  • Thank you received: 0
7 years 10 months ago #272687

You're My Man Nicolas,
It Finally Worked Thank you ;-)

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

  • Posts: 165
  • Thank you received: 3
7 years 10 months ago #273401

nicolas wrote: Hi,

Then you should use such code:

		<?php 	
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php'))
				return true;

			$cartClass = hikashop_get('class.cart');
			$fullCart = $cartClass->loadFullCart();
			$nbProducts = 0;
			foreach($fullCart->products as $product){
			    if($product->cart_product_option_parent_id) continue;
			    $nbProducts += $product->cart_product_quantity;
			}
			echo $nbProducts;
		?>


Hi, I am using the ajax version of the add to cart button. However, the issue I am having is this shows the total number of items in the cart however, the number does not update since I am using ajax how do I get the total number to update using the ajax add to cart button without refreshing the page.

Last edit: 7 years 10 months ago by jschroeder.

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 10 months ago #273450

Hi,

The best would be to use a HikaShop mini cart configured to display only the count number.
Because otherwise, it's a lot more complex. You need to add javascript to that code to be triggered upon add to cart success, you need to then do an ajax request in your javascript to call a specific URL of your website and then customize something (create a plugin for example) to catch that URL and return the number so that you can then update the display. Basically, do the same thing than the cart module we already have.
If you're not a skilled developer it will be difficult to achieve and I can't provide an easy solution to that besides using the HikaShop cart module.

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

  • Posts: 165
  • Thank you received: 3
7 years 10 months ago #273461

nicolas wrote: Hi,

The best would be to use a HikaShop mini cart configured to display only the count number.
Because otherwise, it's a lot more complex. You need to add javascript to that code to be triggered upon add to cart success, you need to then do an ajax request in your javascript to call a specific URL of your website and then customize something (create a plugin for example) to catch that URL and return the number so that you can then update the display. Basically, do the same thing than the cart module we already have.
If you're not a skilled developer it will be difficult to achieve and I can't provide an easy solution to that besides using the HikaShop cart module.


That is unfortunate because I am moving to the new ajax cart and this makes it impossible for me to fully do so. Unfortunately that will not work in my situation. I have a cart module that shows the number, but when you click on the number it expands the cart and shows the "1 items for $10" or whatever the price is. I am a fairly skilled php developer. However, I do not know ajax at all which makes it impossible for me to do this. Below are the pictures attached of what I am trying to achieve. I tired just displaying the $html output twice and just using css to only display the number in 1 area however, that does not work because it causes a javascript error, likely because the ajax is loading twice in 1 page through the $html output.



Also, I have the checkout itself working pretty well in ajax and it does not really make any sense to leave the add to product button in a non ajax environment. This is a very large client and I am guessing legacy mode will either go away at some point or not be supported so I want everything in non legacy mode. It is not cost effect to have to do 2 separate upgrades either.

This seems ridiculous to do so but would it work to load 2 carts inside of each other 1 that is just displaying the quantity and 1 that displays everything else? I would basically display a module position inside the other modules layout override to achieve this or would I get this also cause some sort of conflict?


Also, I have another question and since it mostly related I figured I would just ask it here. I noticed another issue. When you are using the ajax checkout and you login if you have a login box on your site since ajax is being used the state on the login box does not change because the page is not reloading. This is an issue because it appears like you are not logged in until get further through the checkout. Also, I noticed when you login when using the ajax checkout it logs you in but does not scroll you to the top of the page content after logging in so it appears you did not actually log in how do I address this?

Attachments:

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 10 months ago #273463

Hi,

In that case, I see two possible ways to do it without the need of knowing javascript:
1. Configure the slider effect in your template with two module positions: one for the quantity amount and one for the mini cart standard display. Then, have two HikaShop cart modules, one displayed as a mini cart and one just displaying the quantity (it's easy to do that in the file "cart" of the view "product") and assign each one to their respective positions.
That way, the cart modules will refresh themselves automatically.

2. Integrate the slider effect inside the file "cart" of the view "product" so that the module displays the whole slider and the quantity number and the mini cart display. When the cart module will then refresh, it will refresh the whole slider.


Regarding your question about the checkout:
First, please open new threads for unrelated questions.
The Joomla login module not refreshing in that case is indeed an issue we know about. But we can't do much about it since that module doesn't have any javascript refresh feature we could integrate with. The only solution would be to have our own login module, but then you would still have the same issue if you wanted to use another 3rd party login module.
I would just recommend to remove the login module on the checkout since the checkout already provides it.
I didn't understand your point with going to the top of the page? Why going to the top of the page would be necessary for you to know that you're logged in ? You'll usually automatically know that since you'll see the address view instead of the login view or you'll be moved to the next step of the checkout (it depends on how you configure your checkout).

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

  • Posts: 129
  • Thank you received: 0
7 years 9 months ago #273895

Hi,
as you suggested i'm using these line of codes to echo the count of products inside cart without counting the product characteristics or options.
now i want to cut the product quantity from count too.

for example, if i have 3 ipad, 1 iphone, 1 macbook it says there is 5 product inside cart.
i want to count only the product and count 3 or any quantity of ipad as 1 product.

Can you please give me another hint on this topic?

<?php 	
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php'))
				return true;

			$cartClass = hikashop_get('class.cart');
			$fullCart = $cartClass->loadFullCart();
			$nbProducts = 0;
			foreach($fullCart->products as $product){
			    if($product->cart_product_option_parent_id) continue;
			    $nbProducts += $product->cart_product_quantity;
			}
			echo $nbProducts;
		?>

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 9 months ago #273908

Hi,

Then that's easy.

Change the line:
$nbProducts += $product->cart_product_quantity;
to:
$nbProducts += 1;

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

  • Posts: 129
  • Thank you received: 0
7 years 9 months ago #274021

Works like a charm,
thank you! :-)

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

  • Posts: 129
  • Thank you received: 0
7 years 9 months ago #274047

Sorry I got a problem in this case,
when I replace the line with:
$nbProducts += 1;

the counter also count the products with characteristic or options as 2 but the product without characteristic or options are being correctly counted as 1 !

how can I make the code to count the product with characteristic or options as 1 product instead of 2 ?

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
7 years 9 months ago #274054

Hi,

Then change the line to :
$nbProducts += min(1, $product->cart_product_quantity);

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

Time to create page: 0.221 seconds
Powered by Kunena Forum