Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annoying bug: Add to Wishlist is not working properly #1414

Open
ADDISON74 opened this issue Jan 22, 2021 · 2 comments
Open

Annoying bug: Add to Wishlist is not working properly #1414

ADDISON74 opened this issue Jan 22, 2021 · 2 comments

Comments

@ADDISON74
Copy link
Contributor

OpenMage v20.0.6

To reproduce this annoying issue you should have created before: a category, a product associated to the category, a customer account.

Do not login into the account!

In frontend visit as guest the created category and press [Add to Wishlist]. You will be redirected as usual to path /customer/account/login/. Fill up the email and password and press [Login].

Instead of getting into the customer account and see the confirmation that the product was added to wishlist you will get the category page with the following error message: "Please add product to wishlist again". See the image bellow:

screensho3

Please note you are logged in already. By pressing again [Add to Wishlist] the product will be added to wishlist and you are now visiting the customer page which is the correct behavior. See the image bellow:

screensho4

I did not check this issue with other versions of Magento but I suppose it is coming from the changes the team made when added form keys for Add Wishlist. I will make time to install a fresh Magento 1.9.4.3 which has no form keys form Add to Cart, Add to Wishlist and Add to Compare and see if I confirm it again.

As it is now this issue creates confusion and becomes really annoying for a visitor.

@ADDISON74 ADDISON74 added the bug label Jan 22, 2021
@ADDISON74
Copy link
Contributor Author

I checked the part of the code which is responsible for the error: /app/code/core/Mage/Wishlist/controllers/IndexController.php

public function indexAction()
    {
        if (!$this->_getWishlist()) {
            return $this->norouteAction();
        }
        $this->loadLayout();

        if ($this->_isFormKeyEnabled() && strpos($this->_getRefererUrl(), 'login')) {
            Mage::getSingleton('core/session')->addError(Mage::helper('wishlist')->__(
                'Please add product to wishlist again.'
            ));
            return $this->_redirectUrl(Mage::getSingleton('customer/session')->getBeforeWishlistUrl());
        }

Look at that if statement. Running the code these two variables have the following values:

$this->_isFormKeyEnabled() = bool(true)
strpos($this->_getRefererUrl(), 'login') = int(40)

Based on these values the evaluation is always true. Magento is doing the job just of part of it creating a new logged session but instead of accessing the customer account and adding the product to the wishlist it is coming back to the page from where the request came.

I will do more tests by changing in one template AddToWishListUrlCustom to AddToWishListUrl for backward compatibility. If it is not working again I will replace the core file with one from a previous version to see what is happening.

@ADDISON74
Copy link
Contributor Author

ADDISON74 commented Jan 22, 2021

In Magento Team did a change in the Index controller in 1.9.4.3. Making a diff between OpenMage 20.0.6 and Magento 1.9.4.2 the if statement from above was introduced. By commenting the lines 144 - 149 in /app/code/core/Mage/Wishlist/controllers/IndexController.php I was able to use this feature as usual without any error. All templates remained the same as before with the modifications introduced in 1.9.4.3. Here is an example from a template:

[...]
<?php $_params = $this->escapeHtml(json_encode(array('form_key' => $this->getFormKey()))); ?>
[...]
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php $_wishlistUrl = $this->getAddToWishlistUrlCustom($_product, false); ?>
<li>
<a href="#"
    data-url="<?php echo $_wishlistUrl ?>"
    data-params="<?php echo $_params ?>"
    class="link-wishlist"
    onclick="customFormSubmit('<?php echo $_wishlistUrl ?>', '<?php echo $_params ?>', 'post')">
    <?php echo $this->__('Add to Wishlist') ?>
</a>
</li>

Let's evaluate a little the code from the controller. There is no doubt $this->_isFormKeyEnabled() value is always true. If I navigate as I guest by pressing [Add to Wishlist] button I will be redirected to login page (/customer/account/login/) . The URL contains "login" string and strpos function will return a positive value. In this way the if evaluation will always be true. The guest will login but will have to add again the product which is annoying and a bug into the code.

I did a modification by changing login string to login1. I was able to login into my account and see the item added to the wishlist. No errors and this is the same like commenting the if statement. If anyone has some time please evaluate what is the impact of commenting the code. At least with this modification we will solve the issue.

To solve this issue I see the following scenarios:

  1. Commenting/Removing the if statement and returning to Magento 1.9.4.2.
  2. Modify login word in the path (same result as 1 but a dead piece of code).
  3. Change the error message from "Please add product to wishlist again." to "You could not add products to wishlish as guest. You are logged in please add the product again."

Any insides are welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant