Create a tier price table/grid in Magento frontend - magento

I am trying to figure out how to format the tier pricing in Magento products detail page into a grid/table format. For example, I would like to have a Quantity Row, Price row, and discount row. And it about 5 columns. Is this possible? We sell products in bulk, so this layout is important. That would be great if someone can point me in the right direct. I am new to magento and finding the customization side of things difficult to pick up.
Thanks!

I made the following template for my tierprices.phtml.
FYI I'm running Magento 1.8.x
<?php
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
if (count($_tierPrices) > 0):
$_data = array();
$_prevQty = 0;
$_counter = 0;
$_tierPrices = array_reverse($_tierPrices);
foreach ($_tierPrices as $_index => $_price){
$_counter++;
if($_price['price_qty']>$_prevQty){
if($_counter == 1){
$label = $_price['price_qty'] . '+';
} else {
$label = $this->__('%d or less',$_price['price_qty']);
}
$_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price']);
$_prevQty = $_price['price_qty'];
} else {
$label = $_price['price_qty'] . '-' . $_prevQty;
$_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price']);
$_prevQty = $_price['price_qty'];
}
}
$_data = array_reverse($_data);
?>
<table class="tiered-pricing">
<tbody>
<tr>
<th>Quantity</th>
<th>Price</th>
</tr>
<?php foreach ($_data as $_row): ?>
<tr>
<td><?php echo $_row['label']; ?></td>
<td><?php echo $_row['price']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
endif;
?>
It makes a table version of the tiered pricing data.

The following URL will be useful:
http://stackoverflow.com/questions/9257924/magento-tier-sales-prices
You can also modify the following template
magento/app/design/frontend/default/your_theme/template/catalog/product/view/tierprices.phtml
where you can loop through $_tierPrices array and generate html table element

Related

Codeigniter Get Nested Hierarchical Data from Database

How can i get Hierarchical Data from db in Codeigniter. I read this :
http://www.sitepoint.com/hierarchical-data-database/
And i do good that but i cant optimize this tutorial with my model, controler and views
Default Category
|----- Sub category
| ----One more category
|----- Somthing else
I try but dont show sub category:
My model:
public function fetchChildren($parent, $level) {
$this->handler = $this->db->query("SELECT * FROM content_categories WHERE parent_id='".$parent."' ");
foreach($this->handler->result() as $row ) {
$this->data[$row->id] = $row;
//echo str_repeat(' ',$level).$row['title']."\n";
}
return $this->data;
}
Controller :
$this->data['node'] = $this->categories_model->fetchChildren(' ',0);
Views:
<table class="module_table">
<thead>
<tr>
<th><?php echo lang('categories_table_title'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($node as $row) : ?>
<tr>
<th> <?php echo str_repeat('|----', 0+1). $row->title ?> </th>
</tr>
<?php endforeach; ?>
</tbody>
</table>
And output is :
----Default
----Default
----Test Category 1
----Seccond Test Category 1
----Another Test Category 1
When i do this in model all work fine but when i try that to call in controler and loop in view i have result like above example:
This work onlu in model:
public function fetchChildren($parent, $level) {
$this->handler = $this->db->query("SELECT * FROM content_categories WHERE parent_id='".$parent."' ");
foreach($this->handler->result() as $row ) {
echo str_repeat('|-----',$level).$row->title."\n";
$this->fetchChildren($row->title, $level+1);
}
return $this->data;
}
And like output i have :
Default
|----Test Category 1
|----Seccond Test Category 1
|----Another Test Category 1
Any one have solution or example thanks.
Try storing the level value for each category.
In your model:
public function fetchChildren($parent, $level){
$this->handler = $this->db->query("SELECT * FROM content_categories WHERE parent_id='".$parent."' ");
foreach($this->handler->result() as $row ) {
$row->level = $level;
$this->data[] = $row;
$this->fetchChildren($row->title, $level+1);
}
return $this->data;
}
In your controller:
$this->data['node'] = $this->categories_model->fetchChildren(' ',0);
In your view
<table class="module_table">
<thead>
<tr>
<th><?php echo lang('categories_table_title'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($node as $row) : ?>
<tr>
<th><?php echo str_repeat('|----', $row->level). $row->title ?> </th>
</tr>
<?php endforeach; ?>
</tbody>
</table>

how to use use advanced time calculations with codeigniter

I moved to codeigniter and before i did my sql query worked but now that im on a framework it doesnt. im trying to round time and here is my query:
SELECT
DATE_FORMAT(wo.dateCreated,'%m/%d/%Y # %h:%i %p') AS dateCreated
, wo.id
, sr.id AS srid
, ROUND((TIME_TO_SEC(sr.endtime) -
TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) AS totalHours
, ROUND((TIME_TO_SEC(sr.endtime) -
TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) - sr.deduction AS deductHours
, l.name AS locationName
, l.address
, l.zip
FROM company AS c
I shortened the query so it wouldnt be so long, bascially i just need to know how to properly do the ROUND part using codeigniter. Any help would be greatly appreciated!
EDIT:
I changed per your suggestion which gives me this:
public function get_sr($id) {
$this->db->select('
sr.id
,sr.woid
,sr.description
,sr.techId
,sr.startTime
,sr.endTime
,ROUND((TIME_TO_SEC(sr.endtime) - TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) AS totalHours
,u.first_name
,u.last_name
,rt.value AS rate
,wo.tid');
$this->db->from('service_report sr');
$this->db->join('work_orders wo','wo.id = sr.woid','left');
$this->db->join('enum_rate_type rt','rt.id = sr.rateType','left');
$this->db->join('users u','u.id = sr.techId','left');
$this->db->where('sr.woid', $id);
$query = $this->db->get();
return $query->result_array();
but now i get an error when calling it:
Fatal error: Call to a member function result_array() on a non-object
without the ROUND line, it displays fine.
here is my view:
<?php
$total = 0;
foreach ($srInfo as $row):
$total += $amount = $row['rate'] * $row['deductHours'];
?>
<tbody>
<!-- Cart item -->
<tr>
<td class="center"><?php echo $row['id']; ?></td>
<td>
<h5><?php echo $row['description']; ?></h5>
</td>
<td class="center"><?php echo $row['first_name']; ?> <?php echo $row['last_name']; ?></td>
<td class="center"><?php echo $row['deductHours']; ?></td>
<td class="center"><?php echo "$" . number_format($total, 2); ?></td>
</tr><!-- // Cart item END -->
<?php endforeach; ?>
</tbody>

Codeigniter Paginaton Next button is not working

I am trying to display information from database. I have set $config['per_page'] to 2, in my view file I can see the information I want but when I click on the next button it doesn't change anything. The database values remain same and the current page remains the first page too.
Would you please kindly help me figure out the problem?
Thanks in Advance :)
Controller:
function index($id){
$this->load->library('pagination');
$config['base_url'] = site_url().'Student_fee_status/index/'.$id;
$this->db->select('*');
$this->db->from('studentpayment1');
$this->db->where('studentid', $id);
$query = $this->db->get('');
$numrows=$query->num_rows();
$config['total_rows'] = $numrows;
$config['per_page'] = 2;
$config['uri_segment'] = '2';
$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_student_fee_status');
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
$data['main_content']='view_student_fee_status';
$this->load->view('includes/template',$data);
}
My Model :
function fee_status($id,$perPage,$uri_segment) {
$this->db->select('*');
$this->db->from('studentpayment1');
$this->db->where('studentid', $id);
$getData = $this->db->get('', $perPage, $uri_segment);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
EDIT
When the page first loads the link looks like this- http://localhost/sundial/Student_fee_status/index/1006/
but when I click on the next page it looks like this- http://localhost/sundial/Student_fee_status/index/1006/2
My View File:
<h1>Payment Status</h1>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>S.N</th>
<th>Invoice ID</th>
<th>Transaction Description</th>
<th>Received Date</th>
<th>Debit</th>
<th>Credit</th>
<th>Balance</th>
</tr>
</thead>
<?php $i = $this->uri->segment(2) + 0; foreach ($records as $row){ $i++; ?>
<tbody>
<?php
$mydate= $row['period'];
$month = date("F",strtotime($mydate));
$year = date("Y",strtotime($mydate));
?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['invoiceid'];?></td>
<td><a href="<?php echo base_url(); ?>student_fee_status/fee_types/<?php echo $row['paymentid']; ?>" rel="1" class="newWindow" >Total Fee For <?php echo $month ;?>, <?php echo $year ;?> </a></td>
<td><?php echo $row['received_date'];?></td>
<td><?php echo $row['totalamount'];?></td>
<td><?php echo "0";?></td>
<td><?php echo $row['totalamount'];?></td>
</tr>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['invoiceid'];?></td>
<td>Payment Received </td>
<td><?php echo $row['received_date'];?></td>
<td><?php echo "0";?></td>
<td><?php echo $row['amountpaid'];?></td>
<td>
<?php
$balance=$row['totalamount']-$row['amountpaid'];
if($balance>0){
echo "<font color=\"red\">$balance</font>";
}
else {
echo $balance;
}
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
You are telling the pagination library to use $config['uri_segment'] = '2'; - the second segment of your uri.
When this is your url: http://localhost/sundial/Student_fee_status/index/1006/ I am guessing this is your base_url: http://localhost/sundial/
In this case your segments are:
Student_fee_status - your controller
index - the controllers method you are calling
1006 - the argument you are calling the controllers method with
this should be the argument for pagination
Try this
$config['uri_segment'] = '4';
instead of
$config['uri_segment'] = '2';
edit:
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
I think this line contains another error.
You pass your model the information which uri_segment is used by the pagination library. That should be 4 now. However, your model uses this value to specify an offset in your query. This means you always put an offset of 4 into your query. But I think what you really want to do is, pass the model the VALUE of the 4th uri_segment.
I would try this instead:
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$this->uri->segment($config['uri_segment']));

How to display Attribute Group Name on Product page?

I created Attribute Sets with more Grouped attributes inside. In admin, the custom attributes are displayed in groups (tabs) like I created them. But, on the product page, all the attributes are listed together, without displaying the Attribute Group Name before listing the Attributes in that Group.
How can I display also the Attribute Group names, not only the attributes? If you could show me on the default template, I will do it accordingly in my custom template.
Thank you!
Ok, I found an answer and I hope it will be useful to others in search for the same thing.
First, I'm using Magento 1.5.0.
Second, I found the answer in German here, with an extension already created, but the installation failed.
So, I added /app/code/local/Mage/Catalog/Block/Product/View/Attributesgroups.php with the following code:
<?php
class Mage_Catalog_Block_Product_View_Attributesgroups extends Mage_Core_Block_Template
{
protected $_product = null;
function getProduct()
{
if (!$this->_product) {
$this->_product = Mage::registry('product');
}
return $this->_product;
}
public function getAdditionalData(array $excludeAttr = array())
{
$data = array();
$product = $this->getProduct();
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);
// TODO this is temporary skipping eco taxes
if (is_string($value)) {
if (strlen($value) && $product->hasData($attribute->getAttributeCode())) {
if ($attribute->getFrontendInput() == 'price') {
$value = Mage::app()->getStore()->convertPrice($value,true);
} elseif (!$attribute->getIsHtmlAllowedOnFront()) {
$value = $this->htmlEscape($value);
}
$group = 0;
if( $tmp = $attribute->getData('attribute_group_id') ) {
$group = $tmp;
}
$data[$group]['items'][ $attribute->getAttributeCode()] = array(
'label' => $attribute->getFrontend()->getLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
$data[$group]['attrid'] = $attribute->getId();
}
}
}
}
// Noch Titel lesen
foreach( $data AS $groupId => &$group ) {
$groupModel = Mage::getModel('eav/entity_attribute_group')->load( $groupId );
$group['title'] = $groupModel->getAttributeGroupName();
}
return $data;
}
}
Then, I created the /app/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/view/attributesgroups.phtml file with the following content:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additionalgroup = $this->getAdditionalData()): ?>
<div class="box-collateral box-additional">
<h2><?php echo $this->__('Additional Information') ?></h2>
<?php $i=0; foreach ($_additionalgroup as $_additional): $i++; ?>
<h3><?php echo $this->__( $_additional['title'] )?></h3>
<table class="data-table" id="product-attribute-specs-table-<?php echo $i?>">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional['items'] 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-<?php echo $i?>')</script>
<?php endforeach; ?>
</div>
<?php endif;?>
Last step was to modify /app/design/frontend/default/YOUR_TEMPLATE/layout/catalog.xml in line 223, and replaced
<block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml">
with
<block type="catalog/product_view_attributesgroups" name="product.attributes" as="additional" template="catalog/product/view/attributesgroups.phtml">
I repeat, this answer does NOT belong to me, I just translated what I found. Many thanks to the beautiful people who ended my three days of search with a clean and simple answer: WebGuys.DE
Also, thanks to #rpSetzer who cared to help!
Iterate through all the attributes and create an array of groups. In each group you put the attributes that belong to it. Then it's simple to display them the way you wanted.
Here is an implementation that is very close to what you need.
Thanks for translation : additionnal information for those who may need :
For 1st step, if the folder /app/code/local/Mage/Catalog/Block/Product/View/ doesn't exist, create it ! with correct persmissions and place the file Attributesgroups.php there
If you have different store views (for different languages), and you want to use correct translation for each attribute label, here is want you need to do :
In the file Attributesgroups.php
Replace 'label' => $attribute->getFrontend()->getLabel(), with'label' => $attribute->getStoreLabel(),

All Addtional Attributes for Grouped Products in Magento

Similar to the question asked at:
Magento - Show Custom Attributes in Grouped Product table
I'd like to display attributes of simple products in the grouped product page.
However, I need it to work such that you do not explicitly specify which attributes get displayed. Instead, it displays all the attributes that would get displayed on the simple product view of that product.
I've tried variations of:
(from /template/catalog/product/view/type/grouped.phtml)
<?php foreach ($_associatedProducts as $_item): ?>
<tr>
<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
<!-- important problem part -->
<?php foreach ($_item->getAttributes() as $arr): ?>
<td><?php echo $arr->getData() ?></td>
<?php endforeach; ?>
<!-- end of problem part -->
<td class="a-right">
<?php echo $this->getPriceHtml($_item, true) ?>
</td>
<?php if ($_product->isSaleable()): ?>
<td class="a-center">
<?php if ($_item->isSaleable()) : ?>
View
<?php else: ?>
<p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock.') ?></span></p>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
And other variations, however, I cannot limit the attributes being displayed to just the ones I need (i.e. just the additional attributes displayed on the simple product view; those set as Viewable on Frontend). Any ideas?
The class Mage_Catalog_Block_Product_View_Attributes method getAdditionalData() should point you toward how to limit the variables to only those that are selected as Viewable on Frontend. Its getAdditionalData method is referenced in the product view block.
The steps to solving this would be the following:
1. Create a new Magento module with the intent to override the grouped product block.
2. Create the new grouped product block, stealing liberally from the getAdditionalData() method of Mage_Catalog_Block_Product_View_Attributes.
3. Create a new template based on /template/catalog/product/view/type/grouped.phtml to back your custom block.
4. Override the block in your module's config.xml (see: Overriding catalog/breadcrumbs and catalog/products/view, Magento forums)
This has the consequence that all your grouped products in the catalog will behave this way. If you need to be more selective, then I think a reasonable thing to do would be to add a custom attribute to catalog products (preferably set up in the custom module you just created!) in order to toggle the behavior, and program a check for that toggle into your template.
Add after $_product = $this->getProduct();
/* CODE TO GET ATTRIBUTES */
$gridattributes = array();
$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($_product);
if (!$_product->hasData($attribute->getAttributeCode())) {
$value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
$value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = Mage::app()->getStore()->convertPrice($value, true);
}
if (is_string($value) && strlen($value)) {
$gridattributes[$attribute->getAttributeCode()] = array(
'label' => $attribute->getStoreLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
}
}
}
?>
Add after <th><?php echo $this->__('Product Name') ?></th>:
foreach($gridattributes as $attrib){
echo '<th>'.$this->htmlEscape($attrib[label]).'</th>';
}
Add after <td><?php echo $this->htmlEscape($_item->getName()) ?></td>:
foreach($gridattributes as $attribname=>$attribval){
echo '<td>'.$this->htmlEscape($_item->getData($attribname)).'</td>';
}

Resources