Cool!
Thanks very much Xavier.
I now have a cool icon for empty and full shopping bag with the number of selected items on top.
It uses the modals extension from Regular Labs to display a modal window of the shopping cart.
I still have two issues.
Here's the PHP code of the module:
<?php
$cartClass = hikashop_get('class.cart');
$fullCart = $cartClass->loadFullCart();
$nbProducts = 0;
foreach($fullCart->products as $product){
$nbProducts += $product->cart_product_quantity;
}
if ($nbProducts == 0){
echo "{modal /index.php?options=com_content&view=article&id=2}" .
"<div class='emptyCartIcon'></div>{/modal}";
}
else {
echo "{modal /index.php?options=com_content&view=article&id=2}" .
"<div class='fullCartIcon'><h6>" .
$nbProducts .
"</h6></div>{/modal}";
}
?>
Here's the css (should anyone wish to implement it)
.emptyCartIcon{
margin-right: 2em;
margin-left: 2em;
width:40px;
height:50px;
background: url(/images/shoppingBagEmpty.png);
}
.fullCartIcon{
margin-right: 2em;
margin-left: 2em;
position: relative;
width:40px;
height:50px;
background: url(/images/shoppingBagFull.png);
}
.fullCartIcon h6{
display: inline-block;
position: absolute;
bottom: 1px;
right: 1px;
background-color: purple;
color: white;
font-size: 0.7em;
width: 0.7em;
font-weight: bold;
text-align: center;
-moz-border-radius:0.25em;
-webkit-border-radius:0.25em;
border-radius:0.25em;
}
My Issues:
1. The icon is updated only upon page reload. This doesn't always happen.
Is there some sort of a listener I can hook to (Ajax or other), so the icon will receive an update when the cart content is changed?
2. When loading "regular" Joomla pages, not related to Hikashop, the code freezes everything and the page will not display.
I guess it is a scope issue. When a H.S. page loads, PHP gets the scope of H.S. With regular pages this doesn't happen.
Any advice on how to overcome this???
By the way, I think such an icon at the top of the shop's page should be an integral part of Hikashop.