Jump to content

how to show blockcart-modal from any html element ?


timot

Recommended Posts

Hello,

I would like my cart button to show the whole ajax blockcart modal instead of showing a dropdown menu.

On the cart button I've tried to change

data-toggle="dropdown"

to

data-toggle="blockcart-modal"

with no success...

onclick="prestashop.blockcart.showModal()"

doesn't work either, with no javascript error.

I can't find any info on how to trigger the cart modal show up.

 

Would anyone have any idea ?

Link to comment
Share on other sites

If think I should have mentioned it, is use the falcon starter theme, with its is_blockcart module.

The modal block get triggered by this function :
https://github.com/Oksydan/is_shoppingcart/blob/731b7ba31ab7e05747c98b4c197046384886cd3e/_theme_dev/src/js/theme/index.js#L74

Then I guess I should find a way to trigger this

prestashop.on('updateCart')

event ? (do you think this is possible without updating the cart content ?)
nothing happens with :

onclick="prestashop.updateCart"

or copy and adapt the whole function...

Edited by timot (see edit history)
Link to comment
Share on other sites

Hi.

If you have a template other than classic installed, how can we advise you if we don't see what you need and we don't even know your version of Prestashop.

Please give us a screenshot of what you have now and what you need.

Link to comment
Share on other sites

Thanks for your answer @ps8modules

Sorry I try to keep it simple as much as possible... It's true I use is_shoppingcart and I don't really know how much it differs from ps_shoppingcart...
My question might be misplaced ?


Then I try to copy this ajax function but no matter what, I can't get this modal content :

I'm trying to keep it short :

const refreshURL = document.querySelector('.js-blockcart').dataset.refreshUrl;
let requestData = {};
requestData = {
	ajax: 1,
};
requestData = Object.keys(requestData).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(requestData[key])}`).join('&');

fetch(refreshURL, {
	method: 'POST',
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded',
	},
	body: requestData,
	})
	.then((resp) => resp.json())
	.then((resp) => {
		if (resp.modal) {
			showModal(resp.modal);
		}
	})

refreshURL is set to /module/is_shoppingcart/ajax

With this code I do have a resp.preview but I don't get any resp.modal

Whereas in the orginal function the only difference (I think) was that requestData were more populated (because of the updating of the cart) :

requestData = {
  id_customization: event.reason.idCustomization,
  id_product_attribute: event.reason.idProductAttribute,
  id_product: event.reason.idProduct,
  action: event.reason.linkAction,
  ajax: 1,
};

And resp.modal was filled.

Would you think of any way to force this modal setting while fetching /module/is_shoppingcart/ajax ?

Edited by timot (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...