0

Hi I am getting collection using the below function and then calling this on homepage and its working but I want to use this collection and show it in slider.

my block

public function getProductCollection()
{
    $collection = $this->productCollectionFactory->create();
    $collection->addAttributeToSelect('*');
    $collection->addAttributeToFilter('enable_slider_deal', 1);
    $collection->addAttributeToFilter('status', 1);
    $collection->addAttributeToFilter('visibility', 4);
    $collection->setPageSize(3);
    foreach ($collection as $product)
    {
        echo"<pre>";
        print_r($product->getData());
    }
}

phtml

<?php  
//$dailydeal_products = $block->getProductCollection();
?>


<?php
$productCollection = $block->getProductCollection();
if (count($productCollection)) {
?>
<div class="featured-items" data-aos="slide-up" data-aos-offset="10" data-aos-delay="1" data-aos-duration="400">
    <div class="text-center mt-5">
        <h4 class="text-uppercase display-5">Featured Products</h4>
    </div>
    <div class="row no-gutters pt-3 pb-5 product-grid">
        <div class="col-sm-12" style="width: 100%">
            <div class="carousel-products carousel" data-flickity='{ "groupCells": true, "contain": true }'>
            </div> 
        </div>
    </div>
</div>
<?php } ?>



<div class="carousel-cell">
  <a href="<?php echo $product->getProductUrl(); ?>">
      <img class="img-fluid mb-2 border" src="<?php echo $resizedImageUrl; ?>" alt="<?php echo $product->getName(); ?>" />
      <img class="img-fluid mb-2 border pic-hover" src="<?php echo $resizedHoverImageUrl; ?>" alt="<?php echo $product->getName(); ?>" />
  </a> 
  <p><a href="<?php echo $product->getProductUrl(); ?>" class="text-uppercase font-weight-bold"><?php echo $product->getName(); ?></a><br />
  <?php echo implode(', ', $genders) . '<br/>'; ?>
  
  <?php if($price != $salePrice && $salePrice > 0) { ?>
    <del><?php echo $block->getCurrencyPrice($price); ?></del><span class="sale-text"><?php echo $block->getCurrencyPrice($salePrice); ?></span></p>
  <?php } else { ?>
  <span><?php echo $block->getCurrencyPrice($price); ?></span>
  <?php } ?>                
  <?php  $_ratingSummary = $block->getRatingSummary($product);?>    
  <?php if ($_ratingSummary) { ?>
    <div class="product-reviews-summary short">
        <div class="rating-summary">
            <div title="<?php echo (int)$_ratingSummary; ?>%" class="rating-result">
                <span style="width:<?php echo (int)$_ratingSummary; ?>%"><span><?php echo (int)$_ratingSummary; ?>%</span></span>
            </div>
        </div>                      
    </div>
    <?php } ?>                  
</div>
<?php  ?>  

any help on this

6
  • what's issue you faced? – Rohan Hapani Sep 29 '20 at 5:57
  • i dont know right for showing collection in slider need some suggestion to approach it – Pramod Sep 29 '20 at 5:58
  • @RohanHapani Check Updated phtml code but its not working – Pramod Sep 29 '20 at 6:12
  • Did you get product collection in phtml? – Rohan Hapani Sep 29 '20 at 7:03
  • yep here is the collection $productCollection = $block->getProductCollection(); – Pramod Sep 29 '20 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.