Magento condition for specific page - magento

In Magento I'm using <?php if ($this->getIsHomePage()):?> to check if it's the main page or not but how would I check if the user is on a custompage? CMS Page Url Key game-store

To get the URL key / identifier of any CMS page in Magento, use the following bit of code.
<?php
$yourUrlKey = 'game-store';
$cmsPageUrlKey = Mage::getSingleton('cms/page')->getIdentifier();
if($yourUrlKey == $cmsPageUrlKey){
//do something here
}
?>
The above code will print your URL Key

Either
$model = Mage::getModel('cms/page')->load('game-store','identifier');
var_dump($model->getData());
var_dump($model->getPageId());
or
$model = Mage::getModel('cms/page')->getCollection()
->addFieldTofilter('identifier','game-store')
->getFirstItem();
var_dump($model->getData());
var_dump($model->getPageId());
should do it.

Related

How to add Rating of a product in products listing?

I am displaying products of a particular category to the homepage content section.
I have made a separate .phtml file to display my homepage.
Now I want to show the ratings of a product (products are already rated). How do I show it?
If you look at the category listing template it's pretty easy to work out how category pages render out the review summary to show the rating block.
First load the product in question:
$product = Mage::getModel('catalog/product')->load($id);
Then create a product listing block to give access to the correct methods:
$block = Mage::app()->getLayout()->createBlock('catalog/product_list');
Finally run the getReviewsSummaryHtml() method and pass it the product to get the summary HTML.
$html = $block->getReviewsSummaryHtml($product, 'short');
You can do this.
$_product = Mage::getModel('catalog/product')->load($id);
if ($_product->getRatingSummary() && $rating = $this->getReviewsSummaryHtml($_product, 'short')) :
echo $rating;
else:
echo "<a href='$_product->getProductUrl()'>" . $this->__('Be the first to review this') . "</a>";
endif;

how not to show category name in magento breadcrumb?

I am working with a magento website. I have used a featured category to display homepage slider products. So when I click on the product it shows featured as a category in the breadcrumb.
Would it be possible not to show featured in the breadcrumb ? I want category name in the breadcrumb for the rest of categories .
Thanks
Ab
actually not getting your question but you can get some idea from here:
in page/html/breadcrumb.phtml file near line 34-36 change, $_crumbInfo['label'] to $_crumbInfo['title']
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['title']) ?></strong>
then in catalog/block/breadcrumb.php add 2 lines after
$path = Mage::helper('catalog')->getBreadcrumbPath();
$currentCategory = Mage::registry('current_category');
$metaname = $currentCategory['name'];
and change foreach loop like
foreach ($path as $name => $breadcrumb) {
$breadcrumb['title'] = $metaname;
$breadcrumbsBlock->addCrumb($name, $breadcrumb);
$title[] = $breadcrumb['label'];
}
and check it,
hope you get some idea..
Why no simpler than that?
Try to use CSS. Your category will have an automatic and specific class for it. For example:
<li class="category4">
<strong>ARCHERY HUNTING</strong>
</li>
In this piece of code, I have a category that I created, called "Archery hunting". The code auto-created the class="category4", So, only write on your CSS:
.category4 strong { display: none; }
And it will hide only that category.
Instead of using
$_product->getProductUrl()
to fetch URL, use this:
$_product->unsRequestPath()->getUrlInStore(array('_ignore_category' => true))
Then you need to unset last visited category id at the end of your featured block:
Mage::getSingleton('catalog/session')->setLastVisitedCategoryId('');
This is all because key part for forming breadcrumbs is the following code:
$categoryId = $params->getCategoryId();
if (!$categoryId && ($categoryId !== false)) {
$lastId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId();
if ($product->canBeShowInCategory($lastId)) {
$categoryId = $lastId;
}
}
basically, current category is determined by either URL params (hence the modified URL call), or through the session object (hence the removal of last visited category id)
so, to recapitulate, in your Featured block, instead of regular productUrl call, use the one I provided, and at the end of your featured product block listing, remove the lastVisitedCategoryId using the code I gave you

MAGENTO - Registration form (+validation and callback) outside magento files?

I'm trying to integrate a php file inside an aplication that gives users the posibility to register an account. This account has to be registered inside a magento store.
This is what i have to this momment:
<?php
require_once '../../../app/Mage.php';
umask(0);
Mage::app('default');
Mage::app()->getTranslator()->init('frontend');
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
// get layout object
$layout = Mage::getSingleton('core/layout');
//get block object
$block = $layout->createBlock('core/template');
//print_r(get_class_methods(get_class($block))); <- use for seeing classes
$block = $block->setTemplate('customer/form/register.phtml')->renderView();
echo $block;
?>
This code renders the registration form but stops when he is showing the input fields. I tried with "mini.login.phtml" and it renderes correctly. I'm not very good at Magento, or english. I can provide any other information if necessary.
Any help will be appreciated!
Regards
You are using the wrong block type when dynamically creating the block. Try using this:
createBlock('customer/form_register')

Redirect customer back to product after login in Magento

By default, when a customer logs in in Magento, they are redirected to their account page.
I'd like to redirect the customer back to the product/page they were visiting before.
How can I do this in Magento? I guess an observer should be the best way, but I have no idea where to start from.
<a href="<?php echo Mage::getUrl('customer/account/login', array('referer' => Mage::helper('core')->urlEncode($this->helper('core/url')->getCurrentUrl())))?>" >Log In</a>
If a logged out customer is on any page on your site, once they click on this anchor tag it will lead them to login page, after they login successfully, they are redirected to the page they were on when they clicked on the anchor tag.
This is an alternative/emulator of the Login link in Magento's original "Top links" logic.
on product page add these code
<?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->helper('core/url')->getCurrentUrl()); ?>
I have put the magento login into a lightbox popup so this code on the page before set's the referral URL. Hope it helps.
<?php
$current_url = $this->helper('core/url')->getCurrentUrl();
$current_session = Mage::getSingleton('customer/session');
if(isset($current_session)) $current_session->setData("before_auth_url", $current_url);
?>
You can also put this in the head so it will set the before_auth_url on every page. But make sure you wrap this in a conditional so it doesn't set the before_auth_url on the login pae itself. Below is the code I used to do this.
<?php
if (! Mage::helper('customer')->isLoggedIn()) {
$current_url = $this->helper('core/url')->getCurrentUrl();
if((strpos($current_url, 'login') > -1) || (strpos($current_url, 'sign-in') > -1) || (strpos($current_url, 'checkout') > -1) ) {
} else {
$current_session = Mage::getSingleton('customer/session');
if(isset($current_session)) $current_session->setData("before_auth_url", $current_url);
}
}
?>
Not so good way but it works.
$redirectUrl = $_SERVER['HTTP_REFERER'];
echo '<script>document.location.href="'. $redirectUrl . '";</script>';
The extension Custom Login Redirect Pro can help you. You can redirect to referer using the shortcode {{referer}}.

Magento - link to a frontend skin js file from an admin file

I'm already using jQuery in my frontend skin files. I've now added some extra functionality in an admin phtml file, that also needs to use jQuery. I don't want to have to include it twice, but how can I link to the existing jQuery file dynamically, assuming I don't know what theme package name is being used on the frontend (because obviously that can change, so I don't want it hardcoded)?
For example, I tried this, but it gives me the admin theme package name, not the frontend package:
<?php
// Get the package name
$configData = Mage::getStoreConfig('design');
$package = $configData['package']['name'];
?>
Anyone?
OK, this seems to be working. I can access the db directly, look for the "design/package/name" in the core_config_data table and then build the url to the js file using that:
<?php // Get the current theme being used, so we can build the url link to our jQuery file
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tablename = Mage::getSingleton('core/resource')->getTableName('core_config_data');
$results = $connection->fetchAll("SELECT * FROM $tablename WHERE path='design/package/name';");
foreach($results as $row) { $theme = $row['value']; };
?>
<script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/'.$theme; ?>/default/js/jquery.min.js"></script>
for me helped to set $storeId as 1 not 0
$package = Mage::getStoreConfig('design/package/name', 1);
$theme = Mage::getStoreConfig('design/theme/default', 1);

Resources