Cart Items Count with product options

  • Posts: 116
  • Thank you received: 7
  • Hikashop Business
9 years 7 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: 81361
  • Thank you received: 13035
  • MODERATOR
9 years 7 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: 116
  • Thank you received: 7
  • Hikashop Business
9 years 7 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: 9 years 7 months ago by stratacorps. Reason: Update

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

  • Posts: 81361
  • Thank you received: 13035
  • MODERATOR
9 years 7 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: 116
  • Thank you received: 7
  • Hikashop Business
9 years 7 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
6 years 2 months 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: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 2 months 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
6 years 2 months 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: 6 years 2 months ago by Jerome. Reason: [code] tag is the best for code !!

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

  • Posts: 116
  • Thank you received: 7
  • Hikashop Business
6 years 2 months 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: 6 years 2 months ago by stratacorps.

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

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 2 months 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
6 years 2 months 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: 116
  • Thank you received: 7
  • Hikashop Business
6 years 2 months 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: 6 years 2 months ago by stratacorps.

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

  • Posts: 75
  • Thank you received: 1
5 years 3 months ago #301350

Trying to do similar thing but where did you put the mod?

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

  • Posts: 116
  • Thank you received: 7
  • Hikashop Business
5 years 3 months ago #301351

Are you replying to the latter portion of the thread that I was involved in? The icon/with cart count?

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

  • Posts: 75
  • Thank you received: 1
5 years 3 months ago #301379

Yeah, that's the bit I was looking at, You seem to have a pretty simple solution.

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

  • Posts: 116
  • Thank you received: 7
  • Hikashop Business
5 years 3 months ago #301403

spotstv wrote: Yeah, that's the bit I was looking at, You seem to have a pretty simple solution.

Okay, I felt like I may have hijacked the thread from before.

The hikashop cart module can be placed anywhere you want the icon/badge to show up. On my projects I place it at the top right corner. In fact I create a special module position for it now.

In the module, I create a custom class suffix to help control the positioning and layout and make it float right.

For the Hikashop module settings I have:

Data display: mini cart = yes, product quantities = yes, and hide if empty = custom ("0") --all other options No.
Price data display: display price = no
Display: all set to yes, but can be anything ... I like it showing up all of the time

Then change the language strings as mentioned before to control what is displayed by the module. If you don't use font awesome for the cart icon, you'll need to change this to include the image you plan on using.
X_ITEM and X_ITEMS language overrides:
 <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>



I create a second instance of the Hikashop cart module and place it in a hidden position and then use a pop-up to control the display of the cart's contents itself (I use Engage box). That way when you click on the cart icon, the user gets a pop-up of the cart contents and the ability to proceed to checkout. You could do this with any javascript/onclick action.

here is the css customization I use. This creates the cart item count as a badge to the cart icon. So in the cart icon module, I use a module suffix of top-cart-badge, so my css looks like:
//shopping cart icon/badge
#g-top .top-cart-badge {
	 text-align: right;
	 top: 0;
	 right: 0;
	 z-index: 99;
	 position: absolute;
	 float: right;
	 padding: 10px 16px; 
	 margin-right: 2px; 
} 
.top-cart-badge #cart-icon { 
	 width: 2em; 
	 padding-top: 0; 
	 margin-top: 0; 
} 
.top-cart-badge .fa-stack[data-count]:after { 
	 position: absolute; 
	 right: -40%; 
	 top: -10%; 
	 content: attr(data-count); 
	 font-size: 65%; 
	 padding: .1em 0; 
	 border-radius: 999px; 
	 line-height: 1.35em; 
	 color: $accent-color-1; 
	 background: $white; 
	 text-align: center; 
	 min-width: 2.5em; 
}

Attachments:
Last edit: 5 years 3 months ago by stratacorps.

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

Time to create page: 0.114 seconds
Powered by Kunena Forum