I have wholesale attributes for certain products under one store in Magento. I would like to set it so those particular attributes only appear on the product page IF the customer is logged in and they are in the Wholesale customer group.
Is this possible?
Something like this should work, although I have not tested this together. It's assuming your wholesale groupid = 2 and that you want to show the product attribute 'productvideos'
app/design/frontend/default//template/catalog/product/view.phtml
if($_isLoggedIn === true){
$_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($_myGroupId == 2){
print $_helper->productAttribute($_product, $_product->getProductvideos(), 'productvideos');
}
}
Credit:
http://www.magentocommerce.com/boards/viewthread/22597/#t74992
Okay, here's the solution.
In template/catalog/product/view> attributes.phtml use the following:
<?php
$_isLoggedIn = $this->helper('customer')->isLoggedIn();
if($_isLoggedIn == true){
$_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($_myGroupId == 2){
echo '<td class="label">Attribute Name/Label</td>';
echo '<td class="label">';
if ($_product->getResource()->getAttribute('attribute_id')->getFrontend()->getValue($_product)):
echo $_product->getResource()->getAttribute('attribute_id')->getFrontend()->getValue($_product);
endif;
echo '</td>';
}
}
?>
Thanks to #nvoyageur for the initial pointer in the right direction!
I had the same use case and I used the GroupsCatalog extension, which is free and works perfectly for me.
Related
i've stumbled on a relatively known issue, but i cant find the solution.
I am using magento 1.9 CE
I have found some code to show a vertical menu of the current categorie with its children, and on the homepage the root category and everything works fine except 1 little detail. The subcategories don't load in the order of the backend. It's important that the same order as how it is setup in teh backend loads. I have tried allot of variations, like getCChildrenCategories but then it results in a blnak page. I also found menu's that do work, but then when i visit the homepage, i get an error and the page turns blank.
This is the code i am using at the moment.
<section class="block-layered-nav custom-left-menu" role="navigation">
<div class="block-content">
<?php
echo "<dl id='narrow-by-list2'>";
$_category = $this->getCurrentCategory();
$subcatid = $_category->getId();
$parentCategory = Mage::getBlockSingleton('catalog/navigation')->getCurrentCategory()->parent_id;
$name = $_category->getName();
$root_category = Mage::getModel('catalog/category')->load($subcatid);
$subcategories = $root_category->getChildren();
if($subcategories != "")
{
echo "<span class='h3'>Categorie</span><ol>";
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a></li>';
}
}
else
{
echo "<span class='h3'>Categorie</span><ol>";
$root_category = Mage::getModel('catalog/category')->load($parentCategory);
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a>';
}
}
echo "</ol>";
?>
</div>
</section>
Any help would be much appreciated. All i know is that, somewhere in this code its not calling the categories the right way, i also tried:
$currentCat = Mage::registry('current_category');
but this results in a blank homepage.
Here is a link to the dev enviremont: http://dev.smoldersbv.nl/schroeven-en-bouten.html
If you hover over the main navigation you see a different order, the correct order, then on the left menu.
This is normal $this->getCurrentCategory() get the current category = the category you are currently browsing.
On the home page you are not in a category, like on any other cms pages or even on the contact us page, ... (and there are lots more). So you have nothing in the current category which is obvious.
Problem solved,
The way of the requests where wrong therefor this menu is unable to produce the order of the backend so i ended up using a whole different mockup.
thnx for looking anyway.
I Have a product for example,t-shirt that is added to men's category and women's category.Now I want to display a woman's image of that t-shirt on women's category & man's t-shirt image in men's category.
Is there any possiblities for the above without creating the same product again.
If possible kindly provide idea for it.
Ok fair enough. Here's a quick solution to your problem. It's a bit scrappy, but you get the idea. In this example I assume your ladies category has an ID of 123, and the image you want to show in the ladies category is the product's second image;
$otherImage = false;
$catId = 123; // The id of the category to show a different image on
$imageNumber = 2; // The position in the gallery of the image you want to show
$currentCatId = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();
if($currentCatId == $catId) { // This is the category you wanted
$count = 1;
$gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
foreach ($gallery as $image):
if($count == $imageNumber) {
// This is the image you want
$otherImage = $this->helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(180);
}
$count++;
endforeach;
}
if($otherImage) { echo '<img src="'.$otherImage.'" />'; } else { echo '<img src="'.$this->helper('catalog/image')->init($_product, 'small_image')->resize(180).'" />'; }
There is no native way to do this in Magento. Product images can be set per store view but not per category. I can think of various ways you could achieve this, but unless your portfolio is huge, I would recommend you either use a unisex image (maybe both male and female) or create a separate product for each gender.
T
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;
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
On the default product view page for magento where is "getPriceHtml" function located or what is being called here:
<?php echo $this->getPriceHtml($_product) ?>
Several words are being displayed by this code such as "Price From:" with the price included afterwards. This is for a configurable product.
Mage_Catalog_Block_Product::getPriceHtml()
This method renders via app/design/frontend/base/default/template/catalog/product/price.phtml
a.k.a The Worst Template In Magento®
benmark's answer comes down to this:
<?php echo Mage_Catalog_Block_Product::getPriceHtml($_product, true) ?>
Where $_product relates to the product object.
$productBlock = new Mage_Catalog_Block_Product();
$priceBlock = $productBlock->getPriceHtml($_product, true);
echo $priceBlock;