Magento2: How to display most view product collection in home page?Magento 2 colour swatches not showing on homepageDisplay best selling products in home pageHow to get product rating collection in magento 2Customise grid collection in magento2?collection for grid in magento2Home Page url in sitemapHow to filter product with salable filter in magento2How to remove block in view page in magento2How to get recently viewed product collection in magento2?How to add custom footer template for product view page in magento2Magento2: How to display out of stock product in wishlist
left ... right make different sizes in numerator and denominator
Was Donald Trump at ground zero helping out on 9-11?
Dynamic Icon loading in LWC doesn't work
Why put copper in between battery contacts and clamps?
Circle symbol compatible with square and triangle
If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?
Do the books ever say oliphaunts aren’t elephants?
How do I make my photos have more impact?
Bouncing map back into its bounds, after user dragged it out
Did Vladimir Lenin have a cat?
Why are subdominants unstable?
Verb Classification of あげる (to give)
Does Ubuntu reduce battery life?
Asymptotic behaviour of a weird power series
Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?
Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here
Using Python in a Bash Script
Antonym of "Megalomania"
Should I intervene when a colleague in a different department makes students run laps as part of their grade?
Coworker mumbles to herself when working, how to ask her to stop?
Unknown indication below upper stave
Applications of pure mathematics in operations research
Microgravity indicators
What language is Raven using for her attack in the new 52?
Magento2: How to display most view product collection in home page?
Magento 2 colour swatches not showing on homepageDisplay best selling products in home pageHow to get product rating collection in magento 2Customise grid collection in magento2?collection for grid in magento2Home Page url in sitemapHow to filter product with salable filter in magento2How to remove block in view page in magento2How to get recently viewed product collection in magento2?How to add custom footer template for product view page in magento2Magento2: How to display out of stock product in wishlist
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to display product collection in home page in magento2.
Thanks.
magento2.2 php-7.2
add a comment |
I need to display product collection in home page in magento2.
Thanks.
magento2.2 php-7.2
add a comment |
I need to display product collection in home page in magento2.
Thanks.
magento2.2 php-7.2
I need to display product collection in home page in magento2.
Thanks.
magento2.2 php-7.2
magento2.2 php-7.2
asked Jul 21 at 11:47
Mano MMano M
1,1804 silver badges25 bronze badges
1,1804 silver badges25 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In Layout file:
<container name="home.lookbook" htmlTag="div" htmlClass="lookbook-block home-cards">
<block class="MagentoFrameworkViewElementTemplate" name="lookbook"
template="Magento_Theme::html/home/lookbook.phtml"/>
</container>
In Template file:
<?php
$collection = $this->getProductDetails();
$productCollection = $collection['collection'];
$categoryName = $collection['name'];
if (count($productCollection))
?>
<div class="shy-block mgb20 product-recently">
<div class="most-viewed">
<div class="lg-title">
<?php /* @escapeNotVerified */ echo $categoryName; ?>
</div>
<div class="product-carousel" data-mage-init='"viewPageSlickCarousel": '>
<?php
foreach ($productCollection as $product)
$productName = $product->getName();
$productUrl = $block->productRender($product);
$templateType = OXProductReviewBlockProductReviewRenderer::STAR_VIEW;
$image = 'upsell_products_list';
?>
<?php if ($product->isSaleable()): ?>
<div class="product-carousel-item text-center">
<div class="product-carousel-item-image">
<!--To display Product label -->
<?php
$productAttributeCode = $this->getAttributeCode($product);
if (!empty($productAttributeCode))
$attributeOptionlabel = $product->getAttributeText($productAttributeCode);
if (!empty($attributeOptionlabel))
$attributeOptionText = strtolower($attributeOptionlabel);
$optionLabel = str_replace(" ", "-", $attributeOptionText);
$mediaUrl = $block->getMediaUrl();
$productLabelUrl = $mediaUrl . 'attribute/options/' . $optionLabel . '.png';
?>
<div class="product-label shy-product-label">
<img src="<?php echo $productLabelUrl ?>" alt="<?php echo $optionLabel ?>">
</div>
<?php
?>
<!-- To display Product label End -->
<a href="<?= $productUrl ?> ">
<?= $block->getImage($product, $image)->toHtml(); ?>
</a>
<?= $block->getReviewsSummaryHtml($product, $templateType) ?>
</div>
<div class="product details product-carousel-item-details">
<div class="product-carousel-item-name">
<a class="" href="<?= $productUrl ?>">
<?= $productName ?>
</a>
</div>
<?= /* @escapeNotVerified */ $block->getProductPrice($product) ?>
<div class="product-carousel-item-inner">
<div class="product actions product-item-actions">
<div class="actions-primary">
<?php $controller = $block->getUrl('ajaxcart/index/productdata/') ?>
<form data-product-type="<?= /* @NoEscape */ $product->getTypeId() ?>" data-role="tocart-form" data-url="<?php echo $controller ?>" data-product-name="<?= /* @NoEscape */ $product->getName() ?>" data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>" action="<?= $block->getUrl("checkout/cart/add") ?>" method="post" >
<input type="hidden" value="<?= $product->getId() ?>" name="product">
<input type="hidden" value="<?= $block->getEncodeUrl() ?>" name="uenc">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<!--- Item end -->
</div>
<?php
endif;
?>
</div>
</div>
</div>
<script type="text/x-magento-init">
"[data-role=tocart-form], .form.map.checkout":
"productInfoPopup":
</script>
<div id="product-popup"> </div>
And also refer Magento 2 colour swatches not showing on homepage
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%2f282738%2fmagento2-how-to-display-most-view-product-collection-in-home-page%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
In Layout file:
<container name="home.lookbook" htmlTag="div" htmlClass="lookbook-block home-cards">
<block class="MagentoFrameworkViewElementTemplate" name="lookbook"
template="Magento_Theme::html/home/lookbook.phtml"/>
</container>
In Template file:
<?php
$collection = $this->getProductDetails();
$productCollection = $collection['collection'];
$categoryName = $collection['name'];
if (count($productCollection))
?>
<div class="shy-block mgb20 product-recently">
<div class="most-viewed">
<div class="lg-title">
<?php /* @escapeNotVerified */ echo $categoryName; ?>
</div>
<div class="product-carousel" data-mage-init='"viewPageSlickCarousel": '>
<?php
foreach ($productCollection as $product)
$productName = $product->getName();
$productUrl = $block->productRender($product);
$templateType = OXProductReviewBlockProductReviewRenderer::STAR_VIEW;
$image = 'upsell_products_list';
?>
<?php if ($product->isSaleable()): ?>
<div class="product-carousel-item text-center">
<div class="product-carousel-item-image">
<!--To display Product label -->
<?php
$productAttributeCode = $this->getAttributeCode($product);
if (!empty($productAttributeCode))
$attributeOptionlabel = $product->getAttributeText($productAttributeCode);
if (!empty($attributeOptionlabel))
$attributeOptionText = strtolower($attributeOptionlabel);
$optionLabel = str_replace(" ", "-", $attributeOptionText);
$mediaUrl = $block->getMediaUrl();
$productLabelUrl = $mediaUrl . 'attribute/options/' . $optionLabel . '.png';
?>
<div class="product-label shy-product-label">
<img src="<?php echo $productLabelUrl ?>" alt="<?php echo $optionLabel ?>">
</div>
<?php
?>
<!-- To display Product label End -->
<a href="<?= $productUrl ?> ">
<?= $block->getImage($product, $image)->toHtml(); ?>
</a>
<?= $block->getReviewsSummaryHtml($product, $templateType) ?>
</div>
<div class="product details product-carousel-item-details">
<div class="product-carousel-item-name">
<a class="" href="<?= $productUrl ?>">
<?= $productName ?>
</a>
</div>
<?= /* @escapeNotVerified */ $block->getProductPrice($product) ?>
<div class="product-carousel-item-inner">
<div class="product actions product-item-actions">
<div class="actions-primary">
<?php $controller = $block->getUrl('ajaxcart/index/productdata/') ?>
<form data-product-type="<?= /* @NoEscape */ $product->getTypeId() ?>" data-role="tocart-form" data-url="<?php echo $controller ?>" data-product-name="<?= /* @NoEscape */ $product->getName() ?>" data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>" action="<?= $block->getUrl("checkout/cart/add") ?>" method="post" >
<input type="hidden" value="<?= $product->getId() ?>" name="product">
<input type="hidden" value="<?= $block->getEncodeUrl() ?>" name="uenc">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<!--- Item end -->
</div>
<?php
endif;
?>
</div>
</div>
</div>
<script type="text/x-magento-init">
"[data-role=tocart-form], .form.map.checkout":
"productInfoPopup":
</script>
<div id="product-popup"> </div>
And also refer Magento 2 colour swatches not showing on homepage
add a comment |
In Layout file:
<container name="home.lookbook" htmlTag="div" htmlClass="lookbook-block home-cards">
<block class="MagentoFrameworkViewElementTemplate" name="lookbook"
template="Magento_Theme::html/home/lookbook.phtml"/>
</container>
In Template file:
<?php
$collection = $this->getProductDetails();
$productCollection = $collection['collection'];
$categoryName = $collection['name'];
if (count($productCollection))
?>
<div class="shy-block mgb20 product-recently">
<div class="most-viewed">
<div class="lg-title">
<?php /* @escapeNotVerified */ echo $categoryName; ?>
</div>
<div class="product-carousel" data-mage-init='"viewPageSlickCarousel": '>
<?php
foreach ($productCollection as $product)
$productName = $product->getName();
$productUrl = $block->productRender($product);
$templateType = OXProductReviewBlockProductReviewRenderer::STAR_VIEW;
$image = 'upsell_products_list';
?>
<?php if ($product->isSaleable()): ?>
<div class="product-carousel-item text-center">
<div class="product-carousel-item-image">
<!--To display Product label -->
<?php
$productAttributeCode = $this->getAttributeCode($product);
if (!empty($productAttributeCode))
$attributeOptionlabel = $product->getAttributeText($productAttributeCode);
if (!empty($attributeOptionlabel))
$attributeOptionText = strtolower($attributeOptionlabel);
$optionLabel = str_replace(" ", "-", $attributeOptionText);
$mediaUrl = $block->getMediaUrl();
$productLabelUrl = $mediaUrl . 'attribute/options/' . $optionLabel . '.png';
?>
<div class="product-label shy-product-label">
<img src="<?php echo $productLabelUrl ?>" alt="<?php echo $optionLabel ?>">
</div>
<?php
?>
<!-- To display Product label End -->
<a href="<?= $productUrl ?> ">
<?= $block->getImage($product, $image)->toHtml(); ?>
</a>
<?= $block->getReviewsSummaryHtml($product, $templateType) ?>
</div>
<div class="product details product-carousel-item-details">
<div class="product-carousel-item-name">
<a class="" href="<?= $productUrl ?>">
<?= $productName ?>
</a>
</div>
<?= /* @escapeNotVerified */ $block->getProductPrice($product) ?>
<div class="product-carousel-item-inner">
<div class="product actions product-item-actions">
<div class="actions-primary">
<?php $controller = $block->getUrl('ajaxcart/index/productdata/') ?>
<form data-product-type="<?= /* @NoEscape */ $product->getTypeId() ?>" data-role="tocart-form" data-url="<?php echo $controller ?>" data-product-name="<?= /* @NoEscape */ $product->getName() ?>" data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>" action="<?= $block->getUrl("checkout/cart/add") ?>" method="post" >
<input type="hidden" value="<?= $product->getId() ?>" name="product">
<input type="hidden" value="<?= $block->getEncodeUrl() ?>" name="uenc">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<!--- Item end -->
</div>
<?php
endif;
?>
</div>
</div>
</div>
<script type="text/x-magento-init">
"[data-role=tocart-form], .form.map.checkout":
"productInfoPopup":
</script>
<div id="product-popup"> </div>
And also refer Magento 2 colour swatches not showing on homepage
add a comment |
In Layout file:
<container name="home.lookbook" htmlTag="div" htmlClass="lookbook-block home-cards">
<block class="MagentoFrameworkViewElementTemplate" name="lookbook"
template="Magento_Theme::html/home/lookbook.phtml"/>
</container>
In Template file:
<?php
$collection = $this->getProductDetails();
$productCollection = $collection['collection'];
$categoryName = $collection['name'];
if (count($productCollection))
?>
<div class="shy-block mgb20 product-recently">
<div class="most-viewed">
<div class="lg-title">
<?php /* @escapeNotVerified */ echo $categoryName; ?>
</div>
<div class="product-carousel" data-mage-init='"viewPageSlickCarousel": '>
<?php
foreach ($productCollection as $product)
$productName = $product->getName();
$productUrl = $block->productRender($product);
$templateType = OXProductReviewBlockProductReviewRenderer::STAR_VIEW;
$image = 'upsell_products_list';
?>
<?php if ($product->isSaleable()): ?>
<div class="product-carousel-item text-center">
<div class="product-carousel-item-image">
<!--To display Product label -->
<?php
$productAttributeCode = $this->getAttributeCode($product);
if (!empty($productAttributeCode))
$attributeOptionlabel = $product->getAttributeText($productAttributeCode);
if (!empty($attributeOptionlabel))
$attributeOptionText = strtolower($attributeOptionlabel);
$optionLabel = str_replace(" ", "-", $attributeOptionText);
$mediaUrl = $block->getMediaUrl();
$productLabelUrl = $mediaUrl . 'attribute/options/' . $optionLabel . '.png';
?>
<div class="product-label shy-product-label">
<img src="<?php echo $productLabelUrl ?>" alt="<?php echo $optionLabel ?>">
</div>
<?php
?>
<!-- To display Product label End -->
<a href="<?= $productUrl ?> ">
<?= $block->getImage($product, $image)->toHtml(); ?>
</a>
<?= $block->getReviewsSummaryHtml($product, $templateType) ?>
</div>
<div class="product details product-carousel-item-details">
<div class="product-carousel-item-name">
<a class="" href="<?= $productUrl ?>">
<?= $productName ?>
</a>
</div>
<?= /* @escapeNotVerified */ $block->getProductPrice($product) ?>
<div class="product-carousel-item-inner">
<div class="product actions product-item-actions">
<div class="actions-primary">
<?php $controller = $block->getUrl('ajaxcart/index/productdata/') ?>
<form data-product-type="<?= /* @NoEscape */ $product->getTypeId() ?>" data-role="tocart-form" data-url="<?php echo $controller ?>" data-product-name="<?= /* @NoEscape */ $product->getName() ?>" data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>" action="<?= $block->getUrl("checkout/cart/add") ?>" method="post" >
<input type="hidden" value="<?= $product->getId() ?>" name="product">
<input type="hidden" value="<?= $block->getEncodeUrl() ?>" name="uenc">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<!--- Item end -->
</div>
<?php
endif;
?>
</div>
</div>
</div>
<script type="text/x-magento-init">
"[data-role=tocart-form], .form.map.checkout":
"productInfoPopup":
</script>
<div id="product-popup"> </div>
And also refer Magento 2 colour swatches not showing on homepage
In Layout file:
<container name="home.lookbook" htmlTag="div" htmlClass="lookbook-block home-cards">
<block class="MagentoFrameworkViewElementTemplate" name="lookbook"
template="Magento_Theme::html/home/lookbook.phtml"/>
</container>
In Template file:
<?php
$collection = $this->getProductDetails();
$productCollection = $collection['collection'];
$categoryName = $collection['name'];
if (count($productCollection))
?>
<div class="shy-block mgb20 product-recently">
<div class="most-viewed">
<div class="lg-title">
<?php /* @escapeNotVerified */ echo $categoryName; ?>
</div>
<div class="product-carousel" data-mage-init='"viewPageSlickCarousel": '>
<?php
foreach ($productCollection as $product)
$productName = $product->getName();
$productUrl = $block->productRender($product);
$templateType = OXProductReviewBlockProductReviewRenderer::STAR_VIEW;
$image = 'upsell_products_list';
?>
<?php if ($product->isSaleable()): ?>
<div class="product-carousel-item text-center">
<div class="product-carousel-item-image">
<!--To display Product label -->
<?php
$productAttributeCode = $this->getAttributeCode($product);
if (!empty($productAttributeCode))
$attributeOptionlabel = $product->getAttributeText($productAttributeCode);
if (!empty($attributeOptionlabel))
$attributeOptionText = strtolower($attributeOptionlabel);
$optionLabel = str_replace(" ", "-", $attributeOptionText);
$mediaUrl = $block->getMediaUrl();
$productLabelUrl = $mediaUrl . 'attribute/options/' . $optionLabel . '.png';
?>
<div class="product-label shy-product-label">
<img src="<?php echo $productLabelUrl ?>" alt="<?php echo $optionLabel ?>">
</div>
<?php
?>
<!-- To display Product label End -->
<a href="<?= $productUrl ?> ">
<?= $block->getImage($product, $image)->toHtml(); ?>
</a>
<?= $block->getReviewsSummaryHtml($product, $templateType) ?>
</div>
<div class="product details product-carousel-item-details">
<div class="product-carousel-item-name">
<a class="" href="<?= $productUrl ?>">
<?= $productName ?>
</a>
</div>
<?= /* @escapeNotVerified */ $block->getProductPrice($product) ?>
<div class="product-carousel-item-inner">
<div class="product actions product-item-actions">
<div class="actions-primary">
<?php $controller = $block->getUrl('ajaxcart/index/productdata/') ?>
<form data-product-type="<?= /* @NoEscape */ $product->getTypeId() ?>" data-role="tocart-form" data-url="<?php echo $controller ?>" data-product-name="<?= /* @NoEscape */ $product->getName() ?>" data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>" action="<?= $block->getUrl("checkout/cart/add") ?>" method="post" >
<input type="hidden" value="<?= $product->getId() ?>" name="product">
<input type="hidden" value="<?= $block->getEncodeUrl() ?>" name="uenc">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<!--- Item end -->
</div>
<?php
endif;
?>
</div>
</div>
</div>
<script type="text/x-magento-init">
"[data-role=tocart-form], .form.map.checkout":
"productInfoPopup":
</script>
<div id="product-popup"> </div>
And also refer Magento 2 colour swatches not showing on homepage
answered Jul 21 at 11:59
Mano MMano M
1,1804 silver badges25 bronze badges
1,1804 silver badges25 bronze badges
add a comment |
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.
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%2f282738%2fmagento2-how-to-display-most-view-product-collection-in-home-page%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