kgtee Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
burt Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
kgtee Posted March 18, 2020 Share Posted March 18, 2020 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. 😄 Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted March 18, 2020 Share Posted March 18, 2020 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? Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 18, 2020 Share Posted March 18, 2020 <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. Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
LeeFoster Posted March 18, 2020 Share Posted March 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
discxpress Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
discxpress Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 19, 2020 Share Posted March 19, 2020 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? Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
LeeFoster Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 19, 2020 Share Posted March 19, 2020 I mean your store where you have it installed. I have files for both Apps but I don't have them installed. Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
LeeFoster Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted March 19, 2020 Share Posted March 19, 2020 <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> Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
LeeFoster Posted March 19, 2020 Share Posted March 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
discxpress Posted March 21, 2020 Share Posted March 21, 2020 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 Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted June 9, 2020 Share Posted June 9, 2020 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 } } Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted June 9, 2020 Share Posted June 9, 2020 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. Quote Link to comment Share on other sites More sharing options...
LeeFoster Posted June 12, 2020 Share Posted June 12, 2020 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? Quote Link to comment Share on other sites More sharing options...
♥ecartz Posted June 12, 2020 Share Posted June 12, 2020 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. Quote Always back up before making changes. Link to comment Share on other sites More sharing options...
LeeFoster Posted June 12, 2020 Share Posted June 12, 2020 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.