adding Options like size and color in wishlist sidebar magento2

magento 2 wishlist extension free
magento 2 add to wishlist
magento 2 wishlist link
magento 2 guest wishlist extension
magento 2 login popup extension free
ajax suite magento 2
magento 2 countdown timer github
tigren ajax cart

I am using magento 2.1.2.I am having issue to get the wishlist product attributes like color,size in wishlist sidebar.

Here is the code which get the price name etc but unable to get the attributes like size and color

protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem) {
        $product = $wishlistItem->getProduct();        
        return [
            'image' => $this->getImageData($product),
            'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
            'product_name' => $product->getName(),
            'product_color' => 'Blue',
            'product_size' => 'L',
            'product_price' => $this->block->getProductPriceHtml(
                $product,
                'wishlist_configured_price',
                \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                ['item' => $wishlistItem]
            ),
            'product_is_saleable_and_visible' => $product->isSaleable() && $product->isVisibleInSiteVisibility(),
            'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product),
            'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem, true),
            'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem, true),
        ];
    }

THanks

It is not a good idea to hack the core for that. You need to create a plugin that modifies the result of this method. But since this method is protected you will not be able to just hook into that. You can hook into getSectionData which is public.

Another gotcha is that the wishlist items are stored in local storage by the browser. So when testing, after you cleared the Magento cache, you will also have to clear the local storage of your site in the browser and log in again and then add another item to your wishlist.

When you created a module you can then add these files:

app/code/Vendor/Module/Plugin/Magento/Wishlist/CustomerData/Wishlist.php

<?php

namespace Vendor\Module\Plugin\Magento\Wishlist\CustomerData;

class Wishlist
{

    /**
     * @var \Magento\Wishlist\Helper\Data
     */
    protected $wishlistHelper;


    /**
     * @var \Magento\Catalog\Model\ProductRepository
     */
    protected $_productRepository;

    public function __construct(
        \Magento\Wishlist\Helper\Data $wishlistHelper,
        \Magento\Catalog\Model\ProductRepository $productRepository
    ) {
        $this->wishlistHelper = $wishlistHelper;
        $this->productRepository = $productRepository;
    }

    public function afterGetSectionData(
        \Magento\Wishlist\CustomerData\Wishlist $subject,
        $result
    ) {
        $collection = $this->wishlistHelper->getWishlistItemCollection();
        $collection->clear()->setPageSize(count($result['items']))->setInStockFilter(true)->setOrder('added_at');

        foreach($result['items'] as &$item) {
            foreach ($collection as $wishlistItem) {
                $product = $wishlistItem->getProduct();
                if ($item['product_url'] == $product->getProductUrl()) {
                    $item['product_color'] = $product->getAttributeText('color');
                }
            }
        }

        return $result;
    }
}

app/code/Vendor/Module/etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Wishlist\CustomerData\Wishlist">
        <plugin disabled="false" name="Vendor_Module_Plugin_Magento_Wishlist_CustomerData_Wishlist" sortOrder="10" type="Vendor\Module\Plugin\Magento\Wishlist\CustomerData\Wishlist"/>
    </type>
</config>

Then in a file that overwrites app/code/Magento/Wishlist/view/frontend/templates/sidebar.phtml

You can do something like

<span data-bind="visible: product_color, text: product_color"></span>

inside the

<li class="product-item">

Wishlist Sidebar get the product attribute like si, am using magento 2.1.2.I am having issue to get the wishlist product attributes like color,size in wishlist sidebar. Function which is used to get. Wishlist Sidebar get the product attribute like size and color am using magento 2.1.2.I am having issue to get the wishlist product attributes like color,size in wishlist sidebar. Function which is used to get the price,name is

Another way of showing product attribute in wishlist sidebar,

First Need to Remove all the wishlist items ,clear cache and add a new product to wishlist.

app/code/Vendor/Module/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xsi:noNamespaceSchemaLocation = "urn:magento:framework:Module/etc/module.xsd">
    <module name="Yourtheme_YourModule" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Wishlist" />
       </sequence>
     </module>
</config>

app/code/Vendor/Module/etc/di.xml

 <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Wishlist\CustomerData\Wishlist" type="Yourtheme\yourmodule\CustomerData\Wishlist" />
</config>

app/code/Vendor/Module/CustomerData/Wishlist.php

namespace YourTheme\YourModule\CustomerData;

/**
* Wishlist section
*/
class Wishlist extends \Magento\Wishlist\CustomerData\Wishlist
{

/**
 * Get wishlist items
 *
 * @return array
 */
protected function getWishlistItems()
{
    $this->view->loadLayout();

    $collection = $this->wishlistHelper->getWishlistItemCollection();
    $collection->clear()->setPageSize(self::SIDEBAR_ITEMS_NUMBER)
        ->setInStockFilter(true)->setOrder('added_at');

    $items = [];
    foreach ($collection as $wishlistItem) {
        $items[] = $this->getProductItemData($wishlistItem);
    }
    return $items;
}

  /**
 * Retrieve wishlist item data
 *
 * @param \Magento\Wishlist\Model\Item $wishlistItem
 * @return array
 */
protected function getProductItemData(\Magento\Wishlist\Model\Item $wishlistItem)
{
    $product = $wishlistItem->getProduct();

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $model = $objectManager->create('\Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface');

    $custpomProductAttribute = $product->getYourAttribute();

    return [
        'image' => $this->getImageData($model->getFinalProduct($wishlistItem)),
        'product_sku' => $product->getSku(),
        'product_id' => $product->getId(),
        'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
        'product_name' => $product->getName(),
        'product_price' => $this->block->getProductPriceHtml(
            $product,
            'wishlist_configured_price',
            \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
            ['item' => $wishlistItem]
        ),
        'product_is_saleable_and_visible' => $product->isSaleable() &&    
      $product->isVisibleInSiteVisibility(),
        'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product),
        'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem),
        'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem),
        'your_attribute' => $custpomProductAttribute,
    ];
}

magento2: adding Options like size and color in wishlist sidebar , I am using magento 2.1.2.I am having issue to get the wishlist product attributes like color,size in wishlist sidebar.Here is the code which get the  Wishlists. A wishlist is a list of products that registered customers can share with friends or transfer to their shopping carts at a later date. When wishlists are enabled, the Add to Wishlist link appears on the category and product pages of your store. Depending on the theme, it might be a text link or a graphic image.

Thanks to @Victor S. Tried first method, to override the class via preferences, but no lucky, after an hour trying to compile and recompile dependency injection, found your answer and created a module with the plugin, magically works. Magento 2.2.7.

Thanks

How to add specific configurable product options to the wishlist , For some reason, whenever a product is added to my wish list it only adds the product. It does not add the selected configurable options (size/color). I know that it  When you add a configurable product to the cart, you never really buy the configurable product but the products associated to its options. Try to selecting a color/size before you add them to your wishlist. You can also try adding a simple product to see if the price shows in the wishlist.

Magento 2: Working with Wishlist, magento 2 wishlist - how to change number of items in wishlist sidebar, how to "​Add to Another purpose is to keep products you want to buy at a later date. By default you can see 3 last added wishlist items in sidebar. There is no corresponding option in admin panel. for (i = 0; i < items.length; i++) {. Magento 2 Wishlist extension brings an excellent solution to help customers create multiple wishlists to save any their preferred items organizedly. Various wishlist categories assist shoppers manage and access their wishlists much more quickly and easily.

Magento 2 Wishlist extension, Magento 2 Wishlist extension brings an excellent solution to help customers create Popup + AJAX Add to Wishlist; Create multiple wishlists; Editable wishlists can create more wishlists based on specific similarities: purposes, gender, color, a number of wishlists as they want to contain their expected items with ease. What is the Magento Layered Navigation? Attribute Multi Select Ajax Filter is a tool for narrowing down the displayed product list within a category by specifying one or more product attributes (e.g., narrowing the 750 products in the “Clothing” category by size, color, material, cut, etc).

Products in wishlist show $0.00 price · Issue #6866 · magento , Try to selecting a color/size before you add them to your wishlist. function getValue() { $result = 0.; /** @var \Magento\Wishlist\Model\Item\Option $​customOption This solves both issues ('My account' page and the sidebar). I'm editing app\design\frontend\Vendor\theme\Magento_Checkout\templates\cart\item\default.phtml. This is what I'm trying to achieve: For configurable product, it shows color and size by default, but they doesn't show up for simple product.

Comments
  • And you can get that attribute using ko in sidebar.phtm in wishlist modulel