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

Widget cache error #4389

Closed
twslade opened this issue May 3, 2016 · 19 comments
Closed

Widget cache error #4389

twslade opened this issue May 3, 2016 · 19 comments
Assignees
Labels
bug report Component: Cms Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@twslade
Copy link

twslade commented May 3, 2016

Steps to reproduce

  1. Install Magento from develop branch.
  2. Add two widgets of type 'Catalog Product List' to the 'CMS homepage' at location content.bottom with different titles, but the same conditions. For example, condition could be product price is greater than 0
  3. Refresh cache and visit homepage

Expected result

  1. Two widgets appear on homepage with the same products, but different titles.

Actual result

  1. First widget loaded shows twice depending on sort order
  2. See: Magento\CatalogWidget\Block\Product\ProductList::getCacheKeyInfo which doesn't take into consideration the widget_id.
    /**
     * Get key pieces for caching block content
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        $conditions = $this->getData('conditions')
            ? $this->getData('conditions')
            : $this->getData('conditions_encoded');

        return [
            'CATALOG_PRODUCTS_LIST_WIDGET',
            $this->_storeManager->getStore()->getId(),
            $this->_design->getDesignTheme()->getId(),
            $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
            intval($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1)),
            $this->getProductsPerPage(),
            $conditions
        ];
    }
@oserediuk
Copy link
Contributor

oserediuk commented Jun 7, 2016

Hello @twslade! Thank you for the report! We have created issue in our bugtracker system MAGETWO-54008 . It will be fixed as soon as possible.

@mcspronko
Copy link
Contributor

Hi @oserediuk

Do you have any update for timeframe of the MAGETWO-54008 issue?

Thanks

@oserediuk
Copy link
Contributor

Hi @mcspronko ! Nope

@mcspronko
Copy link
Contributor

Hi @pboisvert

Are there any deadlines for this issue?

Thanks,
Max

@vkorotun vkorotun removed the MX label Aug 4, 2016
@andimov andimov added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report labels Aug 16, 2016
@loekderooij
Copy link

loekderooij commented Aug 29, 2016

This is not caused by the cache key. The rule property is a shared object. This can be solved by defining the rule argument in the constructor as not shared in di.xml.

<type name="Magento\CatalogWidget\Block\Product\ProductsList">
    <arguments>
        <argument name="rule" xsi:type="object" shared="false">Magento\CatalogWidget\Model\Rule</argument>
    </arguments>
</type>

@pinicio
Copy link

pinicio commented Nov 9, 2016

@LuckyLoek solution doesn't seem to work for me. If someone found a solution to this bug and share it, it would be greatly appreciated.

@twslade
Copy link
Author

twslade commented Nov 9, 2016

@pinicio I think @LuckyLoek misunderstood the problem. The issue is that the widget_id isn't stored within the cache key.

I fixed it by adding the widget ID to the \Magento\CatalogWidget\Block\Product\ProductsList::getCacheKeyInfo function in the return. See below. I only came across this scenario because I was making lots of widgets that were the same conditions for mocking client data during a project.

    public function getCacheKeyInfo()
    {
        $conditions = $this->getData('conditions')
            ? $this->getData('conditions')
            : $this->getData('conditions_encoded');

        return [
            'CATALOG_PRODUCTS_LIST_WIDGET',
            $this->_storeManager->getStore()->getId(),
            $this->_design->getDesignTheme()->getId(),
            $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
            intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
            $this->getProductsPerPage(),
            $conditions . $this->getData('id'),
            serialize($this->getRequest()->getParams())
        ];
    }

@loekderooij
Copy link

loekderooij commented Nov 9, 2016

@twslade, I didn't misunderstand the problem as I had exactly the same problem. The situations might still be different however.

I had unique conditions and therefor a unique cache key for each widget. Still this didn't produce the result I expected. I can't test right now but I guess it depends on the widget settings. I think both solutions should be considered depending on the situation.

@twslade
Copy link
Author

twslade commented Nov 9, 2016

@LuckyLoek The reason I thought you misunderstood the problem is because I had no context into how you came across the bug/solution you provided. As described above, my conditions were the same in both widgets, so the same products were assigned to each widget. The titles were different even though the frontend showed the same block each time, because they had identical cache keys.

I noticed that you said above that the issue doesn't have to do with cache key, but instead the shared rules. Can you give details on steps to reproduce and expected/actual results?

@loekderooij
Copy link

@twslade, it was also too easy from my side to assume the problem as described was exactly the same as mine. I will provide details to reproduce as soon as I find some time on my hands.

@pinicio
Copy link

pinicio commented Nov 9, 2016

@LuckyLoek @twslade great, thank you both. I wasn't setting any conditions, so I was able to make it work just by passing the widget id.

public function getCacheKeyInfo()
{
    return [
        'CATALOG_PRODUCTS_LIST_WIDGET',
        $this->_storeManager->getStore()->getId(),
        $this->_design->getDesignTheme()->getId(),
        $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
        intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
        $this->getProductsPerPage(),
        'my_widget_id',
        serialize($this->getRequest()->getParams())
    ];
}

@henk-hypershop
Copy link

Any fixes for this yet? Has been over 6 months, but the issue still remains in 2.1.3.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Cms Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team
Copy link
Contributor

@twslade, thank you for your report.
We've created internal ticket(s) MAGETWO-54008 to track progress on the issue.

@magento-engcom-team magento-engcom-team added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 13, 2017
@AlexandrKozyr
Copy link
Contributor

#mageconf

@magento-engcom-team
Copy link
Contributor

@AlexandrKozyr thank you for joining. Please accept team invitation here and self-assign the issue.

@AlexandrKozyr AlexandrKozyr self-assigned this Dec 15, 2017
AlexandrKozyr added a commit to AlexandrKozyr/magento2 that referenced this issue Dec 15, 2017
-fixed CacheKey assignment
AlexandrKozyr added a commit to AlexandrKozyr/magento2 that referenced this issue Dec 15, 2017
- fixed CacheKey assignment
@magento-engcom-team
Copy link
Contributor

Hi @twslade. Thank you for your report.
The issue has been fixed in #12764 by @AlexandrKozyr in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Apr 19, 2018
ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this issue Apr 23, 2018
@magento-engcom-team
Copy link
Contributor

Hi @twslade. Thank you for your report.
The issue has been fixed in #14816 by @ihor-sviziev in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Apr 24, 2018
@abhaykhatariya
Copy link

abhaykhatariya commented Jul 3, 2018

It's still existing into magento 2.2.5 when we add cms static block using widget

magento-engcom-team pushed a commit that referenced this issue Jun 21, 2019
[Magento Community Engineering] Community Contributions - GraphQL
@Hoszi
Copy link

Hoszi commented Sep 30, 2019

It's still existing in magento 2.3.2. when I add the same widget twice in one cms page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Cms Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests