Magento display the search query along with the breadcrumbs - magento

In my site I need to display breadcrumbs like this.
Home / Search results for: 'laptop' / Lenova G50 Laptop
I am searching any products (like above 'laptop') in site.
After get result I click any products in search result page.
That clicked product view page I need above type of breadcrumbs.
When I click that " Search results for: 'laptop' ", go to that search
result page.
How can i do this ? Any one help me.

try this and get search term and add to it's url and then again generate search url with query
<?php
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');
if(is_null($urlPart))
{
$urlPart = $urlRequest->getServer('PATH_INFO');
}
$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);
//$controllerName = Mage::app()->getFrontController()->getRequest()->getControllerName();
//$controllerName = ucfirst($controllerName);
$controllerName = str_replace("/", " ", $urlPart);
$controllerName = str_replace("_", " ", $controllerName);
$controllerName = str_replace("-", " ", $controllerName);
$controllerName = ucfirst($controllerName);
?>
<span class="breadcrumbs">
<strong class="float"><?php echo $this->__("You're currently on: ") ?>
</strong>
<ul class="breadcrumbs">
<li class="home">
<a title="<?php echo $this->__('Go to Home Page') ?>" href="<?php echo $this->getUrl() ?>"><?php echo $this->__('Home') ?></a>
</li>
<li> / </li>
<li class="<?php echo strtolower($controllerName) ?>">
<strong><?php echo $this->__($controllerName) ?></strong>
</li>
</ul>
</span>

I have tried Below Code :
<?php
$last_url = $_SERVER['HTTP_REFERER'];
if (strpos($last_url, 'catalogsearch') !== false && Mage::registry('current_product') && strpos($last_url, 'q=') !== false ) {
$base_url = basename($last_url);
$search = explode("&", $base_url);
foreach($search as $value) {
if(strpos($value, 'q=')!== false) {
$search_text = trim(trim(trim($value), "?"), "q=");
}
}
?>
<div class="breadcrumbs">
<ul>
<li>
<?php echo $this->__("Home");?> /
</li>
<li>
<a href="<?php echo $last_url; ?>">
<?php echo $this->__("Search results for : '%s'", urldecode($search_text));?>
</a>
/
</li>
<li><?php echo $this->escapeHtml(Mage::registry('current_product')->getName()); ?></li>
</ul>
</div>
<?php } ?>
Check this link.

Related

Magetno how add checkbox in contact form?

I must add checkbox in Contact form in Magetno (Magento wer. 1.8.1), I searching tutorials on Google but I found solution ... It is easy way to do this ?
Many Thanks
Wojtek
why you don't use the checkout agreements: Just fetch the agreements in file \app\design\frontend\PACKAGE\TEMPLATE\template\contacts\form.phtml by
if (Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
$agreements = Mage::getModel('checkout/agreement')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1);
}
and print out some or all of them like
if ($agreements) {
foreach ($agreements as $_a):
// ID 5 = Datenschutz-Agreement deutsch, ID 6 = Alter-18-Agreement englisch, ID 7 = Datenschutz-Agreement deutsch, ID 8 = Alter-18-Agreement englisch
if ($_a->getId() >= 7 && $_a->getId() <= 8) {
?>
<li>
<div class="checkout-agreements">
<div class="agreement-content"<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent() ?>
<?php else:?>
<?php echo nl2br($this->escapeHtml($_a->getContent())) ?>
<?php endif; ?>
</div>
<p class="agree">
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>" name="agreement[<?php echo $_a->getId()?>]" value="1" title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>" class="required-entry checkbox" /><label for="agreement-<?php echo $_a->getId()?>"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?></label>
</p>
</div>
</li>
<?php
}
endforeach;
}
That's all!
If there is someone German here: There you will get the full explanation in German!
Best regards
Bastian

Get all product images in Magento 2 on product list page

In Magento 1 I've always used
$_product->getMediaGallery('images')
But in the source from Magento 2 I see
$productImage = $block->getImage($_product, $image);
echo $productImage->toHtml();
It's only getting the first product image.
How do I get the second or third image (not only the base one)?
GetMediaGallery function doesn't exists?
Step 1 : open list.phtml from Your Theme\Magento_Catalog\templates\product
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
Add above in your phtml file
then add below code in product loop where you want gallery images
<div class="left-carousel">
<div class="product-small-thumbs">
<?php $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
$images = $product->getMediaGalleryImages();
if($images->count()>0){?>
<div class="carousel carousel-<?php $_product->getId()?>">
<?php
$i = 0;
foreach($images as $child){
$i++;
$productImage = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(81,53)
->getUrl();
$productImagedata = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(285,240)
->getUrl();
if($i==1) continue;
?>
<div class="slide">
<img data-id="smallthumbs-<?php echo $_product->getId();?>" data-img="<?php echo $productImagedata; ?>" src="<?php echo $productImage; ?>"/>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div>
</div>

products url does not work cant click the

I have the following code to display a product on home page of magento. The product get displayed but I cannot click it and go to the products page .
Can some one please suggest what's wrong.
<?php
//Almost Gone Section
asort($catalog);
reset($catalog);
$almostGoneId = key($catalog);
$almostGoneStock = $catalog[$almostGoneId];
$almostGone = Mage::getModel('catalog/product')->load($almostGoneId);
$_categories = $almostGone->getCategoryIds();
$_catarray = array();
foreach ($_categories as $cat)
{
$category = Mage::getModel('catalog/category')->load($cat);
$_catarray[$category['url_path']] = $category['level'];
}
arsort($_catarray);
$_depth = reset($_catarray);
$_uri = key($_catarray);
$url = $this->getUrl($_uri).$almostGone['url_key'].'';
$almost_gone_price = $almostGone['special_price'];
?>
--><div id="almost_gone" class="product-display-block">
<div class="display-block">
<div class="product_display_image">
<img src="<?php echo $this->helper('catalog/image')- >init($almostGone, 'image')
- >constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(718) ?>" alt="<? php echo $almostGone['name'] ?>">
</div>
<div class="transparent_title">
<!-- <span>Almost Gone, Huge Savings</span> --><span class="display_model">Hurry, Almost Gone Only <?php echo str_replace(".00", "",$_coreHelper->currency($almost_gone_price,true,false)); ?></span>
</div>
</div>
<div class="display_info gone-info">
<span>Grab A Bargain Today, Only </span><span class="red"><?php echo *emphasized text*$almostGoneStock ?></span><span> Left</span>
</div>
<div class="gone-na">
<img src="<?php echo $this->getSkinUrl('images/home/gone-na.png') ?>">
</div>`enter code here`
<div class="link-hover"></div>
</div>
Where is your product url ??
$url = $product->getProductUrl() // may be like this
<a href="<?php echo $url;?>"><img src="<?php echo $this->helper('catalog/image')- >init($almostGone, 'image')
- >constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(718) ?>" alt="<? php echo $almostGone['name'] ?>"></a>

Drop down menu error-display error

i'm in the middle of creating a website and i want to creat a dynamic dropdown menu.The problem is that when i load the entries from the database only the first entry is displayed correctly , the other entries in the menu are displayed as code. I'm using Xamp with PHP 5.3 and HeidiSql.This is my code :
<div id="1" class="mega solidblocktheme">
<div class="column">
<ul>
<li><a href="<?php include('../conect.php'); $result=mysql_query("SELECT * FROM tours");
while($data=mysql_fetch_row($result))
{ echo $data[2]; ?>"> <?php echo $data[1];
echo "</a></li>"; }
mysql_close($con);?>
</ul>
</div>
</div>
Your loop seems to be in the wrong place. Try something like this:
<ul>
<?php include('../conect.php');
$result=mysql_query("SELECT * FROM tours");
while($data=mysql_fetch_row($result))
{
echo '<li><a href="'.$data[2].'">'.$data[1];
echo "</a></li>";
}
mysql_close($con);?>
</ul>
You should not do it this way .
while($data=mysql_fetch_row($result))
{ echo $data[2]; ?>">
echo ""; }
For every loop , you are just adding content and close tags </a> and </li>
But you are not adding start tags for them .
What you can do is , first store your data result in a string
include('../conect.php');
$result=mysql_query("SELECT * FROM tours");
$data=mysql_fetch_row($result);
mysql_close($con);
$list = "";
foreach($data as $data_key) {
$list.= '<li> '.$data[1].' </li>';
}
So now you got your list
After that comes your HTML , just echo your built string
<div id="1" class="mega solidblocktheme">
<div class="column">
<ul>
<?php
echo $list;
?>
</ul>
</div>
</div>

magento - multilingual site + Add store codes to url - want to show flag icons

I want to have a multi-language magento site use a flag image instead of a language selector box for user to select language of page. There is a nice article on this at http://www.atwix.com/magento/replace-language-selector-flag-icons/
Only issue is that we use "Add store codes to url" option. I hacked this code, but it can use some refinement and make it more Magento looking.
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<div class="langs-wrapper">
<?php foreach ($this->getStores() as $_lang): ?>
<?php if ($_lang->getCode() != 'default'): ?>
<?
$base_url = Mage::getBaseUrl();
// remove language in base url
$base_url = str_replace('/en/' , "" , $base_url);
$base_url = str_replace('/fr/' , "" , $base_url);
$current_url = $this->helper('core/url')->getCurrentUrl();
// take out base url and language code
$rest_of_url = str_replace($base_url , "" , $current_url);
$rest_of_url = str_replace('/en/' , "" , $rest_of_url);
$rest_of_url = str_replace('/fr/' , "" , $rest_of_url);
// assmble new url
$new_url = $base_url . '/' . $_lang->getCode() . '/' . $rest_of_url;
?>
<a class="lang-flag" href="<?php echo $new_url ;?>"><img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt=""></a>
<?php endif;?>
<?php endforeach;?>
</div>
</div>
<?php endif;?>
Template file (path/to/template/file.phtml):
<?php if(count($this->getStores()) > 1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $selected = $_lang->getId() == $this->getCurrentStoreId() ?>
<a class="lang-flag<?php $selected && print ' selected' ?>" href="<?php echo $_lang->getCurrentUrl() ?>">
<img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt="<?php echo $this->htmlEscape($_lang->getName()) ?>">
</a>
<?php endforeach ?>
</div>
<?php endif ?>
Add this lines to your layout-update xml file (if you haven't defined switch block):
<block type="page/switch" name="lang.switcher" template="path/to/template/file.phtml" />
If you have already one:
<reference name="store_language">
<action method="setTemplate"><tmpl>path/to/template/file.phtml</tmpl></action>
</reference>

Resources