How to refresh a module with ajax based on checkout shipping method?

  • Posts: 231
  • Thank you received: 28
  • Hikashop Business
3 years 8 months ago #331120

-- url of the page with the problem -- :

This message contains confidential information

-- HikaShop version -- : 4.4.1
-- Joomla version -- : 3.9.25

Hi,
I have create a module which is taking his details from the cart.
I configurated this module to be visible in Hikashop Checkout, using the text view, by adding this tag to load the module.
{module id="116:Hikashop Custom Module" showtitle="false"}
.
And now, i need the module to refresh himself when the shipping method is changed, how can I do this?
Please give me as many details, javascript it's not my strong point.
Loading the module in checkout


Visible in Front-page

Attachments:
Last edit: 3 years 8 months ago by oxido. Reason: I have attached the module.

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
3 years 8 months ago #331146

Hi,

Well, a simple solution would be to add the code of your module directly in one of the view files which is refreshed when the shipping method is changed.
For example, you have the "status" view which just displays the selected shipping and payment methods. If you don't use it, you could repurpose it with your own code to display your custom content on the checkout and the show_block_status where you would add your code already has the javascript code to refresh itself when the shipping method is changed:

<script type="text/javascript">
if(!window.checkout) window.checkout = {};
window.Oby.registerAjax(['checkout.shipping.updated','checkout.payment.updated'], function(params){
	window.checkout.refreshStatus(<?php echo (int)$this->step; ?>, <?php echo (int)$this->module_position; ?>);
});
window.checkout.refreshStatus = function(step, id) { return window.checkout.refreshBlock('status', step, id); };
</script>
Now if you want to stick to your solution with the loadposition in the "text" view, you would need to add such similar javascript to the show_block_text view file via the menu Display>Views.

The following user(s) said Thank You: oxido

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

  • Posts: 231
  • Thank you received: 28
  • Hikashop Business
3 years 6 months ago #332041

For future me and others:

edit the view: checkout / show_block_status.php

// Create a position for module: checkout-position
// prepare content to be rendered corectly with "content.prepare".
echo JHtml::_('content.prepare', '{loadposition checkout-position}');
Now you can set any module to be visible to this position, and it will be refreshed by ajax.

PS. Thx nicolas!

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

Time to create page: 0.065 seconds
Powered by Kunena Forum