magento 2.4 pagination not working in grid mode frontend - magento

currently I am facing an issue with my grid view category page "frontend" when I switch to list view the pagination working perfect e.g when I switch to page 3 and then want to come back to page 1 it's working.
but when I switch to grid view and move to page 2 or 3 and then want to click page 1 then it's not working the page is not clickable but page 2 is clickable.
I am using Magento 2.4 version with SM Market theme
below is my pager.phmtl code
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Pager template
*
* #see \Magento\Theme\Block\Html\Pager
*/
?>
<?php if ($block->getCollection()->getSize()): ?>
<?php if ($block->getUseContainer()): ?>
<div class="pager">
<?php endif ?>
<?php if ($block->getShowAmounts()): ?>
<p class="toolbar-amount">
<span class="toolbar-number">
<?php if ($block->getLastPageNum()>1): ?>
<?= $block->escapeHtml(
__('Items %1 to %2 of %3 total', $block->getFirstNum(), $block->getLastNum(), $block->getTotalNum())
) ?>
<?php elseif ($block->getTotalNum() == 1): ?>
<?= $block->escapeHtml(__('%1 Item', $block->getTotalNum())) ?>
<?php else: ?>
<?= $block->escapeHtml(__('%1 Item(s)', $block->getTotalNum())) ?>
<?php endif; ?>
</span>
</p>
<?php endif ?>
<?php if ($block->getLastPageNum()>1): ?>
<div class="pages">
<strong class="label pages-label" id="paging-label"><?= $block->escapeHtml(__('Page')) ?></strong>
<ul class="items pages-items" aria-labelledby="paging-label">
<?php if (!$block->isFirstPage()): ?>
<li class="item pages-item-previous">
<?php $text = $block->getAnchorTextForPrevious() ? $block->getAnchorTextForPrevious() : '';?>
<a class="<?= $block->escapeHtmlAttr($text ? 'link ' : 'action ') ?> previous"
href="<?= $block->escapeUrl($block->getPreviousPageUrl()) ?>?p=1"
title="<?= $block->escapeHtmlAttr($text ? $text : __('Previous')) ?>">
<span class="label"><?= $block->escapeHtml(__('Page')) ?></span>
<span><?= $block->escapeHtml($text ? $text : __('Previous')) ?></span>
</a>
</li>
<?php endif;?>
<?php if ($block->canShowFirst()): ?>
<li class="item">
<a class="page first" href="<?= $block->escapeUrl($block->getFirstPageUrl()) ?>?p=1">
<span class="label"><?= $block->escapeHtml(__('Page')) ?></span>
<span>1</span>
</a>
</li>
<?php endif;?>
<?php if ($block->canShowPreviousJump()): ?>
<li class="item">
<a class="page previous jump"
title=""
href="<?= $block->escapeUrl($block->getPreviousJumpUrl()) ?>">
<span>...</span>
</a>
</li>
<?php endif;?>
<?php foreach ($block->getFramePages() as $_page): ?>
<?php if ($block->isPageCurrent($_page)): ?>
<li class="item current hola">
<strong class="page">
<span class="label"><?= $block->escapeHtml(__('You\'re currently reading page')) ?></span>
<span><?= $block->escapeHtml($_page) ?></span>
</strong>
</li>
<?php else: ?>
<li class="item">
<a href="<?= $block->escapeUrl($block->getPageUrl($_page)) ?>?p=1" class="page">
<span class="label"><?= $block->escapeHtml(__('Page')) ?></span>
<span><?= $block->escapeHtml($_page) ?></span>
</a>
</li>
<?php endif;?>
<?php endforeach;?>
<?php if ($block->canShowNextJump()): ?>
<li class="item">
<a class="page next jump" title="" href="<?= $block->escapeUrl($block->getNextJumpUrl()) ?>">
<span>...</span>
</a>
</li>
<?php endif;?>
<?php if ($block->canShowLast()): ?>
<li class="item">
<a class="page last" href="<?= $block->escapeUrl($block->getLastPageUrl()) ?>">
<span class="label"><?= $block->escapeHtml(__('Page')) ?></span>
<span><?= $block->escapeHtml($block->getLastPageNum()) ?></span>
</a>
</li>
<?php endif;?>
<?php if (!$block->isLastPage()): ?>
<li class="item pages-item-next">
<?php $text = $block->getAnchorTextForNext() ? $block->getAnchorTextForNext() : '';?>
<a class="<?= /* #noEscape */ $text ? 'link ' : 'action ' ?> next"
href="<?= $block->escapeUrl($block->getNextPageUrl()) ?>"
title="<?= $block->escapeHtmlAttr($text ? $text : __('Next')) ?>">
<span class="label"><?= $block->escapeHtml(__('Page')) ?></span>
<span><?= $block->escapeHtml($text ? $text : __('Next')) ?></span>
</a>
</li>
<?php endif;?>
</ul>
</div>
<?php endif; ?>
<?php if ($block->isShowPerPage()): ?>
<div class="limiter">
<strong class="limiter-label"><?= $block->escapeHtml(__('Show')) ?></strong>
<select id="limiter" data-mage-init='{"redirectUrl": {"event":"change"}}' class="limiter-options">
<?php foreach ($block->getAvailableLimit() as $_key => $_limit): ?>
<option value="<?= $block->escapeUrl($block->getLimitUrl($_key)) ?>"
<?php if ($block->isLimitCurrent($_key)): ?>
selected="selected"<?php endif ?>>
<?= $block->escapeHtml($_limit) ?>
</option>
<?php endforeach; ?>
</select>
<span class="limiter-text"><?= $block->escapeHtml(__('per page')) ?></span>
</div>
<?php endif ?>
<?php if ($block->getUseContainer()): ?>
</div>
<?php endif ?>
<?php endif ?>

Related

Magento: Show recently added products homepage

I want show the last 8 products that I've added on the homepage. How can I do that?
Using this code snippet for Block File form the previous answer will give a more well structured collection, because:
Filter product by status Enabled
Filter product by visibility (simple products of configurable (which are by default 'Not Visible Individually') will not show in this collection)
$_productCollection = Mage::getModel("catalog/product")
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter(
'status',
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
);
<b> To show recently added products,</b>
1. Create Block file and template file (phtml)
2. To show in homepage go to admin panel. Click on CMS->Pages->Homepage(Homepage will be set based on your theme). Inside that Click on Design tab and add the below code:
<reference name="content">
<block type="rileytheme/recentproducts" name="recentproducts_recentproducts" template="recentproducts/recentproducts.phtml"></block>
<block type="cms/block" name="myelement"><action method="setBlockId"<block_id>homepage_block</block_id></action></block>
</reference>
Block File:
//class Namespace_Module_Block_Filename
class MGS_Rileytheme_Block_Recentproducts extends Mage_Core_Block_Template {
public function getRecentProducts() { <br/>
$products = Mage::getModel("catalog/product")
->getCollection()
->addAttributeToSelect('*')
->setOrder('entity_id', 'DESC')
->setPageSize(5); //set page size as your wish
return $products;
}
View File (phtml):
<?php $products = $this->getRecentProducts(); ?>
<?php shuffle($products); ?>
<div class="container">
<div class="box recently" style="padding-left:15px; padding-right:15px;">
<h1 class="text-center fw400 text-red"><?php echo $this->__('Recent Products') ?></h3>
<div class="listing-type-grid catalog-listing">
<?php $_collectionSize = count($products) ?>
<?php $i=0; foreach ($products as $_res): ?>
<?php $_product = Mage::getModel('catalog/product')->load($_res->getId()); ?>
<?php if ($i++%3==0): ?><tr><?php endif ?>
<div class="col-xs-12 col-sm-6 col-md-3 prod-list">
<div class="grid_list">
<div class="product">
<div class="image-container">
<?php if($_product->getProductLabel()): ?>
<a href="<?php echo $_product->getProductUrl() ?>">
<span class="onsale <?php echo strtolower($_product->getAttributeText('product_label')) ?>"><?php echo $_product->getAttributeText('product_label') ?></span>
</a>
<?php endif ?>
<img alt="" class="img-responsive" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(800,800); ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->__('View detail')?>" class="icon-left icon-top ">
<i class="fa fa-eye"></i>
</a>
<a href="<?php echo $_product->getProductUrl()?>" title="<?php echo $this->__('Add to Cart')?>" class="icon-right icon-top">
<i class="fa fa-shopping-cart"></i>
</a>
<?php if($this->helper('wishlist')->isAllow()): ?>
<!--<a class="icon-left ves-boxcolor icon-bottom" href="<?php echo $this->helper('wishlist')->getAddUrl($_product)?>" title="<?php echo $this->__('Add to wishlist')?>">
<i class="fa fa-heart"></i>
</a>-->
<?php endif;?>
<?php if($this->getAddToCompareUrl($_product)): ?>
<!--<a class="icon-right boxcolor icon-bottom" href="<?php echo $this->getAddToCompareUrl($_product)?>" title="<?php echo $this->__('Add to compare')?>">
<i class="fa fa-retweet"></i>
</a>-->
<?php endif;?>
</div>
<!--<div class="media-productlist">
<a href="<?php // echo $_product->getProductUrl() ?>" title="<?php // echo $this->htmlEscape($_product->getName()) ?>">
<img class="product-image" src="<?php // echo $this->helper('catalog/image')->init($_product, 'small_image');?>" alt="<?php // echo $this->htmlEscape($_product->getName()) ?>" />
</a>
</div>-->
<div class="product-list-data">
<a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a>
<div class="product-list-data-inner">
<div class="cart-item-price">
<?php $_product->getPrice();?>
<span class="price"><?php echo $_formattedActualPrice = Mage::helper('core')->currency($_product->getPrice(),true,false);?></span>
</div>
<div class="cart-item-stars">
<div class="rating-shop-item">
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php else:?>
<span class="star"></span>
<span class="star"></span>
<span class="star"></span>
<span class="star"></span>
<span class="star"></span>
<?php endif; ?>
</div>
<div class="space10"></div>
</div>
<div class="book-now-btn">
<button onclick="setLocation('<?php echo $_product->getProductUrl() ?>')" title="<?php echo $this->__('Book Now') ?>" type="button" class="btn btn-primary btn-sm"><?php echo $this->__('Book Now') ?></button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php if ($i%3==0 && $i!=$_collectionSize): ?></tr><?php endif ?>
<?php endforeach ?>
<?php for($i;$i%3!=0;$i++): ?>
<td class="empty-product"> </td>
<?php endfor ?>
<?php if ($i%3==0): ?> <?php endif ?>
</div>
</div>
</div>

Magento show all child categories on child category

I have been searching high and low for this answer. I would be extremely grateful if someone can point me in the right direction. I would like to show all other child categories on a child category in my sidebar navigation.
As an example...
INSTEON
INSTEON Starter Kits
INSTEON Responders
INSTEON Controllers
INSTEON Accessories
When selecting a child category of INSTEON (INSTEON Responders as an example) - I would still like the other children to display (please see http://www.smarthome.com.au/insteon.html). Ideally the current child should be bold and the other children normal.
I believe I need to edit app/design/frontend/theme/subtheme/template/catalog/navigation/left.phtml
<!--Added by Brad - Get current category -->
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content">
<dl id="narrow-by-list2">
<!--Added by Brad - Display current category name -->
<dt><h2><?php echo $currentCategory->getName(); ?><?php echo $this->__('') ?></h2></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->escapeHtml($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<?php endif; ?>
Any help is greatly appreciated.
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $parent = $this->getCurrentCategory()->getParentCategory()->getId(); ?>
<?php $parent = Mage::getModel('catalog/category')->load($parent); ?>
<?php $siblings = explode(',', $parent->getChildren()); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav block-layered-nav--no-filters">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content toggle-content open">
<p class="block-subtitle block-subtitle--filter"><?php echo $this->__('Filter') ?></p>
<dl id="narrow-by-list2">
dt><?php echo $this->__('Category') ?></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>>
<?php echo $this->escapeHtml($_category->getName()) ?>
<span class="count">(<?php echo $_category->getProductCount() ?>)</span>
</a>
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<?php elseif(count($siblings > 1)): ?>
<div class="block block-layered-nav block-layered-nav--no-filters">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content toggle-content open">
<p class="block-subtitle block-subtitle--filter"><?php echo $this->__('Filter') ?></p>
<dl id="narrow-by-list2">
dt><?php echo $this->__('Category') ?></dt>
<dd>
<ol>
<?php foreach($siblings as $sibling_id): ?>
<?php $sibling = Mage::getModel('catalog/category')->load($sibling_id); ?>
<li>
<a href="<?php echo $this->getCategoryUrl($sibling) ?>"<?php if ($this->isCategoryActive($sibling)): ?> class="current"<?php endif; ?>>
<?php echo $this->escapeHtml($sibling->getName()) ?>
<span class="count">(<?php echo $sibling->getProductCount() ?>)</span>
</a>
</li>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
Just use
$parent_category_id = $this->getCurrentCategory()->getParentCategory()->getId();
to get the parent category id. Then
Mage::getModel('catalog/category')->load($parent_category_id);
to load the entire parent category. With that you can load the parent category's children (see Get Child categories magento).
--EDIT--
<!--Added by Brad - Get current category -->
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<!-- My code -->
<?php $parent = $this->getCurrentCategory()->getParentCategory()->getId(); ?>
<?php $parent = Mage::getModel('catalog/category')->load($parent); ?>
<?php $siblings = explode(',', $parent->getChildren()); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content">
<dl id="narrow-by-list2">
<!--Added by Brad - Display current category name -->
<dt><h2><?php echo $currentCategory->getName(); ?><?php echo $this->__('') ?></h2></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->escapeHtml($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<!-- this will only show if there are no child categories of current child (and there are siblings) -->
<?php elseif(count($siblings > 1)): ?>
<!-- show sibling categories if have any -->
<?php foreach($siblings as $sibling_id): ?>
<?php if($sibling_id == $currentCategory->getId()): ?>
<!-- CURRENT CATEGORY -->
<?php else: ?>
<!-- SIBLING CATEGORY -->
<?php $sibling = Mage::getModel('catalog/category')->load($sibling_id); ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

Drop Down Menu in Magento

I have this code in template to make a static home button. On the home button on hover over I would like to have a blog button underneath.
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<div class="container_24">
<div class="grid_24">
<div id="menu-icon">Categories</div>
<ul id="nav" class="sf-menu">
<li class="level0 level-top<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()) echo ' active'; ?>">
<a class="level-top" href="<?php echo $this->getUrl('')?>">
<span>Home</span>
</a>
</li>
<?php echo $_menu ?>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
<?php endif ?>

Display category and subcategories on left block

I want do display selected category name and it subcategories on left side.
app\design\frontend\base\default\template\catalog\navigation\left.phtml
in left.phtml
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content">
<dl id="narrow-by-list2">
<dt><?php echo $this->__('Category') ?>
</dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<?php endif; ?>
Using this code category listing can be viewed but instead of category name, 'CATEGORY' is displayed.How can i view current Category instead of just CATEGORY ?
Here you can get your current category
$_category = Mage::registry('current_category');

Magento displays incorrect products in category view

When I load a productcollection in list.phtml for the first time (or when I turn of caching completely) the products that are returned are the products which reside in the category which was created last (i.e. the category with the highest id). When cache is turned on, on page-refresh the correct products are shown. After the cache is deleted, the same situation occurs (for the correct products to show I need to refresh the page once when the productlisting is shown).
One extra strange thing; If I call
$_product->getCategory()->getName()
the correct categoryname is returned, but when
$_product->getName()
is called, the wrong productname returns... Im at a complete loss here. I have read a similar post elsewhere which stated that when cache is turned on, this problem goes away, but only after the first page-refresh which is highly undesirable.
<?php $_coreHelper = $this->helper('core'); ?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = 4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php echo var_dump($_product->getCategory()->getName()); ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid" style="padding-left:0px;">
<?php endif ?>
<li style="height:230px;" class="hreview-aggregate hproduct item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<h2 class="item fn product-name">
<?php echo substr($this->htmlEscape($_product->getName()), 0, 22).'...' ?>
</h2>
<div>
<div>
<img class="photo fn" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</div>
<div style="clear:both"></div>
</div>
<div>
<div>
<div>
<div>
<div><span style="font-size:13px;font-weight:bold;"><?php echo $_coreHelper->currency($newprice,true,false) ?> <?php echo $this->helper('tax')->__('Ex. BTW') ?></span></div><br />
<div><?php echo $_coreHelper->currency($newtaxprice,true,false) ?> <?php echo $this->helper('tax')->__('Inc. BTW') ?></div>
</div>
</div>
<div style="clear:both;"></div>
<br />
<form action="<?=$this->getAddToCartUrl($_product);?>" method="post" id="product_addtocart_form_<?=$_product->getId();?>" <?if($_product->getOptions()){?> enctype="multipart/form-data"<?}?>>
<?if(!$_product->isGrouped()){?>
<input type="text" name="qty" id="qty" maxlength="12" value="<?echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1);?>" style="width:30px;" /> x
<?}?>
<button type="button" class="button-order" onclick="this.form.submit()"><span><span><?=$this->__('Bestellen');?></span></span></button>
<br /><br />
<span>Zet in verlanglijst</span>
</form>
</div>
</div>
<div style="clear:both"></div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
Re-Index all your products in re-indexing page.
Clear your cache.
Reload your products page.

Resources