0

I have a magento 2 website where I want to share wishlist between websites (for logged in users and guest users). For ex. guest user added product1 to the wishlist from website1 and now user switches to website2 then user would be able to see the same product to wishlist already.

but now every website has own wishlist

magento is only providing sharing between stores not websites. I've tried some solutions but no luck, i used this solution for sharing cart between websites Magento 2 + How to share cart for guest users between multi websites and working great. i tried to use it with wishlist but didn't work

i extened the wishlist model and changed getSharedStoreIds function

    /**
     * @return int[]
     */
    public function getSharedStoreIds()
    {
        if ($this->_storeIds === null || !is_array($this->_storeIds)) {
                $_storeIds = [];
                $stores = $this->_storeManager->getStores();
                foreach ($stores as $store) {
                    $_storeIds[] = $store->getId();
                }
                $this->_storeIds = $_storeIds;
        }
        return $this->_storeIds;
    }

but still not working

1 Answer 1

0

I solved it :)

There is attribute $_useCurrentWebsite; in Wishlist Model its default value is true

i tried to change it in core model and it's working with me

the optimal solution by change it's value by overriding it

i changed the /etc/frontend/di.xml in my module by adding this code

    <type name="Magento\Wishlist\Model\Wishlist">
        <arguments>
            <argument name="useCurrentWebsite" xsi:type="boolean">false</argument>
        </arguments>
    </type>

inside config tag

so no need to override the class

and this did the trick

Thank you

1
  • Hi there, please consider marking your answer as solution, so others can see this too. Cheers!
    – Diana
    Commented Feb 22, 2021 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.