Jump to content

Blockwishlist: Uncaught Referenceerror: Islogged Is Not Defined


Recommended Posts

Good morning everyone,

 

I have a problem with blockwishlist module and i can't find a solution to it.

 

I read in numerous threads  that you have to add blockwishlist to the rightcolumn modules so it can load the ajax-wishlist.js. I have done this and ajax-wishlist.js is successfully loaded. But i have another issue. When i click Add to wishlist i get a javascript error displayed in my console saying:

 

Uncaught ReferenceError: isLogged is not defined

 

First i went to my /themes/template/modules/blockwishlist and i renamed the folder so it only loads from /modules/blockwishlist folder. But the error didn't seem to go away. Also i checked if there is a ajax-wishlist.js at /themes/template/js/...*... but there is none.

 

In the ajax-wishlist.js file there is this code:

$.ajax({
		type: 'GET',
		url: baseDir + 'modules/blockwishlist/cart.php?rand=' + new Date().getTime(),
		headers: { "cache-control": "no-cache" },
		async: true,
		cache: false,
		data: 'action=' + action + '&id_product=' + id_product + '&quantity=' + quantity + '&token=' + static_token + '&id_product_attribute=' + id_product_attribute + '&id_wishlist=' + id_wishlist,
		success: function(data)
		{
			if (action == 'add')
			{
				if (isLogged == true) {
					wishlistProductsIdsAdd(id_product);
					wishlistRefreshStatus();

					if (!!$.prototype.fancybox)
						$.fancybox.open([
							{
								type: 'inline',
								autoScale: true,
								minHeight: 30,
								content: '<p class="fancybox-error">' + added_to_wishlist + '</p>'
							}
						], {
							padding: 0
						});
					else
						alert(added_to_wishlist);
				}
				else
				{
					if (!!$.prototype.fancybox)
						$.fancybox.open([
							{
								type: 'inline',
								autoScale: true,
								minHeight: 30,
								content: '<p class="fancybox-error">' + loggin_required + '</p>'
							}
						], {
							padding: 0
						});
					else
						alert(loggin_required);
				}
			}
			if (action == 'delete') {
				wishlistProductsIdsRemove(id_product);
				wishlistRefreshStatus();
			}
			if($('#' + id).length != 0)
			{
				$('#' + id).slideUp('normal');
				document.getElementById(id).innerHTML = data;
				$('#' + id).slideDown('normal');
			}
		}
	});

So i went before the if (isLogged == true) and added

var isLogged = true;

Then everything worked fine.

 

So my question is how can i fix this?

How can i declare this variable correctly, so that the JS knows if a user is logged in or no?

 

PS I have updated blockwishlist module to latest version

 

Information:

http://exxesfashion.com/en/earings/1325-earings-code-9921.html

Prestashop Version: 1.6.0.6

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

Hi everybody!

I have the same problem in prestashop 1.6.

I make a solution, probably is not the best solution (because I didn't look for the origin: why the variable doesn't work?), but it works for me.

So I hope it can help someone!

 

The idea is simple: add the variable to the ajax function overriden the module.

1º choose the template you are using in your theme (in my case: blockwishlist-extra.tpl)

/themes/my_theme/modules/blockwishlist/blockwishlist-{your_template}.tpl

and on the click function add: , '{if $logged}1{else}0{/if}'

<a class="add_to_closet" href="#" id="wishlist_button" onclick="WishlistCart('wishlist_block_list', 'add', '{$id_product|intval}', $('#idCombination').val(), document.getElementById('quantity_wanted').value, '{if $logged}1{else}0{/if}'); return false;"  title="{l s='Add to my wishlist' mod='blockwishlist'}" rel="nofollow"> + {l s='Add to Closet' mod='blockwishlist'}</a>

2º override also the function WishlistCart, 2 little changes:

/themes/my_theme/js/modules/blockwishlist/js/ajax-wishlist.js --> function WishlistCart(id, action, id_product, id_product_attribute, quantity, logged) and if (logged == true)

function WishlistCart(id, action, id_product, id_product_attribute, quantity, logged)
{
	$.ajax({
		type: 'GET',
		url: baseDir + 'modules/blockwishlist/cart.php?rand=' + new Date().getTime(),
		headers: { "cache-control": "no-cache" },
		async: true,
		cache: false,
		data: 'action=' + action + '&id_product=' + id_product + '&quantity=' + quantity + '&token=' + static_token + '&id_product_attribute=' + id_product_attribute,
		success: function(data)
		{
			if (action == 'add')
			{
				if (logged == true) {
					wishlistProductsIdsAdd(id_product);
					wishlistRefreshStatus();
		            if (!!$.prototype.fancybox)
		                $.fancybox.open([
		                    {
		                        type: 'inline',
		                        autoScale: true,
		                        minHeight: 30,
		                        content: '<p class="fancybox-error">' + added_to_wishlist + '</p>'
		                    }
		                ], {
		                    padding: 0
		                });
		            else
		                alert(added_to_wishlist);
				}
				else
				{
		            if (!!$.prototype.fancybox)
		                $.fancybox.open([
		                    {
		                        type: 'inline',
	                                autoScale: true,
		                        minHeight: 30,
		                        content: '<p class="fancybox-error">' + loggin_required + '</p>'
		                    }
		                ], {
		                    padding: 0
		                });
		            else
		                alert(loggin_required);
				}
			}
			if (action == 'delete') {
				wishlistProductsIdsRemove(id_product);
				wishlistRefreshStatus();
			}
			if($('#' + id).length != 0)
			{
				$('#' + id).slideUp('normal');
				document.getElementById(id).innerHTML = data;
				$('#' + id).slideDown('normal');
			}
		}
	});
}

That's all!

Have a nice day! :)

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...