Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Wishlist For Phoenix


tmcca

Recommended Posts

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.

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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. 😄

Link to comment
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?

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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. 

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • 2 months later...

I managed to hook in the application_bottom.php changes thanks to @burt adding some more hooks, however, it doesn't fully work. The page redirects to the wishlist as it should but nothing is added not. The code is below

class hook_shop_system_wishlistApp {
  var $preActionApp = null;  

   public function listen_preActionApp() {
	  
	  // 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
  }
  
}

 

Link to comment
Share on other sites

36 minutes ago, LeeFoster said:

I managed to hook in the application_bottom.php changes thanks to @burt adding some more hooks, however, it doesn't fully work. The page redirects to the wishlist as it should but nothing is added not. The code is below


class hook_shop_system_wishlistApp {
  var $preActionApp = null;  

   public function listen_preActionApp() {
	  
	  // 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
  }
  
}

 

It's writing the data to the database as it should but it's not showing on the wishlist page.

Link to comment
Share on other sites

Still struggling to get this fully hooked. The final piece is just out of reach, the application_top.php change still isn't working. I have created the hook file however it doesn't seem to be passing the session data even though it is passing data to the database. Do any of the core dev's have 5 mins to help @ecartz @burt?

Link to comment
Share on other sites

class hook_shop_system_wishlistApp {

  public function listen_preActionApp() {
// wishlist data
    if (!isset($_SESSION['wishList']) || !($_SESSION['wishList'] instanceof wishlist)) {
      $_SESSION['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'])) {
        $qty = $_SESSION['wishList']->get_quantity(tep_get_uprid($_POST['products_id'], $attributes)) + (int)($_POST['qty'] ?? 1);

        $_SESSION['wishList']->add_wishlist($_POST['products_id'], $qty, ($_POST['id'] ?? ''));
      }

      if (WISHLIST_REDIRECT ==  'No') tep_redirect(tep_href_link('product_info.php', 'products_id=' . $_POST['products_id']));
      tep_redirect(tep_href_link('wishlist.php'));
    }
  }
  
}

Alternately, adding global $wishlist at the beginning of the function might work. 

Always back up before making changes.

Link to comment
Share on other sites

28 minutes ago, ecartz said:

class hook_shop_system_wishlistApp {

  public function listen_preActionApp() {
// wishlist data
    if (!isset($_SESSION['wishList']) || !($_SESSION['wishList'] instanceof wishlist)) {
      $_SESSION['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'])) {
        $qty = $_SESSION['wishList']->get_quantity(tep_get_uprid($_POST['products_id'], $attributes)) + (int)($_POST['qty'] ?? 1);

        $_SESSION['wishList']->add_wishlist($_POST['products_id'], $qty, ($_POST['id'] ?? ''));
      }

      if (WISHLIST_REDIRECT ==  'No') tep_redirect(tep_href_link('product_info.php', 'products_id=' . $_POST['products_id']));
      tep_redirect(tep_href_link('wishlist.php'));
    }
  }
  
}

Alternately, adding global $wishlist at the beginning of the function might work. 

Yeah that did it, thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...