Cart Items Count with product options

  • Posts: 69
  • Thank you received: 2
  • Hikashop Business Hikashop Style
3 years 5 months ago #166192

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.3
-- PHP version -- : 5.4.30
-- Browser(s) name and version -- : any
-- Error-message(debug-mod must be tuned on) -- : none

Is there any way to correct for the number of items in the Cart module...it is counting the product's options as well as the product. Example: a product has an option to engrave. When that option is selected two items are actually added to the cart.

even though we have Group options as one item, the cart count reflects all of the parts and pieces.

While we're at trying to combine or group product options, is there a global php or session variable that has the Item count? We would like to hide the shopping cart module if the cart is empty and we don't like the workaround in changing the language string to a null because then we get messages without any text in them elsewhere in the cart.

If we could do something like "return $cart->items > 0" to show the module in NoNumber Advance Module manager, that would be awesome!

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

  • Posts: 60535
  • Thank you received: 8531
  • MODERATOR
3 years 5 months ago #166223

Hi,

I just did a test with the latest version of HikaShop on our demo website and it's not counting the options for the number of items in the cart module. You can try yourself by just turning on the mini cart option of the cart module there.
So if that's not the case on your website, it means that the "cart" file of the view "product" has been modified. You can go in the menu Display>Views and check for any customization and revert to the current code of the cart module and you should then get the proper number of items.

There is no global PHP or session variable where the items count is stored. It is calculated dynamically by the cart module.
If you want to calculate it yourself, you can use such code:

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

The following user(s) said Thank You: stratacorps

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

  • Posts: 69
  • Thank you received: 2
  • Hikashop Business Hikashop Style
3 years 5 months ago #166248

That code works perfectly for hiding the shopping cart module with tools like AMM (NoNumber)!! On the last line I changed it to "return $number_of_items;" and if its greater than 0, you get the cart! Nothing, No Cart module AND we can keep our Cart Empty message so we don't get blank messages on the rest of the site.

EDIT: is there a way to directly refer to the function class hikashop_get ... when its not on a Hikashop page it errors out.

And, as I speak my number of items count problem isn't happening. I have screen shots, but since it won't do you any good because all it says is "2 Items" and not the detail. I turned on to show the detail in the mod_cart, but then the count is correct. It doesn't matter...I can hide my cart!! Weird how small things can mean so much to you!

Last Edit: 3 years 5 months ago by stratacorps. Reason: Update

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

  • Posts: 60535
  • Thank you received: 8531
  • MODERATOR
3 years 5 months ago #166251

That code will indeed only work if HikaShop is loaded. If you want to add it somewhere where HikaShop is not loaded, you need to load HikaShop first with such code:

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;

The following user(s) said Thank You: stratacorps

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

  • Posts: 69
  • Thank you received: 2
  • Hikashop Business Hikashop Style
3 years 5 months ago #166307

That did it! My final Custom PHP set to Include looks like this:

if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php'));
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart();
$number_of_items = 0;
foreach($cart->products as $product){
 if($row->cart_product_option_parent_id) continue;
 $number_of_items+=$product->cart_product_quantity;
}
return $number_of_items;
Thanks again

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

  • Posts: 7
  • Thank you received: 1
  • Hikashop Business
3 weeks 20 hours ago #285134

Is it Possible to Update quantity without page refresh like shoping cart after click ADD TO CART ?

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

  • Posts: 21769
  • Thank you received: 3404
  • MODERATOR
3 weeks 12 hours ago #285145

Hello,

Sure, with the ajax system of HikaShop 3.x it's possible !
www.hikashop.com/home/blog/357-hikashop-3-0-beta.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: Eesty

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

  • Posts: 7
  • Thank you received: 1
  • Hikashop Business
2 weeks 6 days ago #285173

Thank you !

But it will be nice if you can tell me what i have to do with that code:

window.Oby.registerAjax(["cart.updated","wishlist.updated"],function(params){
	/*
		params.type : 'cart' or 'wishlist'
		params.id : the cart id. If NaN, it has failed.
		params.el : the dom element where the customer clicked to add the product into the cart
		params.product_id : the product id
		params.resp : object
			ret : the cart id, if 0, it has failed
			product_name : the name of the product
			quantity : the quantity of the product
			image : the url of the product image (50x50)
	*/
	});
I need only updated the Quantity here:
<?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'));
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart();
$number_of_items = 0;
foreach($cart->products as $product){
 if($row->cart_product_option_parent_id) continue;
 $number_of_items+=$product->cart_product_quantity;
}
return $number_of_items;

?>
<?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;
?>
<?php
echo '<div id="mydiv" class="uk-badge uk-badge-success uk-badge-notification">'.$number_of_items.'</div>';
?>
Maybe i need to add this code to the add to cart button ?
It will be nice, if someone can help me here.

my Store:
www.picknstick.de and the Count is on the right top !
Styled with uikit.

Last Edit: 2 weeks 6 days ago by Jerome. Reason: [code] tag is the best for code !!

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

  • Posts: 69
  • Thank you received: 2
  • Hikashop Business Hikashop Style
2 weeks 6 days ago #285175

Eesty,

Can you look at www2.breedsofcattle.net/shop and interact with he HS 3.1 store there to see if this is what you are trying to do?

This installation makes use of the optional popup display plugin which can be disabled. However in the upper righthand corner there is a shopping cart icon and “badge” counter. The icon is generated via the standard HS cart module using a language override that contains a font awesome cart icon and html code. Along with some simple css for placement. Whenever an item is added to the cart the icon is updated by the cart module via ajax (without refreshing the page).

Note that the site also uses a popup to display the cart contents if you click on the cart count icon, but that is also optional and uses a 3rd part element handler and another instance of the HS cart module.

Last Edit: 2 weeks 6 days ago by stratacorps.

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

  • Posts: 21769
  • Thank you received: 3404
  • MODERATOR
2 weeks 6 days ago #285177

Hello,

I'm not sure to understand what you're trying to do.

The HikaShop cart module is already compatible with the Ajax system and that module already have a "mini cart" mode which allow to display only minimal information.
So I don't see why you're trying to do some custom code while the feature is already there, as presented in the page I linked previously.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: Eesty

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

  • Posts: 7
  • Thank you received: 1
  • Hikashop Business
2 weeks 6 days ago #285190

Thank you i got it ! =)

just change: lagnuage ini :)

nice work !

The following user(s) said Thank You: Jerome

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

  • Posts: 69
  • Thank you received: 2
  • Hikashop Business Hikashop Style
2 weeks 6 days ago #285192

Eesty, I wasn't sure that was what you were trying to do. So that it is, note that there are TWO language overrides (you don't have to edit the .ini files directly, just use the default Joomla! Language override and add the appropriate overrides for X_ITEM and X_ITEMS

This is what I am using, but I am using font-awesome for the icon...but its just html either way...

<span id="cart-icon" class="fa-stack fa-fw has-badge" data-count="%s"> <i class="fa fa-shopping-cart fa-stack-2x fa-fw"></i> </span>
Also, on the cart module settings, we disable everything but quantity, and for the Empty Cart, we select Custom and I put a "0" in the custom empty cart message. Then I just used CSS template overrides to put the necessary display adjustments for the badge to display over the icon...like Amazon or many other shopping carts out there.

It would be nice if HS had a mini-cart option for the cart icon/badge count display. Its a common thing, and this work-around took me awhile to figure it out :( But since its using the new ajax code, you don't have to change anything in the core of the system or worry about custom javascript!

EDIT: also note that if the cart is empty, this string will be hidden. I wish there was a better way so it would show a "0" (zero) instead of just hiding it.

Last Edit: 2 weeks 6 days ago by stratacorps.

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

Time to create page: 0.110 seconds
Powered by Kunena Forum