Jump to content
Sign in to follow this  
tmcca

Wishlist For Phoenix

Recommended Posts

58 minutes ago, LeeFoster said:

@kgtee Where/when is the function add_wishlist called?

@LeeFoster When the button "save to wishlist" is clicked, the session parameters registered for wishlist are invoked and passed on to application_top.php to take wishlist actions.

Share this post


Link to post
Share on other sites
16 minutes ago, kgtee said:

@LeeFoster When the button "save to wishlist" is clicked, the session parameters registered for wishlist are invoked and passed on to application_top.php to take wishlist actions.

OK, I've found the cause of the issue, @burt's supporters code #27 Ajax Buy Buttons overrides the functions of the Add to Wish List button. Turning off this Header Tags module fixes the Add to Wish List addon but obviously removes the function added by this.

Share this post


Link to post
Share on other sites
17 minutes ago, LeeFoster said:

OK, I've found the cause of the issue, @burt's supporters code #27 Ajax Buy Buttons overrides the functions of the Add to Wish List button. Turning off this Header Tags module fixes the Add to Wish List addon but obviously removes the function added by this.

This wishlist mod is coded in a way that is inconsistent with the rest of Phoenix.  

A null link button in a form SUBMITs the form...that is the root cause.

Give the wishlist button a href that links to the wishlist action.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites
4 minutes ago, burt said:

This wishlist mod is coded in a way that is inconsistent with the rest of Phoenix.  

A null link button in a form SUBMITs the form...that is the root cause.

Give the wishlist button a href that links to the wishlist action.

Thanks @burt I'll look into that unless @kgtee beats me to it.

Share this post


Link to post
Share on other sites
5 hours ago, burt said:

Give the wishlist button a href that links to the wishlist action. 

The problem is that it needs to submit the form to get the attributes.  I.e. submitting the form is the correct behavior here.  The issue is that it needs to submit the form differently when it is a wishlist from when it is adding to cart. 

Note that if people are already using AJAX to submit the form, then they can use Javascript to change the form submission URL or to add a "Wishlist" input that is only posted with the Wishlist.  Then the current behavior would be a fall back for the non-Javascript case. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

https://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form

Two form submit buttons were coded from day 1 by the original contributor and they did not have any problem. As they each have their own name and value, I should see that this has avoided any problem. The contributor has even highlighted that the wishlist actions should be placed before the shopping cart actions. This is really clever. 😄

Share this post


Link to post
Share on other sites
10 minutes ago, kgtee said:

https://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form

Two form submit buttons were coded from day 1 by the original contributor and they did not have any problem. As they each have their own name and value, I should see that this has avoided any problem. The contributor has even highlighted that the wishlist actions should be placed before the shopping cart actions. This is really clever. 😄

So is something out of the proper order then?

Share this post


Link to post
Share on other sites
<script>$(document).ready(function(){ $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).parents('form:first');
    form.appendChild(input);
    form.submit();

    return false;
  }});
</script>

I think that this would fix it. 

To test it, you could add this into the existing header tag module with which you are having trouble, as that already adds scripts to the footer.  But you might then want to move it into its own module or hook after establishing that it works. 

The problem is that the AJAX submission is not passing which button was clicked to submit the form.  Which makes sense because there is only one button in the default install.  So  if Javascript is running, this adds a form input to the form when that button is clicked. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
21 minutes ago, ecartz said:

<script>$(document).ready(function(){ $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).parents('form:first');
    form.appendChild(input);
    form.submit();

    return false;
  }});
</script>

I think that this would fix it. 

To test it, you could add this into the existing header tag module with which you are having trouble, as that already adds scripts to the footer.  But you might then want to move it into its own module or hook after establishing that it works. 

The problem is that the AJAX submission is not passing which button was clicked to submit the form.  Which makes sense because there is only one button in the default install.  So  if Javascript is running, this adds a form input to the form when that button is clicked. 

Thanks, I'll try this tomorrow.

Share this post


Link to post
Share on other sites
6 hours ago, ecartz said:

<script>$(document).ready(function(){ $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).parents('form:first');
    form.appendChild(input);
    form.submit();

    return false;
  }});
</script>

I think that this would fix it. 

To test it, you could add this into the existing header tag module with which you are having trouble, as that already adds scripts to the footer.  But you might then want to move it into its own module or hook after establishing that it works. 

The problem is that the AJAX submission is not passing which button was clicked to submit the form.  Which makes sense because there is only one button in the default install.  So  if Javascript is running, this adds a form input to the form when that button is clicked. 

Hmmm. You threw me off when you said add to existing header tag module. I believe this version doesn't have that. But I also have no need to doubt you because your level of code is light years beyond my understanding. So I'll place it around until I find the correct spot.

Thanks for your help sir.

Share this post


Link to post
Share on other sites

The problem that LeeFoster identified was a conflict with another App.  If he turned off the header_tag module from the other App, he could get the Wishlist to work.  That App has a header_tag module. 

The ideal would be to add this as its own header_tag module that adds to footer_scripts but for testing purposes, anything that adds to footer_scripts would probably work.  For testing purposes (to verify that it works), you could add it to template_bottom.  But that would put it on every page even though it's only needed on the product_info page. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
10 minutes ago, ecartz said:

The problem that LeeFoster identified was a conflict with another App.  If he turned off the header_tag module from the other App, he could get the Wishlist to work.  That App has a header_tag module. 

The ideal would be to add this as its own header_tag module that adds to footer_scripts but for testing purposes, anything that adds to footer_scripts would probably work.  For testing purposes (to verify that it works), you could add it to template_bottom.  But that would put it on every page even though it's only needed on the product_info page. 

When I added that script to template_bottom it didn't work. The same behavior. There's code in application_top: 

// BOF WISHLIST
// wishlist data
	if (!tep_session_is_registered('wishList') || !is_object($wishList)) {
		tep_session_register('wishList');
		$wishList = new wishlist;
	}
	
//Wishlist actions (must be before shopping cart actions)
  if (isset($_POST['wishlist'])) {
	  if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
      $attributes = isset($_POST['id']) ? $_POST['id'] : '';

        // php 5
        $qty = isset($_POST['qty']) ? (int)$_POST['qty'] : 1;
        // php 7
        // $qty = (int)($_POST['qty'] ?? 1);

      $wishList->add_wishlist($_POST['products_id'], $wishList->get_quantity(tep_get_uprid($_POST['products_id'], $attributes))+$qty, $attributes);
	  }
		if (WISHLIST_REDIRECT ==  'No') tep_redirect(tep_href_link('product_info.php', 'products_id=' . $_POST['products_id']));
	  tep_redirect(tep_href_link('wishlist.php'));
  }
// EOF WISHLIST

Then there's the class file in which does the work of the button. As @LeeFoster stated it works once the Ajax buttons is turned off. 

Share this post


Link to post
Share on other sites
1 hour ago, ecartz said:

The problem that LeeFoster identified was a conflict with another App.  If he turned off the header_tag module from the other App, he could get the Wishlist to work.  That App has a header_tag module. 

The ideal would be to add this as its own header_tag module that adds to footer_scripts but for testing purposes, anything that adds to footer_scripts would probably work.  For testing purposes (to verify that it works), you could add it to template_bottom.  But that would put it on every page even though it's only needed on the product_info page. 

I added the code into the header_tag module and still the same error.

Share this post


Link to post
Share on other sites
3 minutes ago, LeeFoster said:

I added the code into the header_tag module and still the same error.

Is it publicly available?  Could you PM me a link? 


Always back up before making changes.

Share this post


Link to post
Share on other sites
Just now, ecartz said:

Is it publicly available?  Could you PM me a link? 

It's not unfortunately it's one of the paid Phoenix addons.

Unless you mean wishlist in which case it is.

Share this post


Link to post
Share on other sites

I mean your store where you have it installed.  I have files for both Apps but I don't have them installed. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
Just now, ecartz said:

I mean your store where you have it installed.  I have files for both Apps but I don't have them installed. 

Ah, no it's not. Still in development.

Share this post


Link to post
Share on other sites
<script>$(document).ready(function() { $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).closest('form');
    form.unbind('submit');
    form.append(input);
    form.submit();

    return false;
  });});
</script>

 


Always back up before making changes.

Share this post


Link to post
Share on other sites
4 minutes ago, ecartz said:

<script>$(document).ready(function() { $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).closest('form');
    form.unbind('submit');
    form.append(input);
    form.submit();

    return false;
  });});
</script>

 

Adding that to template bottom does the trick. Now to turn it in to a hook along with the other core change.

Share this post


Link to post
Share on other sites
On 3/19/2020 at 6:54 AM, ecartz said:

<script>$(document).ready(function() { $('button[name="wishlist"]').bind('click', function() {
    let input = document.createElement('input');

    input.setAttribute('type', 'hidden');
    input.setAttribute('name', 'wishlist');
    input.setAttribute('value', 'wishlist');

    let form = $(this).closest('form');
    form.unbind('submit');
    form.append(input);
    form.submit();

    return false;
  });});
</script>

 

Yes this works! Thanks Matt @ecartz

Share this post


Link to post
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
Sign in to follow this  

×