fbpx

An Exclusive Offer For You To Grab JD Builder ProCheck Deal of The Day

Welcome, Guest
Username: Password: Remember me

You can build one page sites with Astroid

Did you know that you can build one page website web Astroid, without using any 3rd party extension

Watch the tutorial

TOPIC: (SOLVED)Show cart quantity and total in sticky header

Show cart quantity and total in sticky header 3 months 6 hours ago #17237

  • ManuelaK
  • ManuelaK's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Hello,

I want to show the cart quantity and total in the sticky header using the custom social media link.
I edited the /index/templates/jd_boston/features/social.php as following:
$cart = VirtueMartCart::getCart(); //getting cart object */

$products = $cart->products;
$total = 0;
$count = 0;
foreach($products as $product){
    $count += $product->amount;
}
$total = $cart->cartPrices['billTotal'];
...

if( $custom ) {
    if ($count > 0) {
		$html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-cart"></i> '.  $count . '  Artikel € ' . $total  .'  </a></li>';
    }
    else { 
		$html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-cart"></i> </a></li>';		
    }
}

This works fine, but only when I am in the product details or cart page. See attached screenshot.
But when I navigate to the shop frontpage or the product categories or any other page outside the shop, the count and total become zero and so the info is only showing the cart icon.
In the shop itself the cart module is always visible in the sidebar, so the data is there.

Any idea how I can fix this?

I tried this code before getting the cart object, but it did NOT help:
if (!class_exists('VirtueMartCart'))
                  require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php');

Kind regards
Manuela
Attachments:
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17248

  • chandandeep
  • chandandeep's Avatar
  • Offline
  • Administrator
  • Posts: 3154
  • Thank you received: 499
  • Karma: 83
Please share the site URL.
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.

To know more about products check out the their documentation.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17259

  • ManuelaK
  • ManuelaK's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Hello,

the URL is www.herzenspinselwerke.at

Thank you and kind regards
Manuela
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17266

  • chandandeep
  • chandandeep's Avatar
  • Offline
  • Administrator
  • Posts: 3154
  • Thank you received: 499
  • Karma: 83
Include the update_cart.js file. It will help to display the number.
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.

To know more about products check out the their documentation.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17269

  • ManuelaK
  • ManuelaK's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Hello,

sorry for asking, but can you please tell me how I can do this?
include '/index/modules/mod_virtuemart_cart/assets/js/update_cart.js';
does not find the file;

Kind regards
Manuela
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17270

  • ManuelaK
  • ManuelaK's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Now i tried
include JPATH_ROOT . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'mod_virtuemart_cart' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'update_cart.js';

but with the effect that the code of update_cart.js is shown on top of the page and the cart values remain missing.
Attachments:
Last Edit: 2 months 4 weeks ago by ManuelaK.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17273

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Posts: 3070
  • Thank you received: 466
  • Karma: 100
Hi,

The code you used is for including a PHP file but you are including a JS file with it.

You can probably use the below code to get the necessary JS in header, copied from Virtuemart mod_virtuemart_cart.php file.
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig();
vmLanguage::loadJLang('mod_virtuemart_cart', true);
vmLanguage::loadJLang('com_virtuemart', true);
vmJsApi::jQuery();

vmJsApi::addJScript("/modules/mod_virtuemart_cart/assets/js/update_cart.js",false,false);

Thanks,
Chetan
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17285

  • ManuelaK
  • ManuelaK's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
I got it working! B)
But I had to get the $data array - using the $cart array did not change the false behaviour.
	if (!class_exists( 'VmConfig' )) 
		require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
	VmConfig::loadConfig();
	vmLanguage::loadJLang('mod_virtuemart_cart', true);
	vmLanguage::loadJLang('com_virtuemart', true);
	vmJsApi::jQuery();
	vmJsApi::addJScript("/modules/mod_virtuemart_cart/assets/js/update_cart.js",false,false);

	$cart = VirtueMartCart::getCart(false);
	$data = $cart->prepareAjaxData();
	$count = $data->totalProduct;
	$total = $data->billTotal;	
	if ($count > 0) {
		html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-basket"></i> '.  $count . '  Artikel ' . 	$total  .'  </a></li>';
	 }
	 else {  
		html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-basket"></i> </a></li>';
  	}

Thank you so much for your support, I am very happy!

Kind regards
Manuela
Attachments:
Last Edit: 2 months 4 weeks ago by ManuelaK.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17293

  • nishtha
  • nishtha's Avatar
  • Offline
  • Administrator
  • Posts: 410
  • Thank you received: 44
  • Karma: 7
Hi,

Thank you for appreciating our work, your feedbacks are very much valuable for us therefore we'll be happy if you could also rate the template on our website:
www.joomdev.com/products/templates/jd-boston-template

Thanks,
Nishtha
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.

To know more about products check out the their documentation.
Last Edit: 2 months 4 weeks ago by nishtha.
The topic has been locked.

Show cart quantity and total in sticky header 2 months 4 weeks ago #17297

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Posts: 3070
  • Thank you received: 466
  • Karma: 100
ManuelaK wrote:
I got it working! B)
But I had to get the $data array - using the $cart array did not change the false behaviour.
	if (!class_exists( 'VmConfig' )) 
		require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
	VmConfig::loadConfig();
	vmLanguage::loadJLang('mod_virtuemart_cart', true);
	vmLanguage::loadJLang('com_virtuemart', true);
	vmJsApi::jQuery();
	vmJsApi::addJScript("/modules/mod_virtuemart_cart/assets/js/update_cart.js",false,false);

	$cart = VirtueMartCart::getCart(false);
	$data = $cart->prepareAjaxData();
	$count = $data->totalProduct;
	$total = $data->billTotal;	
	if ($count > 0) {
		html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-basket"></i> '.  $count . '  Artikel ' . 	$total  .'  </a></li>';
	 }
	 else {  
		html .= '<li><a href="index.php/shop/cart"><i class="fa fa-shopping-basket"></i> </a></li>';
  	}

Thank you so much for your support, I am very happy!

Kind regards
Manuela
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.
The topic has been locked.
Time to create page: 0.234 seconds