I use Iptrack extension in Magento. Based on IP detection the following specifications will be shown for a product (if applicable);
Specifications - it is attribute for product.
if IP is from the UK or US and language is English :
Show all I- and G-specifications
other IP's and languages :
Show all M- and G-specifications
This is where attributes come: attributes.phtml:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
dumping $_data inside foreach give me like
array(3) { ["label"]=> string(19) "Diameter D (inches)" ["value"]=> string(7) "2 11/16" ["code"]=> string(4) "i062" } Diameter D (inches)
for one loop.
Maybe someone got the same problem? Thank you.
If I understand you correctly, you can achieve what you want by something like this:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
function isAllowedAttribute($aData)
{
$bIpCheck = (bool) preg_match('/^[igm]{1}[0-9]{3}$/', $aData['code']);
if (!$bIpCheck) {
return true;
}
if (isIpFromUkOrUsAndLanguageEnglish()) {
return (bool) preg_match('/^[ig]{1}[0-9]{3}$/', $aData['code']);
}
else {
return (bool) preg_match('/^[mg]{1}[0-9]{3}$/', $aData['code']);
}
}
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php if (isAllowedAttribute($_data)): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
I don't know this IP track extension you use at all, so I simply used a dummy call to a non-existing function named isIpFromUkOrUsAndLanguageEnglish().
You only need to replace this by the proper IP track extension call(s).
Related
I want to add some styling to the product additional information table.
To do so, i have added the product attribute label to the standard table layout file located in:
app/design/frontend/my_theme/template/catalog/product/view/attributes.phtml
<?php foreach ($_additional as $_data): ?>
<?php $lbl = $this->escapeHtml($this->__($_data['label']))?>
<tr class="<?php echo strtolower(str_replace(' ', '_', $lbl)) ?>">
<th class="label"><?php echo $this->escapeHtml($_data['label']) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
the problem with this is that te label gets translated to the store language. Is there a way to force the label to always display in English?
Much appreciated!
I think you're better off using the attribute code instead of the attribute label if you just need an identifier. The attribute code is universal across all storeviews.
<?php foreach ($_additional as $_data): ?>
<?php $code = $this->escapeHtml($this->__($_data['code']))?>
<tr class="<?php echo $code; ?>">
<th class="label"><?php echo $this->escapeHtml($_data['label']) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
You should remove $this->__() from string
<?php foreach ($_additional as $_data): ?>
<?php $lbl = $this->escapeHtml($this->__($_data['label']))?>
<tr class="<?php echo strtolower(str_replace(' ', '_', $lbl)) ?>">
<th class="label"><?php echo $this->escapeHtml($_data['label']) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
we can see "Additional information " tab in magento product view page.
there we can list all attributes.
I want to display some contents under "Additional information " tab....
means
Main information
attribute label 1 : attribute value
Sub - information
attribute label 2 : atribute value.
please let me know if you need any clarifications.
thanks in advance.
As answered on Magento SE:
You could customize the template
catalog/product/view/attributes.phtml. Copy it to your theme from
base/default if it isn't there yet and include what you need.
For better maintainability, I'd recommend to just add
$this->getChildHtml('my_child_alias') to the template and define
child blocks in the layout (i.e. layout/local.xml of your theme:
<reference name="product.attributes">
<block type="core/template" name="my.custom.product.block" as="my_child_alias" template="my/custom/template.phtml" />
</reference>
Judging by the additional information from your comments here, you probably don't want to create child blocks, instead you'll have to add code within the foreach loop.
Original
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
Changed (example)
<?php foreach ($_additional as $_data): ?>
<?php if ($_data['code'] == 'attribute_1'): ?>
<tr><th colspan="2"><?php echo $this->__('Main Information') ?></th></tr>
<?php elseif ($_data['code'] == 'attribute_2'): ?>
<tr><th colspan="2"><?php echo $this->__('Sub Information') ?></th></tr>
<?php endif; ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
where attribute_1 and attribute_2 are the codes of the first attributes of each group.
Modify File : catalog\product\view\attributes.phtml.
Replace <th></th> by this code.
<th class="label">
<?php if(array_key_exists('size',$_additional) && array_key_exists('color',$_additional) ){
if($_data['code'] == 'size'){
echo " Main features : ";
}
} ?>
<?php echo $this->escapeHtml($this->__($_data['label'])) ?>
</th>
Apply this code and check out put.
I have added configurable product and added textarea attribute to it, I want to show the attributes at front end in my custon view, how can I show ?
you can use this code
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label">
<?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data">
<?php echo $_helper->productAttribute($_product, $_data['value'],
$_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
Catalog -> Attribute -> Manage Attribute -> Select your attribute -> Visible on Product View Page on Front-end -> Select "YES"
Does this solve your problem?
Magento has done great job on showing empty attributes as "No" or "N/A", but
I need them to show up as empty table cells.
I know this code hides empty attributes completely:
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
Source: http://www.magthemes.com/magento-blog/empty-attributes-showing-na-fix/
but as I am new to php, I don't really know how to modify it to show them empty.
I know I could go to core files and modify Attributes.php, but thats a bad practice and I wanted to do it right.
Thanks in advance!
You can write a extension thar rewrites Mage_Catalog_Block_Product_View_Attributes::getAdditionalData. But this requires much more knowledge than is necessary to modify the template.
Modify template. Your code is already done. Only few modifications need
<?php foreach ($_additional as $_data): ?>
<?php
$_attribute = $_product->getResource()->getAttribute($_data['code']);
$_isEmpty = (!is_null($_product->getData($_attribute->getAttributeCode())) &&((string)$_attribute->getFrontend()->getValue($_product) != ''));
?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php if (!$_isEmpty) { echo $_helper->productAttribute($_product, $_data['value'], $_data['code'])} ?> </td>
</tr>
<?php endforeach; ?>
P.S. Code can contain errors, have not tested :)
ALT+0160
Use the above keyboard shortcut as the attribute value when you edit your product.
How?
On Windows, at least, do the following:
Hold ALT key and type the numbers 0160 on your keypad. Now release the ALT key.
Basically a whitespace character appears that is not a space character. This will register as a non-null value for your product field and the engine will render the character which, fortunately for us humans, is a whitespace that we won't see.
It's not elegant, but it will help those who aren't able to modify template code.
i try with this options to remove "No or N/A" and ok remove this words but don´t remove atribute name. i use this code:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="akordeon-item-head">
<div class="akordeon-item-head-container">
<div class="akordeon-heading">
<?php echo $this->__('Additional Information') ?>
</div>
</div>
</div>
<div class="akordeon-item-body">
<div class="akordeon-item-content">
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php
$_attribute = $_product->getResource()->getAttribute($_data['code']);
$_isEmpty = (!is_null($_product->getData($_attribute->getAttributeCode())) &&((string)$_attribute->getFrontend()->getValue($_product) != ''));?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php if ($_isEmpty) { echo $_helper->productAttribute($_product, $_data['value'], $_data['code']);} ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
</div>
</div>
<?php endif;?>
i find this anwerd and work for me
<?php foreach ($_additional as $_data): ?>
<?php if ($_data['value'] == 'No') {continue;} ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
I am trying to fetch data from my database and when I display it I want to show serial numbers (Just like a list) , example:
**Serial Number** Name Country
1. John USA
2. Srijon UK
I have tried something with PHP Loops, but I couldn't make it work. Would you please kindly help me? please note that by serial numbers I don't mean values retrieved from database.
Thanks in Advance :)
Here's my Model
//Function To Create All Batch List
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
//End of Function To Create All Batch List
Here's mY Controller
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page']
,$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
Here's My View
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Serial</th>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php $i = $this->uri->segment(3); foreach ($records as $row){ $i++; ?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
In my case the fourth and fifth parameters where page number and rows per page respectively
ie: example.com/category/page/1/10
first page with 10 rows per page.
so in this case just use this before the loop
$i = $this->uri->segment(4)? (
$this->uri->segment(4) + $this->uri->segment(5)? $this->uri->segment(5):0
)
:0;
and from inside the loop just increment the value of i.
foreach ($result_obj as $key => $value)
{
$i++;
...
}
Try this..work like this..1,2,3,4,5
$i = 0
while($condition)
{
echo '<td>'.$i++.'</td>';
}