Magetno how add checkbox in contact form? - magento

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

Related

Magento display the search query along with the breadcrumbs

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.

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>

How to display category description only on the first page in Magento

I'm trying to display category description only on the first page. The following code is not working - any idea how to fix it?
<div class="category-description std">
<?php
if (strlen($_SERVER['QUERY_STRING']) = 0 || $_GET['p'] = '1')
{
echo $_helper->categoryAttribute($_category, $_description, 'description');
}
?>
</div>
Please try this one :
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<?php $currentPage = (int) Mage::App()->getRequest()->getParam('p');
if($currentPage <= 1):
?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php endif; ?>
<?php endif; ?>'
You can use the products list toolbar to know if you're on the first page :
if ($this->isContentMode()
|| $this->getChild('product_list')->getToolbarBlock()->isFirstPage()) {
// Display description (assuming that content mode is always first page)
}

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 - How do I get a list of all allowed countries in optionsarray?

I can get countries like this:
$countryCollection = Mage::getModel('directory/country')->getResourceCollection()->loadByStore();
And they are listed somewhere in the object, but, how do I toOptionsArray them out?
I'm after only the options per website rather than complete listi.e. I want Angola, Antarctica and so on out of the list. (Sorry Angolans and penguins.)
Its actually the obvious answer:
$countryList = Mage::getModel('directory/country')->getResourceCollection()
->loadByStore()
->toOptionArray(true);
also check out http://fishpig.co.uk/magento-tutorials/list-countries-for-drop-down-in-magento for more info on creating drop-down lists and such with the country list.
<?php
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
$allowed = Mage::getStoreConfig('general/country/allow');
if (count($_countries) > 0) { ?>
<div class="input-box">
<select name="country" id="country" class="validate-select" title="Country" >
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country){
if(!in_array($_country['value'],explode(',',$allowed))){
continue;
} ?>
<option value="<?php echo $_country['value']; ?>" <?php echo $formData['country'] == $_country['value'] ? ' selected="selected"' : '';?>>
<?php echo $_country['label'] ?>
</option>
<?php
} ?>
</select>
<?php } ?>

Resources