Translate magento form - php

I am translating a review form. There are some phrases inside form which are predefined in Mage_Review.csv.
No problem so far. But there are two words Overall and Quality inside review form that I can't find their English source inside Mage_Review.csv. I even searched inside Mage_Rating.csv.
This is the form.phtml content. Please take a look:
<div class="form-add">
<h2><?php echo $this->__('Write Your Own Review') ?></h2>
<?php if ($this->getAllowWriteReviewFlag()): ?>
<form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
<fieldset>
<?php echo $this->getChildHtml('form_fields_before')?>
<h3><?php echo $this->__("You're reviewing:"); ?> <span><?php echo $this->htmlEscape($this->getProductInfo()->getName()) ?></span></h3>
<ul class="form-list">
<li>
<label for="nickname_field" class="required"><em>*</em><?php echo $this->__('Nickname') ?></label>
<div class="input-box">
<input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getNickname()) ?>" />
</div>
</li>
<li>
<label for="summary_field" class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
<div class="input-box">
<input type="text" name="title" id="summary_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getTitle()) ?>" />
</div>
</li>
<li>
<label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
<div class="input-box">
<textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
</div>
</li>
</ul>
<?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
<h4><?php echo $this->__('How do you rate this product?') ?> <em class="required">*</em></h4>
<span id="input-message-box"></span>
<table class="data-table" id="product-review-table">
<col />
<col width="1" />
<col width="1" />
<col width="1" />
<col width="1" />
<col width="1" />
<thead>
<tr>
<th> </th>
<th><span class="nobr"><?php echo $this->__('1 star') ?></span></th>
<th><span class="nobr"><?php echo $this->__('2 stars') ?></span></th>
<th><span class="nobr"><?php echo $this->__('3 stars') ?></span></th>
<th><span class="nobr"><?php echo $this->__('4 stars') ?></span></th>
<th><span class="nobr"><?php echo $this->__('5 stars') ?></span></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->getRatings() as $_rating): ?>
<tr>
<th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
<?php foreach ($_rating->getOptions() as $_option): ?>
<td class="value"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="hidden" name="validate_rating" class="validate-rating" value="" />
<script type="text/javascript">decorateTable('product-review-table')</script>
<?php endif; ?>
</fieldset>
<div class="buttons-set">
<button type="submit" title="<?php echo $this->__('Submit Review') ?>" class="button"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('review-form');
Validation.addAllThese(
[
['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
var trs = $('product-review-table').select('tr');
var inputs;
var error = 1;
for( var j=0; j < trs.length; j++ ) {
var tr = trs[j];
if( j > 0 ) {
inputs = tr.select('input');
for( i in inputs ) {
if( inputs[i].checked == true ) {
error = 0;
}
}
if( error == 1 ) {
return false;
} else {
error = 1;
}
}
}
return true;
}]
]
);
//]]>
</script>
<?php else: ?>
<p class="review-nologged" id="review-form">
<?php echo $this->__('Only registered users can write reviews. Please, log in or register', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
</p>
<?php endif ?>

You can translate Rating labels in Catalog > Reviews & Ratings > Manage ratings

What Sergey says is correct. You can translate it there, but if you want to do it via the translation files you will have to fix a minor bug in Magento's review from template. The labels in the review form template aren't passed trough the translation module
find this template:
app/design/frontend/[yourtheme]/[yourskin]/template/review/form.phtml
At line 58 (Magento 1.9) you will find this code:
<th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
You will have to add the translation parser ($this->__()) to the code like so:
<th><?php echo $this->__($this->escapeHtml($_rating->getRatingCode())) ?></th>
After you do this you will be able to translate the labels via the translation files

Related

Grouped Product won't be added to cart and there is a message "Please specify the quantity of product(s)."

I am developing a store and the product I tried to add is a grouped product which I had done some design and configuration on the front end. Then, I added sample grouped product and when I click "Add to cart" , there is message "Please specify the quantity of product(s)."
Please see the website (Sorry the website is in Thai but you can try to increase the Quantity of each product and then click add to cart - Pink button)
http://www.preciosathailand.com/eyeline-0001.html
This is PHP code that I made the configuration
<?php if ($_hasAssociatedProducts): ?>
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td width="80%"><span class="product-<?php echo $_item->getId() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></span></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php echo $this->getTierPriceHtml($_item) ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<td class="a-center" width="20%">
<?php if ($_item->isSaleable()) : ?>
<div class="qty-tools">
<div class="minus-qty minus-<?php echo $_item->getId() ?>"><a class="click-to-minus" id="minus-<?php echo $_item->getId() ?>" href="#" data-id-p="<?php echo $_item->getId() ?>">-</a></div>
<div class="input-qty-wrapper">
<input type="text" name="super_group[<?php echo $_item->getId() ?>]" data-qty-product-id="<?php echo $_item->getId() ?>" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
</div>
<div class="plus-qty plus-<?php echo $_item->getId() ?>"><a class="click-to-plus" href="#" id="plus-<?php echo $_item->getId() ?>" data-id-p="<?php echo $_item->getId() ?>">+</a></div>
</div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
</tr>
<?php endif; ?>
This is jQuery that I have done.
jQuery(document).ready(function(){
jQuery('.click-to-minus').click(function(){
var IDInput = jQuery(this).data('id-p');
var CurrentVal = jQuery('input[name="super_group['+IDInput+']"]').val();
var minusedVal = CurrentVal-1;
jQuery('input#'+IDInput).val(minusedVal);
});
jQuery('.click-to-plus').click(function(){
var pIDInput = jQuery(this).data('id-p');
var CurrentPlusVal = jQuery('input[name="super_group['+pIDInput+']"]').val();
/* if ( CountPlus == 0){
var plusedVal = 1;
}else{
jQuery('input#'+pIDInput).val('');
var plusedVal = CurrentPlusVal+1;
}*/
var plusedVal = +CurrentPlusVal+1;
jQuery('input[data-qty-product-id="'+pIDInput+'"]').val(plusedVal);
});
});
Did I do anything wrong?
Are you trying to group configurable products, then you should know that magento doesnt allow it.
you can check this answer here

Display top 10 results in codeigniter and display 1st, 2nd and 3rd top values

I am getting output page like this (Shown in below screenshot)
I want gold image to be display to top scorers and silver to second topper and bronze to others
I am using code like this
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-tasks"></i> ScoreBoard</h3>
</div>
<div class="panel-body">
<div class="col-sm-12">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered">
<tbody>
<?php
$total_exams1 = $this->db->select('title_id')
->from('exam_title')
->count_all_results();
$b1 = $this->db->select('*, (sum(result.result_percent)) / '.$total_exams1.' as percent')
->group_by('users.user_id')
->from('result')
->order_by("percent", "desc" )
->join('users', 'users.user_id = result.user_id', 'left')
->join('states', 'users.state = states.state_id', 'left')
->join('user_zone', 'users.user_zone = user_zone.user_zone_id', 'left')
->limit("10")
->get()
->result();
$j = 1;
foreach($b1 as $z) {
?>
<tr class="<?= ($i & 1) ? 'even' : 'odd'; ?>">
<td style="width:5%;"><?php echo $j; ?></td>
<?php if($z->image == "") { ?>
<td class="hidden-x" style="width:35%;">
<img class="userImgTop10n" src="<?php echo base_url('user-avatar/avatar-placeholder.jpg') ?>" alt="Profile Picture" />
<div class="image_righ">
<b><?php echo $z->user_name; ?></b><br>
<?php echo $z->state_name; ?><br>
<?php echo $z->user_zone_name; ?>
</div>
</td>
<?php } else { ?>
<td class="hidden-x" >
<img class="userImgTop10n" src="<?php echo base_url("user-avatar/".$z->image); ?>" alt="Profile Picture" />
<div class="image_righ">
<b><?php echo $z->user_name; ?></b><br>
<?php echo $z->state_name; ?><br>
<?php echo $z->user_zone_name; ?>
</div>
</td>
<?php } ?>
<?php
$exams_attended1 = $this->db->select('title_id')
->where('user_id', $z->user_id)
->from('result')
->group_by('user_id')
->count_all_results();
?>
<td class="hidden-xxs"><b><?php echo $exams_attended1; ?></b><br>Exams Attended</td>
<td class="hidden-xxs"><b><?php echo $total_exams1; ?></b><br>Total Exams</td>
<td class="hidden-x">
<b><?php echo round($z->percent, 2); ?> %</b><br>Avg Result
<div class="badge_righ">
<?php if($j == 1) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Gold.png') ?>" alt="Badge Gold" /></span>
<?php }
if($j == 2) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Silver.png') ?>" alt="Badge Gold" /></span>
<?php } if($j > 2) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Bronze.png') ?>" alt="Badge Gold" /></span>
<?php } ?>
</div>
</td>
</tr>
<?php
$j++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
in the above screenshot first 3 rows should be gold images (because of same marks).
You can create a temporary array containing unique reverse sorted average scores. Then, when giving medals, instead of checking for places (1st, 2nd, 3rd...), check if the score matches the 1st, 2nd or 3rd score from that temporary array.
For the screenshot you posted, the array would look like:
$scores = [92.5, 90, 87.5];
and the gold medals would be all the scores with the score of $scores[0], the silver ones are $scores[1] and the bronzes would be $scores[2] (unless you want everyone else to get bronze).

Wordpress the_excerpt showing same data for all id's

I have a cart plugin for Wordpress. It uses the_excerpt to show the product description. it works on all pages except the checkout page. On the checkout page it shows the same description for all the products. The description it shows is always from the first product in the database even if that product is not in the cart. I have tried many variations nothing fixes it. it pulls the correct id and price for the product but just the description is always the same for al products.
<?php the_excerpt(get_the_ID()); ?>
<input id="item-<?php echo $item->ID; ?>-price" name="item-<?php echo $item->ID; ?>-price" type="hidden" value="<?php echo intval($price); ?>"/>
In the code above, the price pulls correctly but the_excerpt is same for every product.
i have tried:
<?php the_excerpt(get_the_ID()); ?>
<?php the_excerpt($item->ID); ?>
<?php the_excerpt(get_the_excerpt); ?>
i have also tried if and while but then it just shows all 20 product descriptions for each product
this is all the code for the page:
<script>
window.onload = calculate_order(0,0);
function calculate_order(qty_item, qty_type) {
//qty_type could be add or substract
total = 0;
numberofitems = 0;
if (qty_type == "add"){
document.getElementById((qty_item+"-qty")).value++;
}
if (qty_type == "subtract") {
if (document.getElementById((qty_item+"-qty")).value > 0) {
document.getElementById((qty_item+"-qty")).value--;
}
}
//return;
$('.store-item').each(function(i, obj) {
price = document.getElementById(($(this).attr("id")+"-price")).value;
//price = price * 1 ;
qty = document.getElementById(($(this).attr("id")+"-qty")).value;
//qty = qty * 1;
numberofitems = numberofitems + (qty*1);
total = total + ((price*1)*(qty*1));
//alert (numberofitems);
});
document.getElementById("total_price").innerHTML = total ;
document.getElementById("total_qty").value = numberofitems ;
discount = 100*Math.floor(numberofitems/2);
document.getElementById("total_discount").innerHTML = discount ;
document.getElementById("final_price").innerHTML = (total - discount);
document.getElementById("tot_discount").value = discount ;
document.getElementById("tot_order").value = (total - discount);
document.getElementById("tot_price").value = total ;
if (numberofitems <2) {
$("#total-price").hide();
$("#total-discount").hide();
}
else {
$("#total-price").show();
$("#total-discount").show();
}
return;
}
</script>
<div id="shopping-cart">
<div>
<h2>Shopping Cart</h2>
</div>
<div id="section group">
<div class="col span_1_of_4"> Items in Cart</div>
<div class="col span_1_of_4">
Description
</div>
<div class="col span_1_of_4" style="text-align:center">
Price
</div>
<div class="col span_1_of_4" style="text-align:right">
Quantity
</div>
</div></div>
<div style="clear:both"></div>
<div class="cart-header">
<div id="checkout-form" class="cart-header" style="border:0px;">
<fieldset class="addressdetails">
<table width="330" border="0" cellspacing="0" cellpadding="0">
<tr><td style="width:120px;padding-bottom:5px">Your Name:</td><td style="padding-bottom:5px"><input id="yName" type="text" name="order_name2" style="background-color:#D3E3F8"/></td></tr>
<tr><td>Your Email</td><td style="padding-bottom:5px"><input id="Email" type="text" name="order_email" style="background-color:#D3E3F8"/> </td></tr>
<tr><td></br></td><td>
<tr><td style="width:120px;padding-bottom:5px">Shipping Name:</td><td style="padding-bottom:5px"><input id="Name" type="text" name="order_name" style="background-color:#D3E3F8"/></td></tr>
<tr><td>Shipping Address:</td><td style="padding-bottom:5px"><input id="Address" type="text" name="order_address" style="background-color:#D3E3F8"/></td></tr>
<tr><td>City: </td><td style="padding-bottom:5px"><input id="City" type="text" name="order_city" style="background-color:#D3E3F8"/></td></tr>
<tr><td>State:</td><td style="padding-bottom:5px"><input id="State" type="text" name="order_state" style="background-color:#D3E3F8"/></td></tr>
<tr><td>Zip Code:</td><td style="padding-bottom:5px"><input id="ZipCode" type="text" name="order_zipcode" style="background-color:#D3E3F8"/></td></tr>
<tr><td>Country:</td><td><input id="Country" type="text" name="order_country" style="background-color:#D3E3F8"/></td></tr>
<tr><td></br></td><td>
<tr><td>Comments</td><td style="padding-bottom:5px"><textarea id="Comments" name="order_comments" style="width:180px;background-color:#D3E3F8"></textarea></td></tr>
</table>
</br>
</fieldset>
</br>
<div><label></label><center><input type="submit" name="submit" value="Submit Order" class="submit_order_button"/></center></div>
</div>
</div>
<?php $total = 0; ?>
<?php $nitems = 0; ?>
<?php foreach ($_POST as $item => $quantity): ?>
<?php $matches = array(); ?>
<?php if (preg_match('/^item-([0-9]+)$/', $item, $matches) === 1 and intval($quantity) > 0): ?>
<?php $item = get_post(intval($matches[1])); ?>
<?php if ($item): ?>
<?php $nitems++; ?>
<?php $price = intval(get_post_meta($item->ID, 'price', true)); ?>
<?php $total += $price; ?>
<div class="section group" style="margin:10px 0 10px 0">
<input id="item-<?php echo $item->ID; ?>-ID" type="hidden" name="art_id[]]" value="<?php echo $item->ID; ?>"/>
<div class="col span_1_of_4" style="text-align:center">
<?php echo get_the_post_thumbnail($item->ID, 'checkout-thumbnail'); ?>
</div>
<div class="col span_1_of_4">
<h2><?php
$title = explode('(', $item->post_title, 2);
echo $title[0];
if (count($title) > 1) {
echo '<span class="parenthetical">(';
echo preg_replace('/ /', ' ', $title[1]);
echo '</span>';
}
?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
}
echo get_the_excerpt($item->ID); // Outputs the processed value to the page
?>
<?php endwhile; ?>
</div>
<div class="col span_1_of_4" style="text-align:center">
$ <span id="price"><?php echo $price; ?></span>
</div>
<input id="item-<?php echo $item->ID; ?>-price" name="item-<?php echo $item->ID; ?>-price" type="hidden" value="<?php echo intval($price); ?>"/>
<div class="col span_1_of_4" style="text-align:right">
<input type="text" class="store-item-quantity" style="width:20px" name="item-<?php echo $item->ID; ?>-qty" id="item-<?php echo $item->ID; ?>-qty" value="<?php echo intval($quantity); ?>" readonly />
<input type='button' class="qtybutton" name='add' onclick='javascript: calculate_order("item-<?php echo $item->ID; ?>", "add");' value='+'/>
<input type='button' class="qtybutton" name='subtract' onclick='javascript: calculate_order("item-<?php echo $item->ID; ?>", "subtract");' value='-'/>
</div></div>
<!--<input id="item-<?php echo $item->ID; ?>-qty" type="text" value="<?php echo intval($quantity); ?>"/>-->
</div></div>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<!-- MSR 11062013 display mode of discount -->
<?php $discount = 100*intval(floor($nitems/2)); ?>
<div id="price-totals" style="padding-right:20px">
Price includes international shipping<br />
<table id="price-table">
<input id="total_qty" type="hidden" value="<?php echo $nitems; ?>"/>
<tr id="total-price" <?php if ($nitems < 2) echo 'style="display:none"' ?>>
<td class="price-label">Total:</td>
<td class="price-value">$ <span id="total_price"><?php echo $total; ?></span></td>
</tr>
<tr id="total-discount" <?php if ($nitems < 2) echo 'style="display:none"' ?>>
<td class="price-label">Discount:</td>
<td class="price-value">$ <span id="total_discount"><?php echo $discount; ?></span> </td>
</tr>
<tr>
<td class="price-label"><strong>Final Price:</strong></td>
<td class="price-value"><strong>$ <span id="final_price"><?php echo $total - $discount; ?></strong></span></td>
</tr>
</table>
<input id="tot_price" type="hidden" name="tot_price" value="<?php echo $total; ?>"/>
<input id="tot_discount" type="hidden" name="tot_discount" value="<?php echo $discount; ?>"/>
<input id="tot_order" type="hidden" name="tot_order" value="<?php echo $total - $discount; ?>"/>
</div>
</div>
</div>
</div>
You can't pass parameters to the_excerpt, it always uses the "post in the loop", same goes for get_the_excerpt (I was wrong earlier). By looking at your code, you are looping over each item and getting its corresponding WP_Post object. Its excerpt should then be in $item->post_excerpt
A potentially cleaner way of doing this would be to create a new WP_Query that you can loop over. See http://codex.wordpress.org/The_Loop#Multiple_Loops

Echo short description for related products

Is there a way to echo the short description foreach related product?
I've tried to use this code but it doesn't display the description of each product:
<?php echo nl2br($this->getProduct()->getDescription()) ?>
also
<?php echo $_helper->productAttribute($_item, nl2br($_item->getShortDescription()), 'short_description') ?>
Is there a way to do this for related products? If anyone knows please point me in the right direction.
<?php if($this->getItems()->getSize()): ?>
<div class="block block-related">
<div class="block-title">
<strong><span><?php echo $this->__('Related Products') ?></span></strong>
</div>
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Check items to add to the cart or add to your wishlist') ?> <br /></p>
<div class="form-horizontal">
<?php foreach($this->getItems() as $_item): ?>
<div class="control-group">
<label for="related-checkbox<?php echo $_item->getId() ?>" class="control-label">
<a class="fancybox static-thumbs pull-left" href="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(500, 450); ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(135, 135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
</label>
<div class="controls">
<label class="checkbox">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
<?php endif; ?>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<span class="icon-check"></span>
<p class="product-name span6">
<?php echo $this->htmlEscape($_item->getName()) ?>
<br />
<?php echo nl2br($this->getProduct($_item)->getDescription()) ?>
</p>
<form action="<?php echo $this->getAddToCartUrl($_item) ?>" method="post">
<fieldset>
<label class="product-name"><?php echo $this->__('Quantity:'); ?></label>
<select name="qty" class="span1">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getMaxSaleQty()) ?>
</select>
<div class="clearfix"></div>
<button class="btn btn-danger" data-loading-text="PLease wait..."><span><?php echo $this->__('Add to Cart') ?></span></button>
<span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
</fieldset>
</form>
<?php endif; ?>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
</label>
</div>
</div>
<hr />
<?php endforeach ?>
</div>
</div>
Have you tried nl2br($this->getProduct($_item)->getShortDescription()) ?
It might be that the value for short description isn't loaded for related products by default. You could try to do a $_item->load($_item->getId()) and then use $_item->getShortDescription().
after TRYING $_item->load($_item->getId()) and echoing the shortDescription, you should look for the Collection where the related products are loaded. In this collection the attribute short_description is not loaded with.
If you load every product, you make a lot of queries to the database which will cost a lot of performance. This is not needed. The alternative is:
$relatedProductCollection->addAttributeToSelect('short_description');
The question is to find the $relatedProductCollection.
UPDATE:
I dug into the code (Reference is v. 1.7.0.2):
// app/code/core/Mage/Catalog/Block/Product/List/Related.php:61
$this->_addProductAttributesAndPrices($this->_itemCollection);
// app/code/core/Mage/Catalog/Block/Product/Abstract.php:410
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
// app/code/core/Mage/Catalog/Model/Config.php:260
$this->getAttributesUsedInProductListing()
This should be interpreted as: When the "related products" are loaded, all attributes are loaded, which are used in the product listing as well. The problem might be: short_desciption is loaded by default. So remove the load() call and check, wether the attribute short_description is "Used in Product Listing". If this is set to yes, My interpretation is wrong.
None the less, the solution by loading every product is crap.
EDIT:
I have added the following line to Related.php
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToSelect('short_description')
->setPositionOrder()
->addStoreFilter()
And using this line does echo a descrtiption foreach product but it is the Same description getProduct()->getDescription()) ?>
You need to <?php echo ($this->getProduct()->getShortDescription()) ?>
But editing the core code is a bad way to change the magento behaviour as well. Here is described how to rewrite a block, but I don't think this is necessary. http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/

Using a PHP foreach - how to create individual divs per each row?

I have a query that selects all the information from a database table and puts it into an array. I then use a PHP foreach statement to display all that in a uniform manner. It's the left table here to get a sense of what I'm talking about.
What I want to do is to make one of the divs (it normally just appears repeatedly under the same name) to have a unique name for each sumbission row. For example, instead of the "response" divs all just being called response, they are "response1", "response2", and so on. Is there any way to do this? (code below)
Any help would be greatly appreciated.
Here's where I call the info from the query:
<?php foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php } ?>
You can do this by two ways I will show you now
1- add the row id if exists to the id value or any unique column
<div id="response<?php echo $image['id']; ?>">
<?php echo $image['rating'];?>
</div>
2- make a counter
<?php
$i= 1;
foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response<?php echo $i; ?>">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php
$i++; //increment the $i each iteration
} ?>
<?php $i = 1; foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response<?php echo $i; ?>">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php $i ++; } ?>
Notice the $i = 1 before the foreach as well as the $i ++ before the closing }. Also, echo $i in the response div id.

Categories