Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top