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
Related
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
<?php $rulesCollection = Mage::getModel('salesrule/rule')->getCollection();
$i=1;
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$totalPrice = 0;
foreach($items as $item) {
$totalPrice+=$item->getPrice();
}
$coll = Mage::getResourceModel('salesrule/rule_collection')->load();
echo '<div class=vip_test>';
foreach($coll as $rule){
$productDetail = $rule->afterLoad();
$discountAmount = $productDetail['discount_amount'];
echo "<div class=ssk><span> You Save : </span>".$totalAmount = $totalPrice-($discountAmount/100*$totalPrice)."</div>";
$ruleID = $productDetail['rule_id'];
}
foreach($rulesCollection as $rule){
$coupon = $rule->getCode();
$couponName = $rule->getName()
?>
In Magento, with this I am getting only the coupon code and coupon name. I want to display if there is any coupon code for particular product in shopping cart, in front of coupon - its showing the saving amount. Is it possible or not? Am I doing Wrong? please help me
First you need to get the collection of products which are in your cart. Then you need to check if there are any active coupons in catalog price rules or shopping cart price rules for the products which are in your cart. If all the above conditions becomes true then you need to display the coupon code of it.
On the next side, you need to calculate the difference amount of it and also you need to display if the user increases his quantity then the savings amount value also has to be increased.
I need to show qty field for tier_price near regular price in product list (highest qty for lowest tier_price). Now $_product->getTierPrice() in product list gives me array(1) with 'tier_price'=>xxx and 'qty'=>1 (where xxx is lowest of my tier prices). Is it possible to get qty for tier_price in product list?
PS. In product view I can see array of tier prices with $_product->getTierPrice().
Magento CE 1.7.0.2
You can put this code in list.phtml or in view.phtml to show tier prices for each quantity.
$attribute = $_product->getResource()->getAttribute('tier_price');
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
foreach($tierPrices as $tierPrice)
{
?>
<span class="priceqty"><?php echo '+'.round($tierPrice["price_qty"], 0);?></span><br>
<span class="pricetitle"><?php echo $symbol.number_format($tierPrice["price"], 2, '.', '');?></span>
<?php
}
}
?>
If you are looking for a Magento way:
$attribute = $_product->getResource()->getAttribute('tier_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
}
From /app/code/core/Mage/Catalog/Model/Product/Type/Price.php getTierPrice()
I have tested on Magento 1.4.0.2 (it should work also on other version ) on category pages and it works
In case you want to do it with SQL look here:
Magento: Display tier prices at category listing page
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
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;