In Magento,how can i add different image for same product that was assigned to more than one category,When it is in different categories - magento

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

Related

How can I get the all attributes together in one page for the each of categories

How can I get the all attributes together in one page for the each of categories
I want to show the filter in this way!
Season
spring
summer
fall
winter
Color
red
green
blue
black
yellow
price
0 to 50
50 to 100
for each categories
please guide me.
I tried to get the layer navigation,but it din't
it seems to me you are talking about layered navigation on category page.
There are two things you can do
insure the category's option value Is Anchor is Yes on Display Settings tab
Category Name -> Display Settings -> Is Anchor
and custom attributes are set Yes for Use In Layered Navigation option on Frontend Properties section.
custom attribute name -> Frontend Properties -> Use In Layered Navigation
for details you can check this link
Thanx,but I need to get it by programmatic
I used the custom coding to get all attributes in layers navigation
$layer = Mage::getModel("catalog/layer");
$category_id = $layer->getCurrentCategory();
$currentCategoryId= $category_id->getId();
$category = Mage::getModel("catalog/category")->load($currentCategoryId);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute)
{
echo $attribute->getAttributeCode().'<br />';
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = 'catalog/layer_filter_decimal';
} else {
$filterBlockName = 'catalog/layer_filter_attribute';
}
Mage::app()->getLayout()->createBlock($filterBlockName)
->setLayer($layer)->setAtributeModel($attribute)->init();
foreach($result->getItems() as $option)
{
echo $option->getFrontendLabel();
echo $option->getLabel().'<br/>';
//echo $option->getValue().'<br/>';
}
}

Magento configurable product stock =0

I have this custom code in my list.phtml to display an image when product qty goes 0:
<?php $stock_count = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($stock_count <1) {
echo '<span style="position:relative;top:-230px;float:right;"><img src="http://www.mysite.com/images/ico_outofstock.png" border=0></span>';
}
?>
Problem is that if product is Configurable it will still display the out of stock image.
What i need is to add something like
if($_product->isConfigurable()) {
to the above code, so the outofstock image will be displayed only for simple products.
Thanks

Magento Retrieve simple product price for configurable product

We have a configurable product called with sku TEST and under it are simple products (for example) red-ven1, red-ven2, blue-ven3, etc. The configurable product itself does not have a price but each simple product does. I need to retrieve the price for the simple product based on the attributes that are selected. So I need the price for red product with vendor 2. How do I get this specific price? I am currently trying to dynamically display the price next to the vendor attribute (so vendor attribute is not selected). Will I have to "invisibly" select the vendor attribute value to get the price? Please advise.
Currently Trying:
<?php $_product = $this->getProduct(); ?>
<?php $_price = $_taxHelper->getPrice($_product, $_product->getPrice()) ?>
<script>
var price = <?=$_price ?>;
/...lots of non-applicable code
for(var i=0; i < IDs.length; i++)//traversing the vendor detail nodes
{
//Invisibly make selection of vendor so as to gather correct price
var optionToSelect = $j('option', '#attribute136').filter(function() {
return $j(this).text().indexOf(data[i].vendor_id) != -1;
}).val();
var vals = $j('#attribute136').val() || [];
vals.push(optionToSelect);
$j('#attribute136').val(vals);
$j('.details'+data[i].vendor_id).append('<li class="priceBlock">$'+price+'</li>');
}
});
</script>
After some research I figured out this is pretty hard to solve on your own. If you're willing to spend a few bucks this is a great extension:
http://www.magentocommerce.com/magento-connect/simple-product-pricing.html

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

Resources