Replacing the getHomeLink in Magento - magento

Can I just replace code <?php echo $this->getHomeLink() ?> in the header.phtml file copied below with http://ourdomainname.com?
Since our magento store is linked through navigation within our site, we want to use a link to our main domain in the header INSTEAD of using the store domain name.
Thanks for your help.
<div class="header-top">
<img src="<?php echo $this->getSkinUrl($this->__('images/logo.gif')) ?>” alt="<?php echo $this->__('Magento Logo') ?>” class="logo"/>
<div class="header-right">
<p class="super">
<?php echo $this->__("Logged in as %s", $this->getUser()->getUsername()) ?><span class="separator">|</span><?php echo $this->formatDate(null, 'full') ?><span class="separator">|</span><?php echo $this->__('Log Out') ?>
</p>
<?php if ( Mage::getSingleton('admin/session')->isAllowed('admin/global_search') ): ?>
<fieldset>
<legend>Search</legend>
<span id="global_search_indicator" class="autocomplete-indicator" style="display: none">
<img src="<?php echo $this->getSkinUrl('images/ajax-loader.gif') ?>” alt="<?php echo $this->__('Loading...') ?>” class="v-middle"/>
</span>
<?php $defSearch = $this->__('Global Record Search') ?>
<input id="global_search" name="query" type="text" class="input-text" value="<?php if(!empty($query)): ?><?php echo $query ?><?php else: ?><?php echo $defSearch ?><?php endif ?>” onfocus="if(this.value==’<?php echo $defSearch ?>’)this.value=’’; “ onblur="if(this.value==’’)this.value=’<?php echo $defSearch ?>’;” />
<div id="global_search_autocomplete" class="autocomplete"></div>
<script type="text/javascript\">
new Ajax.Autocompleter(
‘global_search’,
‘global_search_autocomplete’,
‘<?php echo $this->getUrl('*/index/globalSearch') ?>’,
{
paramName:"query",
minChars:2,
indicator:"global_search_indicator",
updateElement:getSelectionId,
evalJSON:’force’
}
);
function getSelectionId(li) {
location.href = li.getAttribute(’url’);
}
</script>
</fieldset>
<?php endif; ?>
</div>
</div>

Of course you can. You can do whatever you want, you just need to live with the consequences of whatever action you take.

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>

Custom attribute text in Magento Cart Crosselling

Currently I have this in crosselling.phtml:
<?php if($this->getItemCount()): ?>
<div class="crosssell">
<h2><?php echo $this->__('Service:') ?></h2>
<ul id="crosssell-products-list">
<?php foreach ($this->getItems() as $_item): ?>
<li class="item">
<a class="product-image" href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(75, 75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" /></a>
<div class="product-details">
<h3 class="product-name"><?php echo $this->escapeHtml($_item->getName()) ?></h3>
<?php echo $this->getPriceHtml($_item, true) ?>
<p><?php
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
echo $custom->getAttributeText('servicetekst');
?></p>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<ul class="add-to-links">
</ul>
</div>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('crosssell-products-list', 'none-recursive')</script>
</div>
<?php endif; ?>
Everything loads fine, except de custom attribute "servicetekst". From here, I'm unsure how to proceed?
I found something that worked for me for displaying custom attributes in crossell template Magento 1.9.2.2. It's easy.
<?php echo $this->escapeHtml($_item->getCustom_attribute()) ?>
Make sure "Used in Product Listing" is set to "Yes" and reindex.

Get the content of terms and conditions by url?

I know this is how you get the content of Terms and Condition,
<?php if (!$this->getAgreements()) return; ?>
<form action="" id="checkout-agreements" onsubmit="return false;">
<ol>
<?php foreach ($this->getAgreements() as $_a): ?>
<li>
<div id="agreement-block-<?php echo $_a->getId();?>" class="agreement-content <?php if (Mage::helper('opc')->getTermsType()):?>hidden<?php endif?>"<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent() ?>
<?php else:?>
<?php echo nl2br($this->htmlEscape($_a->getContent())) ?>
<?php endif; ?>
</div>
<div class="form-group checkbox">
<label>
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>" name="agreement[<?php echo $_a->getId()?>]" value="1" title="<?php echo $this->htmlEscape($_a->getCheckboxText()) ?>" />
<a class="button-cart-simple button-agreement" data-id="<?php echo $_a->getId();?>" data-toggle="modal" data-target="#myModal"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->htmlEscape($_a->getCheckboxText()) ?></a>
</label>
</div>
</li>
<?php endforeach ?>
</ol>
</form>
But can I access this page by using URL?
You can get Term condition value in where in magento using below
code
if (Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
$agreements = Mage::getModel('checkout/agreement')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1);
}

latest product with add-to-cart in magento

I'm new for Magento. I need to display latest added product in home page. I'm using following code in 2columns-left.phtml
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
<?php
$productsCollection = Mage::getModel("catalog/product")->getCollection()
->addAttributeToSort("entity_id","DESC")
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
->setPageSize(6)
->setCurPage(1);
foreach ($productsCollection as $product) {
$model = Mage::getModel('catalog/product')->load($product->getId());
echo $model->getName().'<br>';
echo $model->getPrice().'<br>';
echo $model->getImageUrl().'<br>';
echo "<br><br>";
}
?>
</div>
</div>
It's working fine. But I can't correct code for add-to-cart option.
I found fllowing code from addtocart.phtml with script,
<?php $_product = $this->getProduct(); ?>
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form">
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
</form>
But, if I click add-to-cart, going to home page.
Help me.
Call a block on home page through static block with content value as
{{block type="catalog/product_list" name="product_listing" template="catalog/product/latest.phtml"}}
or you can directly call this block on cms home , paste this
{{block type="catalog/product_list" name="product_listing" template="catalog/product/latest.phtml" }}
in your cms home page content.
create a file in folder frontend/theme_folder/default/template/catalog/product as latest.phtml.
Paste the below code in it as :
Latest Products
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 4);
?>
<?php $_iterator = 0; ?>
<ul class="products-grid">
<?php foreach($_productCollection as $_product) : ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></h2>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
Thats it you will be able to see the latest 4 product on home page. you can increase the number of product by increasing the ->setPage(1, 4); to your required number of product on home page.

Magento getProductCollection not working.

Here is my Magento code to get all new products but it has suddenly stopped working. I added some new categories and then when I saw frontend New Arrivals section was empty. Any help would be appreciated.
Here is my code:
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="new-products">
<div class="title_index">
<!-- <div class="pagination_carousel" id="foo3_pag"></div>-->
<h2><?php echo $this->__('New Arrivals') ?></h2>
</div>
<div class="index_cont">
<div class="list_carousel">
<ul id="user_interaction">
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<li><h3 class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></h3>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(220, 200) ?>" width="150" height="130" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="descr"><?php echo($_product->getSku()); ?></div>
<div class="new_price"><?php echo $this->getPriceHtml($_product, true, '-new') ?></div>
<div class="new_pr_btn"><input value="1" type="text" name="qty" class="my-qty-box" /><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php
echo $this->__('Add to Cart') ?></span></span></button></div>
</li>
<?php endforeach; ?>
</ul>
<div class="clear"></div>
</div>
</div>
<div class="shadow-div"></div>
</div>
<?php endif; ?>
Thanks
Dani
$sql=$this->getProductCollection()->getSelect(); place this code at top of your phtml.
echo $sql;
This will show you sql qquery.
Now fire this query directly in phpMyAdmin or miniadmin and check whether you have records for this query or not.
If not diagnose this sql query, think of filters that resulted in some conditions this will lead you to a fix.
Else you paste sql query here for further comments.
Note : if flat catalog is on code will check flat catalog table.So check if these tables do have all products opulated.If not run indexing.

Resources