Drop Down Menu in Magento - 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 ?>

Related

magento 2.4 pagination not working in grid mode frontend

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 ?>

clicking menu error does not show the page

What is the difference between:
http://localhost/gsa/profile/history --> (offline)
and
http://www.gsa-constructionspecialist.com/profile/history (online)
Offline shows:
Not Found
The requested URL /gsa/profile/history was not found on this server.
After clicking this menu:
views/0hearder.php
<div id="menu">
<h3 class="listmenu" data="1" data-title="home">Home</h3>
<h3 class="listmenu" data="2" data-title="profile">Home</h3>
<div class="submenu2" style="display:none">
<?php
$profile = $this->post_model->post(1);
if ($profile){
foreach ($profile as $pro){
?>
<h3 class="submenu" style="<?php echo ($this->uri->segment(2)==$pro->post_alias)?'font-weight:bold':''; ?>"><?php echo $pro->post_title; ?></h3>
<?php } } ?>
</div>

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>

Add to cart button not adding product in cart

I have created a new1.phtml file in catalog/product with following content
<?php
//getting new product collection
$product=Mage::getModel("catalog/product")->getCollection();
$filtered_prodduct=$product->addAttributeToSelect("*")
->setOrder("created_at","desc")
->addPriceData();
echo "<ul>
<li>";
$i=0;
$row=3;
foreach($filtered_prodduct as $prod){
$i++;
if($i>$row*3){
break;
}
?>
<div class="prod_box">
<div class="center_prod_box">
<div class="product_title">
<a href="<?php echo $prod->getProductUrl()?>">
<?php echo $prod->getName() ?>
</a>
</div>
<div class="product_img">
<a href="<?php echo $prod->getproductUrl()?>">
<img src="<?php echo $prod->getImageUrl()?>" alt="" border="0" height="100" width="100">
</a>
</div>
<div class="prod_price">
<span class="reduce"><?php echo $prod->getSpecialPrice()?></span>
<span class="price"><?php echo $prod->getPrice()?></span><br/>
</div>
</div>
<div class="prod_details_tab">
<?php if($prod->isSaleable()): ?>
<a href="<?php echo $this->getUrl()?>checkout/cart/add? product=<?php echo $prod->getId(); ?>&qty=1" class="prod_buy">
<?php echo $this->__('Add') ?>
</a>
<?php else: ?>
<p class="availability out-of-stock"><span>
<?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<a href="<?php echo $prod->getProductUrl()?>" class="prod_details">
Details
</a>
</div>
</div>
<?php }
?>
Every thing is ok ,but 'Add' button (means add to cart) is not working .It just opens checkout/cart.
i have added this phtml file in layout xml of home page. what is wrong in the code ?
You can do this my using below code ,which generated add to cart url.
Mage::helper('checkout/cart')->getAddUrl(($prod);
If product type is configurable and group or if product type is simple and it have customoption ,then it did not cart directly without selecting any options
The controller's action validates request therefore you should send formKey
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
...
{
Mage::helper('checkout/cart')->getAddUrl(($prod);

Custom output html menu in magento

basicly magento generate menu html:
<ul id="nav">
<li class="level0 nav-1 first level-top">
<span>Home</span>
</li>
<li class="level0 nav-1 first level-top parent">
<span>Category</span>
<ul class="level0">
<li class="level1 nav-2-1 first">
<span>Sub Category</span>
</li>
<li class="level1 nav-2-1">
<span>Sub Category</span>
</li>
<li class="level1 nav-2-1 last">
<span>Sub Category</span>
</li>
</ul>
</li>
</ul>
now, i want custom change output html menu (add more class html, add more element html...) somebody can help me?
There's different tutorials for doing this, but here's what I did:
Save /app/code/frontend/design/default/default/template/page/html/topmenu.phtml to /app/code/frontend/design/yourpackagename/yourthemename/template/page/html/topmenu.phtml and edit as follows:
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<li class="level0 nav-1 first level-top"><a href="/" class="level-top" ><span>Home</span></a></li>
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
To get yourpackagename and yourthemename, use System - Configuration - Design
hth, sconnie

Resources