I am in requirement to add mini wish-list icon like mini cart count on top of header .I do not know this is Magento default functionality or Not.
Asked
Active
Viewed 3,573 times
6
-
Do you need to display the count on top of wishlist? – Haritha Jun 17 '18 at 11:53
-
Haritha@yes before my cart button on top – new developer Jun 17 '18 at 12:01
-
Haritha@you there? – new developer Jun 17 '18 at 12:04
-
By default for wishlist and the cart, the count is available... check these files to add counter to your custom icons vendor/magento/module-wishlist/view/frontend/templates/link.phtml vendor/magento/module-checkout/view/frontend/templates/cart/minicart.phtml – Haritha Jun 17 '18 at 12:12
-
Haritha@let me know what I have to do there – new developer Jun 17 '18 at 12:16
-
can you share the code which shows the wishlist icon – Haritha Jun 17 '18 at 12:17
-
Let us continue this discussion in chat. – Haritha Jun 17 '18 at 12:18
-
Haritha@I have no code there for wish-list icon I have to create functionality like image – new developer Jun 17 '18 at 12:18
1 Answers
8
You can either create a module or customize the code in the theme, I have used custom module as follows,
app/code/VendorName/ModuleName/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'VendorName_ModuleName',
__DIR__
);
app/code/VendorName/ModuleName/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="VendorName_ModuleName" setup_version="1.0.0">
</module>
</config>
app/code/VendorName/ModuleName/view/frontend/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header-wrapper">
<block class="Magento\Wishlist\Block\Link" name="wish-list-link-custom" after="minicart" template="VendorName_ModuleName::link.phtml" />
</referenceContainer>
</body>
</page>
app/code/VendorName/ModuleName/view/frontend/templates/link.phtml
Note: The below css styles can be added in a new less file
<?php
/* you can customize the wishlist here */
?>
<style>
.custom.link.wishlist{
float: right;
}
.custom.link.wishlist .counter.qty {
background: #ff5501;
color: #fff;
height: 24px;
line-height: 24px;
border-radius: 2px;
display: inline-block;
margin: 3px 0 0;
min-width: 18px;
overflow: hidden;
padding: 0 3px;
text-align: center;
white-space: normal;
}
.wishlist-custom:before {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: 22px;
line-height: 28px;
color: #757575;
content: '\e600';
font-family: 'luma-icons';
margin: 0;
vertical-align: top;
display: inline-block;
font-weight: normal;
overflow: hidden;
speak: none;
text-align: center;
}
.wishlist-custom .text{
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
</style>
<div class="custom link wishlist" data-bind="scope: 'wishlist'">
<a <?= /* @noEscape */ $block->getLinkAttributes() ?> class="wishlist-custom">
<span class="text"><?= $block->escapeHtml($block->getLabel()) ?></span>
<!-- ko if: wishlist().counter -->
<span data-bind="text: wishlist().counter" class="counter qty"></span>
<!-- /ko -->
</a>
</div>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"wishlist": {
"component": "Magento_Wishlist/js/view/wishlist"
}
}
}
}
}
</script>
run commands
bin/magento setup:upgrade
bin/magento setup:static-content:deploy
give permission to the magento 2 files as per Magento 2 folder/file permissions
after creating this we can able to see the customization as shown in the below screen shot
Haritha
- 666
- 5
- 14

