Show cart module only when it has something in

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 10 months ago #87370

I think that a solution could be to add some Javascript in the view "product / cart".
Try to use the following Javascript if there is no products in the cart:

<script type="text/javascript">
var cart_module = document.getElementById('hikashop_cart_module');
var parent = cart_module.getParent();
parent.style.display='none';
</script>

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

  • Posts: 16
  • Thank you received: 1
5 years 10 months ago #87389

The script does get rid of the empty cart but it also removes it when there's an item in it. So not quite there.

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 10 months ago #87469

if there is no products in the cart:


You can add the previous code in the php check like:
<?php if(empty($this->rows)){ ?>
<script type="text/javascript">
var cart_module = document.getElementById('hikashop_cart_module');
var parent = cart_module.getParent();
parent.style.display='none';
</script>
<?php } ?>

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

  • Posts: 16
  • Thank you received: 1
5 years 10 months ago #88425

Silly me. I understand now and it works great. Just one last thing, is it possible to show the module title only when there's an item in it?

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 10 months ago #88556

This code should hide the module title too when empty cart.

You can try to add a suffix to the module in the Joomla option, set something like "-cart".
Then use the code:

<?php if(empty($this->rows)){ ?>
<script type="text/javascript">
var cart_module = document.getElementById('moduletable-cart');
cart_module.style.display='none';
</script>
<?php } ?>

Replace "moduletable-cart" by the class of your module, you can find it with, for example, firebug.

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

  • Posts: 16
  • Thank you received: 1
5 years 10 months ago #88573

Still no luck. I've attached the code for cart.php. Maybe I'm doing something wrong.

File Attachment:

File Name: cart.txt
File Size:19 KB

Attachments:

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 10 months ago #88632

You don't use the good id.
Could you give me a backend access via mp ?

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

  • Posts: 51
  • Thank you received: 0
5 years 9 months ago #92472

hello
i m trying to do the same thing and i have the same problem
could you help please ?

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

  • Posts: 64127
  • Thank you received: 9251
  • MODERATOR
5 years 9 months ago #92706

Hi,

Well the solution is the same. You shoudl be able to do it with AMM. Otherwise, the code modification proposed by Xavier is also a solution. Just do as explained in the previous messages.

The following user(s) said Thank You: gili

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

  • Posts: 51
  • Thank you received: 0
5 years 9 months ago #92762

hello
i tried to use xaviers code but it does not hide the title of module

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 9 months ago #92867

Could you give us a link to your website ?

The following user(s) said Thank You: gili

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 9 months ago #93057

Solved.

The way to do that is:
- In the Joomla cart module options, at the end of the "Module Class Suffix" option add :

" id="cart_module"
- At the end of the view "product / cart" add the code:
<?php if(empty($this->rows)){ ?>
<script type="text/javascript">
var cart_module = document.getElementById('cart_module');
cart_module.style.display='none';
</script>
<?php } ?>

The following user(s) said Thank You: gili

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

  • Posts: 51
  • Thank you received: 0
5 years 9 months ago #93660

hello
after this script
when i click on the categories (Κατηγορίες) on one of the subcategories the module disappears and only the title remains
helppp !!!! :)

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 9 months ago #93857

Hi,

The problem don't come from the script.
It's due to the parameters of the module "Κατηγορίες", it display content depending on the category displayed.
If the category have no sub categories so it's empty.

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

  • Posts: 51
  • Thank you received: 0
5 years 9 months ago #93870

hello
i m not sure i understood that. could u please tell me the steps to fix it ????
regards

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

  • Posts: 64127
  • Thank you received: 9251
  • MODERATOR
5 years 9 months ago #94032

The solution of Xavier won't hide the title of the module.
If you don't want that, you should use the solution with AMM.

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

  • Posts: 51
  • Thank you received: 0
5 years 8 months ago #94113

hello
what xavier did and said to me worked perfectly to the module i wanted
the problem is to another module so i asked whats wrong with the other one and how to fix it !
regards

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

  • Posts: 64127
  • Thank you received: 9251
  • MODERATOR
5 years 8 months ago #94456

Ah ok, I had read too fast.
That's because you have the "Synchronize with currently displayed item when possible" turned on in the hikashop options of your module. You should turn off that option.

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

  • Posts: 16
  • Thank you received: 1
5 years 8 months ago #97117

Hello Xavier,

I have tried your last solution with the Module Class Suffix and Product/Cart and it does hide the cart when empty. However the problem is that when you add an item to the cart, the cart doesn't show up. It only shows up once you've refreshed the page.

Can you help?

Thanks
Erik

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

  • Posts: 13201
  • Thank you received: 2316
  • MODERATOR
5 years 8 months ago #97307

Hi,

Do you have the latest version of HikaShop ?
Can you try to change the value for the option "Use AJAX when possible for add to cart buttons", option in Config > Main > Advanced settings.

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

Time to create page: 0.133 seconds
Powered by Kunena Forum