How to display all wishlist items in wishlist sidebar
What is the code to display all wishlist items in the sidebar? Currently only last added three items are showing up. I wanted to display all items in current wishlist selection.
What should I change in this file:
vendor/magento/module-wishlist/view/frontend/templates/sidebar.phtml
magento2 wishlist
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
What is the code to display all wishlist items in the sidebar? Currently only last added three items are showing up. I wanted to display all items in current wishlist selection.
What should I change in this file:
vendor/magento/module-wishlist/view/frontend/templates/sidebar.phtml
magento2 wishlist
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56
add a comment |
What is the code to display all wishlist items in the sidebar? Currently only last added three items are showing up. I wanted to display all items in current wishlist selection.
What should I change in this file:
vendor/magento/module-wishlist/view/frontend/templates/sidebar.phtml
magento2 wishlist
What is the code to display all wishlist items in the sidebar? Currently only last added three items are showing up. I wanted to display all items in current wishlist selection.
What should I change in this file:
vendor/magento/module-wishlist/view/frontend/templates/sidebar.phtml
magento2 wishlist
magento2 wishlist
edited Sep 17 '17 at 1:14
St3phan
1,9231136
1,9231136
asked Sep 16 '17 at 17:40
learnerlearner
121316
121316
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56
add a comment |
1
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56
1
1
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56
add a comment |
1 Answer
1
active
oldest
votes
You can do it by plugin or overwrite of MagentoWishlistCustomerDataWishlist. I will cover pluginize getSectionData for achieving this.
VendorName/ModuleName/etc/frontend/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="MagentoWishlistCustomerDataWishlist">
<plugin name="customer_data_wishlist" type="VendorNameModuleNamePluginWishlistCustomerDataWishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
namespace VendorNameModuleNamePluginWishlistCustomerData;
class Wishlist
{
/**
* @var MagentoWishlistHelperData
*/
protected $wishlistHelper;
/**
* @var MagentoCatalogHelperImageFactory
*/
protected $imageHelperFactory;
/**
* @var MagentoFrameworkAppViewInterface
*/
protected $view;
/**
* @var MagentoWishlistBlockCustomerSidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param MagentoWishlistHelperData $wishlistHelper
* @param MagentoWishlistBlockCustomerSidebar $block
* @param MagentoCatalogHelperImageFactory $imageHelperFactory
* @param MagentoFrameworkAppViewInterface $view
*/
public function __construct(
MagentoWishlistHelperData $wishlistHelper,
MagentoWishlistBlockCustomerSidebar $block,
MagentoCatalogHelperImageFactory $imageHelperFactory,
MagentoFrameworkAppViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
MagentoWishlistCustomerDataWishlist $subject,
Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : ,
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return MagentoFrameworkPhrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = ;
foreach ($collection as $wishlistItem) {
$items = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param MagentoWishlistModelItem $wishlistItem
* @return array
*/
protected function getItemData(MagentoWishlistModelItem $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
MagentoFrameworkPricingRender::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),
];
}
/**
* Retrieve product image data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoCatalogBlockProductImage
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f193491%2fhow-to-display-all-wishlist-items-in-wishlist-sidebar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it by plugin or overwrite of MagentoWishlistCustomerDataWishlist. I will cover pluginize getSectionData for achieving this.
VendorName/ModuleName/etc/frontend/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="MagentoWishlistCustomerDataWishlist">
<plugin name="customer_data_wishlist" type="VendorNameModuleNamePluginWishlistCustomerDataWishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
namespace VendorNameModuleNamePluginWishlistCustomerData;
class Wishlist
{
/**
* @var MagentoWishlistHelperData
*/
protected $wishlistHelper;
/**
* @var MagentoCatalogHelperImageFactory
*/
protected $imageHelperFactory;
/**
* @var MagentoFrameworkAppViewInterface
*/
protected $view;
/**
* @var MagentoWishlistBlockCustomerSidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param MagentoWishlistHelperData $wishlistHelper
* @param MagentoWishlistBlockCustomerSidebar $block
* @param MagentoCatalogHelperImageFactory $imageHelperFactory
* @param MagentoFrameworkAppViewInterface $view
*/
public function __construct(
MagentoWishlistHelperData $wishlistHelper,
MagentoWishlistBlockCustomerSidebar $block,
MagentoCatalogHelperImageFactory $imageHelperFactory,
MagentoFrameworkAppViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
MagentoWishlistCustomerDataWishlist $subject,
Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : ,
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return MagentoFrameworkPhrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = ;
foreach ($collection as $wishlistItem) {
$items = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param MagentoWishlistModelItem $wishlistItem
* @return array
*/
protected function getItemData(MagentoWishlistModelItem $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
MagentoFrameworkPricingRender::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),
];
}
/**
* Retrieve product image data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoCatalogBlockProductImage
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
add a comment |
You can do it by plugin or overwrite of MagentoWishlistCustomerDataWishlist. I will cover pluginize getSectionData for achieving this.
VendorName/ModuleName/etc/frontend/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="MagentoWishlistCustomerDataWishlist">
<plugin name="customer_data_wishlist" type="VendorNameModuleNamePluginWishlistCustomerDataWishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
namespace VendorNameModuleNamePluginWishlistCustomerData;
class Wishlist
{
/**
* @var MagentoWishlistHelperData
*/
protected $wishlistHelper;
/**
* @var MagentoCatalogHelperImageFactory
*/
protected $imageHelperFactory;
/**
* @var MagentoFrameworkAppViewInterface
*/
protected $view;
/**
* @var MagentoWishlistBlockCustomerSidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param MagentoWishlistHelperData $wishlistHelper
* @param MagentoWishlistBlockCustomerSidebar $block
* @param MagentoCatalogHelperImageFactory $imageHelperFactory
* @param MagentoFrameworkAppViewInterface $view
*/
public function __construct(
MagentoWishlistHelperData $wishlistHelper,
MagentoWishlistBlockCustomerSidebar $block,
MagentoCatalogHelperImageFactory $imageHelperFactory,
MagentoFrameworkAppViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
MagentoWishlistCustomerDataWishlist $subject,
Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : ,
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return MagentoFrameworkPhrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = ;
foreach ($collection as $wishlistItem) {
$items = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param MagentoWishlistModelItem $wishlistItem
* @return array
*/
protected function getItemData(MagentoWishlistModelItem $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
MagentoFrameworkPricingRender::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),
];
}
/**
* Retrieve product image data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoCatalogBlockProductImage
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
add a comment |
You can do it by plugin or overwrite of MagentoWishlistCustomerDataWishlist. I will cover pluginize getSectionData for achieving this.
VendorName/ModuleName/etc/frontend/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="MagentoWishlistCustomerDataWishlist">
<plugin name="customer_data_wishlist" type="VendorNameModuleNamePluginWishlistCustomerDataWishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
namespace VendorNameModuleNamePluginWishlistCustomerData;
class Wishlist
{
/**
* @var MagentoWishlistHelperData
*/
protected $wishlistHelper;
/**
* @var MagentoCatalogHelperImageFactory
*/
protected $imageHelperFactory;
/**
* @var MagentoFrameworkAppViewInterface
*/
protected $view;
/**
* @var MagentoWishlistBlockCustomerSidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param MagentoWishlistHelperData $wishlistHelper
* @param MagentoWishlistBlockCustomerSidebar $block
* @param MagentoCatalogHelperImageFactory $imageHelperFactory
* @param MagentoFrameworkAppViewInterface $view
*/
public function __construct(
MagentoWishlistHelperData $wishlistHelper,
MagentoWishlistBlockCustomerSidebar $block,
MagentoCatalogHelperImageFactory $imageHelperFactory,
MagentoFrameworkAppViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
MagentoWishlistCustomerDataWishlist $subject,
Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : ,
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return MagentoFrameworkPhrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = ;
foreach ($collection as $wishlistItem) {
$items = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param MagentoWishlistModelItem $wishlistItem
* @return array
*/
protected function getItemData(MagentoWishlistModelItem $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
MagentoFrameworkPricingRender::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),
];
}
/**
* Retrieve product image data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoCatalogBlockProductImage
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
You can do it by plugin or overwrite of MagentoWishlistCustomerDataWishlist. I will cover pluginize getSectionData for achieving this.
VendorName/ModuleName/etc/frontend/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="MagentoWishlistCustomerDataWishlist">
<plugin name="customer_data_wishlist" type="VendorNameModuleNamePluginWishlistCustomerDataWishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
namespace VendorNameModuleNamePluginWishlistCustomerData;
class Wishlist
{
/**
* @var MagentoWishlistHelperData
*/
protected $wishlistHelper;
/**
* @var MagentoCatalogHelperImageFactory
*/
protected $imageHelperFactory;
/**
* @var MagentoFrameworkAppViewInterface
*/
protected $view;
/**
* @var MagentoWishlistBlockCustomerSidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param MagentoWishlistHelperData $wishlistHelper
* @param MagentoWishlistBlockCustomerSidebar $block
* @param MagentoCatalogHelperImageFactory $imageHelperFactory
* @param MagentoFrameworkAppViewInterface $view
*/
public function __construct(
MagentoWishlistHelperData $wishlistHelper,
MagentoWishlistBlockCustomerSidebar $block,
MagentoCatalogHelperImageFactory $imageHelperFactory,
MagentoFrameworkAppViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
MagentoWishlistCustomerDataWishlist $subject,
Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : ,
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return MagentoFrameworkPhrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = ;
foreach ($collection as $wishlistItem) {
$items = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param MagentoWishlistModelItem $wishlistItem
* @return array
*/
protected function getItemData(MagentoWishlistModelItem $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
MagentoFrameworkPricingRender::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),
];
}
/**
* Retrieve product image data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoCatalogBlockProductImage
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
answered Sep 17 '17 at 1:35
Sohel RanaSohel Rana
19.8k33853
19.8k33853
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
add a comment |
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
The sidebar is not visible.😕
– learner
Sep 17 '17 at 9:28
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Did you created 'VendorNameModuleName' module and added my answer into your module?
– Sohel Rana
Sep 17 '17 at 10:14
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
Also clear browser cache, magento cache, add/remove wishilst item.
– Sohel Rana
Sep 17 '17 at 10:15
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f193491%2fhow-to-display-all-wishlist-items-in-wishlist-sidebar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
did you get the solution ?
– Manoj Deswal
Sep 29 '17 at 12:56