How To paste result From PDO query into Paginate? - pdo

I have a good result using PDO query retrieve all data from database.
But, this only display the result with LIMIT like 10.
My questions now is how to paste this result for paginate?
I want to set result for 10 perpage and have prev 1 2 3 4 next for all data.
below script is good and fast result for me.
<?php
//load database connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
$search=$_POST['search'];
$query = $pdo->prepare("select * from table where colum1 LIKE '%$search%' OR colum2 LIKE '%$search%' LIMIT 0 , 10");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
// Display search result
if (!$query->rowCount() == 0) {
echo "Search found :<br/>";
echo "<table style=\"font-family:arial;color:#333333;\">";
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Title Books</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Author</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>";
while ($results = $query->fetch()) {
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['name'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['description'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo "$".$results['thumb'];
echo "</td></tr>";
}
echo "</table>";
} else {
echo 'Nothing found';
}
?>

I would suggest that you create a class for pagination then include the class.
pagination.php
<?php
class paginate
{
private $pdo;
function __construct($pdo)
{
$this->db = $pdo;
}
public function dataview($query,$Search)
{
$stmt = $this->db->prepare($query);
$stmt->execute(arary($Search,$Search));
$results = $stmt->fetchall();
if (count($results) > 0) {?>
Search found : <br/>
<table style="font-family:arial;color:#333333;">";
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Title Books</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Author</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>
<?php
foreach ($results as $row):
?>
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['name'];?></td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">;
<?php echo $row['description'];?>
</td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['thumb'];?>
</td></tr>
<?php
endforeach;
echo "</table>";
} else {
echo "<p> Nothing found </p>";
}
}
public function paging($query, $records_per_page)
{
$starting_position = 0;
if (isset($_GET['page_no'])) {
$starting_position = ($_GET["page_no"] - 1) * $records_per_page;
}
$query2 = $query . " limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query, $records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if ($total_no_of_records > 0) {
?>
<ul class="pagination"><?php
$total_no_of_pages = ceil($total_no_of_records / $records_per_page);
$current_page = 1;
if (isset($_GET["page_no"])) {
$current_page = $_GET["page_no"];
}
if ($current_page != 1) {
$previous = $current_page - 1;
echo "<li><a href='" . $self . "?page_no=1' >First</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $previous . "'>Previous</a></li>";
}
for ($i = 1; $i <= $total_no_of_pages; $i++) {
if ($i == $current_page) {
echo "<li class='active'><a href='" . $self . "?page_no=" . $i . "' >" . $i . "</a></li>";
} else {
echo "<li><a href='" . $self . "?page_no=" . $i . "'>" . $i . "</a></li>";
}
}
if ($current_page != $total_no_of_pages) {
$next = $current_page + 1;
echo "<li><a href='" . $self . "?page_no=" . $next . "'>Next</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $total_no_of_pages . "'>Last</a></li>";
}
?></ul>
<?php
}
}
}
?>
page.php
<?php
//your connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
include_once'pagination.php';
$paginate = new paginate($pdo);
$search=$_POST['search'];
$Search = "%$search%";
$query = "SELECT * from table where colum1 LIKE ? OR colum2 LIKE ? ";
$records_per_page=10;
$newquery = $paginate->paging($query,$records_per_page,$Search);
$paginate->dataview($newquery,$Search);
$paginate->paginglink($query,$records_per_page);
?>
This should work. Suggestions/comments are welcome.
This is one of the projects I have used the above code to do a pagination :
or use jquery dataTables which will also work perfect
all u need is to download https://datatables.net/
With Datatables, simple download it then add required scripts and css, then on your table add an ID, then initialize datatable
$('#TableID').dataTable();
You might have to do the proper table markup,
<table>
<thead>
<tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
</tr>
</tbody>

Related

display dynamic data in multiple columns

I use an html string in php to display sql query results in a single column:
How can I use multiple columns to lay it out like this:
while($row = mysqli_fetch_array($q)){
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<a href="' . $link . '">
<h3>' . $title . '</h3>
<p>' . $desc . '</p>
</a>';
}
Credit to hungrykoala for help on this one
$i = 0 ;
$resultsPerRow = 2 ;
$output = '<tr>';
while($row = mysqli_fetch_array($q)){
$i++;
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<td>' .$title. '<br>' .$desc. '</td>';
if ($i % $resultsPerRow == 0) {
$output .= '</tr><td><br></td><tr>';
}
}
echo($output);
Then output to a table tag

Open Cart SEO URL for category/manufacturer

OC 1.5.6
I've installed a module to filter products in categories based on manufacturer.
I'm able to reach every "search result page" at an url like:
example.com/index.php?route=product/category&path=X&manufacturer=Y
I'd like to create a SEO url like:
example.com/alias-for-category/alias-for-manufacturer
(ex. /bikes/honda or /cars/bmw)
but I can't figure out how to do it.
I've tried for testing and simplifying to convert just a single url:
product/category&path=1&manufacturer=1
so I added to url_alias a record with this query and keyword
cat1-man1
then I modified catalog/common/seo_url.php
function Index
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/info';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
//ADDED BELOW CODE TO ROUTE ALL URL
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($this->request->get['_route_']) . "'");
if ($query->num_rows) {
$this->request->get['route'] = $query->row['query'];
}
}
and function rewrite
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
}
unset($data[$key]);
}
//ADDED CODE BELOW TO CONVERT ALL URL
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
}
but also this simplified version doesn't work at all, page not found is shown.
What I'm doing wrong? Any tip will be really appreciated
First of all the custom module I've installed expects the parameter for manufacturer as "manufacturer" instead of "manufacturer_id" so a converted URL like :
example.com/index.php?route=product/category&path=X&manufacturer_id=Y
isn't handled correctly by the module.
So the answer to my question is : OC does already convert alias-cat/alias-manufacturer to a correct internal URL
On the other hand OC does not convert URL of the type
example.com/index.php?route=product/category&path=X&manufacturer_id=Y
into SEO friendly URL like:
example.com/alias-for-category/alias-for-manufacturer
in the menus or links, to do this, modify catalog/common/seo_url.php like this:
public function rewrite($link) {
$url_info = parse_url(str_replace('&', '&', $link));
$url = '';
$data = array();
parse_str($url_info['query'], $data);
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
}
unset($data[$key]);
}
// ADD THIS CODE
elseif ($key == 'manufacturer_id') {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'manufacturer_id=" . (int)$value . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
unset($data[$key]);
}
// END ADDED CODE----------------
else {
.....

Can't connect to SOAP web service (WSDL) with php

I have a username and password, yet trying to send a request to SOAP web server via WSDL while using Authentication, it gives an error Username was not specified.
What am I doing wrong? Thanks in advance
<?php
require_once('lib/nusoap.php');
$username = 'user';
$password = 'pass';
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
//echo 'You must set your username and password in the source';
//exit();
$client = new nusoap_client("example.com:88/Service.asmx?wsdl", 'wsdl',
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$client->setUseCurl($useCURL);
$client->loadWSDL();
$client->setCredentials($username, $password, 'digest');
$result = $client->call('GetValidTourList', array());
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

Illegal String Offset within PDO For Each loop

PHP Query:
<?php
$query = $db->prepare('SELECT * FROM Locations WHERE user_id = :id LIMIT 0, 5');
$query->bindParam(":id",$id);
$result = $query->execute();
$rows = $query->fetch();
foreach ($rows as $row) {
echo $row["timestamp"]; "<br />";
}
?>
The two rows that should be printed (timestamp):
What actually prints:
1188((22
The error within the console:
PHP Warning: Illegal string offset 'timestamp' in /Sites/pages/user_account.php on line 73 - Line 73 being the echo $row... inside the forloop.
Any help would be greatly appreciated.
You are using fetch, which retrieves a single row, instead of fetchAll:
$rows = $query->fetchAll();
You have two rows (user_id = 8)
$rows = $query->fetchAll();
For all rows
foreach ($rows as $row) {
echo $row . "<br />";
}
For 1 row , all column
while ($row = $rows) {
foreach ($row as $column) {
echo $column . "<br />";
}
}

Magento Tier Sales Prices?

I've been trying to mirror some functionality
in Magento (v1.6) as seen on another website. In the example, the
store owner has set up the ability to apply sales prices to a tier.
(most likely tierprices.phtml as the wrapper) by applying a sales price
(most likely in admin / product / price sales)
I've been working on figuring out exactly how it is done, but haven't
made any headway on it insofar. Does anyone have any idea how this was
constructed?
Here's the example website
http://www.epromos.com/product/2801001.html
Here's the Table code:
if($_tierPrices) {
echo '<style>
.strikeRow {text-decoration: line-through;}
.saleRow td {color:red;}
.quantityRow {background: #eef}
td {padding:3px 9px; border: 1px solid #fc0;}
</style>'; // temporary styling
$q = "<td>Quantity</td>";
$p = "<td>{$_product->getName()}</td>";
$s = "<td>Reduced Price</td>";
foreach ($_tierPrices as &$tier) {
#$tier['tier_sale'] = '0.00'; // trick the dump into thinking there is a product sale
if($tier['price_qty']) { $q .= "<td>{$tier['price_qty']}</td>"; }
if($tier['price']) { $p .= "<td>".number_format($tier['price'], 2, '.', '')."</td>"; }
if($tier['tier_sale']) { $s .= "<td>{$tier['tier_sale']}</td>"; }
}
$q = "<tr class='quantityRow'>{$q}</tr>";
$p = ($_tierPrices[0]['tier_sale'])? "<tr class='strikeRow'>{$p}</tr>" : "<tr>{$p}</tr>";
$s = ($_tierPrices[0]['tier_sale'])? "<tr class='saleRow'>{$s}</tr>" : '';
echo "<tbody>$q $p $s</tbody></table>";
}
And the full source:
<?php
/**
* #see Mage_Catalog_Block_Product_View
*/
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);
/** #var $_catalogHelper Mage_Catalog_Helper_Data */
$_catalogHelper = Mage::helper('catalog');
$_weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($_product);
if (Mage::helper('weee')->typeOfDisplay($_product, array(1,2,4))) {
$_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product);
}
if (count($_tierPrices) > 0) {
// start table group with class type if (obj)getInGrouped() == 1
echo ($this->getInGrouped()) ? '<table class="tier-prices-grouped product-pricing-grouped">' : '<table class="tier-prices product-pricing">';
// assign tier pricing to $_tierPrices
if ($this->getInGrouped()) {
$_tierPrices = $this->getTierPrices($_product);
}
Mage::helper('weee')->processTierPrices($_product, $_tierPrices);
foreach ($_tierPrices as $_price) {
echo '<tr>';
if ($_catalogHelper->canApplyMsrp($_product)) {
if ($this->getInGrouped()) {
echo $this->__('Buy %1$s for', $_price['price_qty']) .':';
} else {
echo $this->__('Buy %1$s', $_price['price_qty']);
}
} else {
if ($this->helper('tax')->displayBothPrices()) {
if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
echo $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price_incl_weee_only'], $_price['formated_price_incl_weee']);
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
if ($_weeeTaxAttributes) {
echo '(<small>';
echo $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);
$separator = ' + ';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
if ($_weeeTaxAttributes) {
echo '(<small>';
echo $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);
$separator = ' + ';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);
if ($_weeeTaxAttributes) {
echo '(<small>';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());
}
echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
echo '</small>)';
}
echo $this->__('each');
} else {
echo $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price'], $_price['formated_price_incl_tax']);
}
} else {
if ($this->helper('tax')->displayPriceIncludingTax()) {
if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee']);
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);
if ($_weeeTaxAttributes) {
echo '(<small>';
$separator = '';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());
$separator = ' + ';
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);
if ($_weeeTaxAttributes) {
echo '(<small>';
$separator = '';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());
$separator = ' + ';
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_tax']);
if ($_weeeTaxAttributes) {
echo '(<small>';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());
}
echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
echo '</small>)';
}
echo $this->__('each');
} else {
echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_tax']);
}
} else {
if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
if ($_weeeTaxAttributes) {
echo '(<small>';
$separator = '';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount());
$separator = ' + ';
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
if ($_weeeTaxAttributes) {
echo '(<small>';
$separator = '';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $separator;
echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());
$separator = ' + ';
}
echo '</small>)';
}
echo $this->__('each');
} elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {
echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);
if ($_weeeTaxAttributes) {
echo '(<small>';
foreach ($_weeeTaxAttributes as $_attribute) {
echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount());
}
echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee_only']);
echo '</small>)';
}
echo $this->__('each');
} else {
// concern
//echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price']);
$priceSchema['quantity'][] = $_price['price_qty'];
$priceSchema['formated_price'][] = $_price['formated_price'];
}
}
}
} // Can apply MSRP
if (!$this->getInGrouped()) {
// we need this ~
// funky ass OR switch, can i rework this in a saner way?
if( ($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
|| ($_product->getPrice() != $_product->getFinalPrice() && $_product->getFinalPrice() > $_price['price']) ) {
// echo ' '. $this->__('and') .' <strong class="benefit">'. $this->__('save') .' '. $_price['savePercent'] .'%';
}
// echo '</strong>'; // why the hell isn't this in the OR switch???
// we need this ~
}
if ($_catalogHelper->isShowPriceOnGesture($_product)) {
$popupId = 'msrp-popup-' . $_product->getId() . $this->helper('core')->getRandomString(20);
echo ''. $this->__('Click for price') .'';
echo '<script type="text/javascript">';
if (!$this->getInGrouped()) {
echo 'var newLink = {';
echo 'url: "'. $this->getAddToCartUrl($_product, array('qty' => $_price['price_qty'])) .'",';
echo 'qty: "'. $_price['price_qty'] .'"';
echo '};';
} else {
echo 'var newLink = {';
echo 'url: "'. $this->getAddToCartUrl($_product, array('qty' => $_price['price_qty'])) .'",';
echo 'notUseForm: true';
echo '};';
}
echo 'Catalog.Map.addHelpLink(';
echo "$('{$popupId}'),";
echo '"'. $_product->getName() .'",';
echo json_encode($_price['real_price_html']) .',';
echo '"'. $this->helper('core')->currency($_product->getMsrp(),true,false) .'",';
echo 'newLink';
echo ');';
echo '</script>';
} else {
echo '<span class="msrp-price-hide-message">'. $_catalogHelper->getMsrpPriceMessage($_product) .'</span>';
}
}
}
if($_tierPrices) {
echo '<style>
.strikeRow {text-decoration: line-through;}
.saleRow td {color:red;}
.quantityRow {background: #eef}
td {padding:3px 9px; border: 1px solid #fc0;}
</style>'; // temporary styling
$q = "<td>Quantity</td>";
$p = "<td>{$_product->getName()}</td>";
$s = "<td>Reduced Price</td>";
foreach ($_tierPrices as &$tier) {
#$tier['tier_sale'] = '0.00'; // trick the dump into thinking there is a product sale
if($tier['price_qty']) { $q .= "<td>{$tier['price_qty']}</td>"; }
if($tier['price']) { $p .= "<td>".number_format($tier['price'], 2, '.', '')."</td>"; }
if($tier['tier_sale']) { $s .= "<td>{$tier['tier_sale']}</td>"; }
}
$q = "<tr class='quantityRow'>{$q}</tr>";
$p = ($_tierPrices[0]['tier_sale'])? "<tr class='strikeRow'>{$p}</tr>" : "<tr>{$p}</tr>";
$s = ($_tierPrices[0]['tier_sale'])? "<tr class='saleRow'>{$s}</tr>" : '';
echo "<tbody>$q $p $s</tbody></table>";
}
?>
I am pretty sure what you are looking for is absolute pricing for options regardless of tier, if so here is the link to how this could be accomplished:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/use-absolute-price-for-custom-options
Here is quick solution for you.
You can use a 'cost' field of the product to define the percentage by which the retail price is higher then your price. By default 'cost' field is used as a memo of how much you paid for the product and is not used anywhere at the front-end.
Then go to templates/template/catalog/product/view/tierprices.phtml of your theme and add the following lines after $_product = $this->getProduct(); line:
$multiplier = $_product->getData('cost');
$multiplier = $multiplier ? $multiplier : 1;
And the following line between <?php endif; ?> and <?php if (!$this->getInGrouped()): ?>:
Retail price: <?php echo $_coreHelper->currency($_price['price']*$multiplier, true, false) ?>
I'm sure you will be able to style it as you wish. Please let me know if something is unclear.