Page 1 of 1
A few questions...
Posted: Thu Feb 21, 2008 10:35 am
by OneBadFlower
I've got a few things i've not been able to figure out myself. if anyone can help and point me in the right direction on these i would really appreciate it.
- Reports: Products Viewed: anyone know if it's possible to reset this report view?
- Newsletter: Legally in the US you have to offer a way to opt-out of a newsletter. I'm trying to add a standard footer that would automatically insert that in every email but can't find where to do that (can't trust client to do this themselves) anyone have a suggestion?
- product gallery view: If you wanted to sort this by PRICE where would that be done?
THANKS
Re: A few questions...
Posted: Tue Feb 26, 2008 7:25 am
by bruce
I am not sure where you mean by product gallery. There are two locations where products can be displayed. First on the home page, and second when navigating through the categories.
In the first case, the file to modify is \catalog\controller\home.php and you can change the order by clause in the following sql statement.
Code: Select all
$results = $database->getRows("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '" . (int)$language->getId() . "' and p.date_available < now() and p.status = '1' order by p.date_added limit 6");
In the second case, the file to modify is \catalog\controller\category.php. I have shown an excerpt of the code so you will know where to go.
You have two choices to sort by price. You can either modify the order by in the sql statement or you can do an array sort on $results.
Code: Select all
$view->set('categories', $category_data);
$product_data = array();
$results = $database->getRows($database->splitQuery("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join product_to_category p2c on (p.product_id = p2c.product_id) left join image i on (p.image_id = i.image_id) where status = '1' and language_id = '" . (int)$language->getId() . "' and p2c.category_id = '" . (int)end(explode('_', $request->get('path'))) . "' and p.date_available < now() and p.status = '1' order by p.sort_order, pd.name", ($request->has('path') ? $session->get('category.' . $request->get('path') . '.page') : $session->get('category.page')), $config->get('config_max_rows')));
foreach ($results as $result) {
$query = array(
'path' => $request->get('path'),
'product_id' => $result['product_id']
);
$product_data[] = array(
'name' => $result['name'],
'href' => $url->href('product', FALSE, $query),
'thumb' => $image->resize($result['filename'], $config->get('config_image_width'), $config->get('config_image_height')),
'price' => $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $config->get('config_tax')))
);
}
$view->set('products', $product_data);
Re: A few questions...
Posted: Tue Feb 26, 2008 7:32 am
by bruce
Emails are created using templates. There is one in \admin\template\default\content\email.tpl
Do a search for Mail over your test site in all files *.php because some emails are sent from the catalog too.
That will find them all. Then you can work out when they are used and which one in which to put your opt out instructions
Re: A few questions...
Posted: Tue Feb 26, 2008 7:44 am
by bruce
Products Viewed. By reset, I presume you want to set the viewed count back to zero for all products?
You can only do this in sql but could add a button somewhere in the administration section to perform this task.
Having done that, the report will break in its current form. You need to also make the following change in the file \admin\controller\report_viewed.php
Some surrounding code is shown so that you know where to put the change.
Code: Select all
$total = 0;
foreach ($results as $result) {
$total += $result['viewed'];
}
// added the following to handle viewed = 0
if ($total == 0)
$total = 1;
foreach ($results as $result) {
$product_data[] = array(
'name' => $result['name'],
'viewed' => $result['viewed'],
'percent' => round(($result['viewed'] / $total) * 100, 2) . '%'
);
}
$view->set('products', $product_data);
Re: A few questions...
Posted: Thu Mar 06, 2008 2:33 am
by OneBadFlower
Bruce,
thanks for the assist here. it's helping a lot.
Still stuck on sorting by price.
here's an example of the page i'm trying to modify:
http://onebadflower.com/work/2007/nbk/i ... ry&path=21
you will see the products are listed from lowest price to highest.
i want to reverse that.
anyone? Thanks.
Re: A few questions...
Posted: Thu Mar 06, 2008 8:33 am
by bruce
Actually, they appear to be random wrt price.
In the code extract shown previously, you would have to change
order by p.sort_order,
to, instead
order by p.price desc,
Re: A few questions...
Posted: Thu Mar 06, 2008 10:46 am
by OneBadFlower
ok bruce,
First of all... THANKS for the help. You are saving me here.
Secondly, since you seem to be the wiz at this.
I have tried and tried to get the navigation (dropdown that states you are on page 1 of 3) at the bottom of the page as well as at the top of the page.
Any thoughts on how to make that tweak?
Bonus Question:
How would one kill the dropdown and have it look more like this:
Page: 1 | 2 | 3 | 4
Re: A few questions...
Posted: Thu Mar 06, 2008 12:01 pm
by bruce
I have to do this for a customer some time soon so will let you know how I go.
As for the bonus question, the drop down is the best navigation mechanism if you have more than about 10 pages.
But All you have to do is have an onclick javascript event fired from each of the numbered links that does the same as the onchange (or onclick) of the dropdown.
and...
Format the "current" page link differently using the same info that the dropdown uses to set its "current" page.
Re: A few questions...
Posted: Thu Mar 06, 2008 12:57 pm
by OneBadFlower
MAN i came close.
i tried this code with a little css:
Code: Select all
<?php foreach ($pages as $pages) { ?>
<?php if ($pages['value'] == $page) { ?>
<span class="navCurrent"><?php echo $pages['value']; ?></span>
<?php } else { ?>
<a href="index.php?controller=category&action=page=<?php echo $pages['value']; ?>&path=21"><?php echo $pages['value']; ?></a>
<?php } ?>
<?php } ?> <?php echo $text_results; ?> </div>
however it wasn't returning the right URL to go to next page.
first of all i have the path id hardcoded and if i didn't have issue 2, i can't swap categories.(need to figure how to get that inserted)
secondly, well... i have no clue why else it didn't work.
it would return a url like:
http://onebadflower.com/work/2007/nbk/i ... =2&path=21
and go nowhere. thinking it has to do with the page=2 portion.
the reason i was going for this approach is i'll never have more than 6 pages per category. Dropdown is a little overkill for this instance.
Re: A few questions...
Posted: Thu Mar 06, 2008 5:14 pm
by bruce
Here is the dropdown at the bottom of the page. I had to rename a variable in the php code in the template so I have posted the entire file. \catalog\template\default\content\category.tpl
Code: Select all
<div class="heading"><?php echo $heading_title; ?></div>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<div class="categories"><a href="<?php echo $category['href']; ?>"></a><br />
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></div>
<?php } ?>
<?php } ?>
<?php if ($products) { ?>
<?php if ($categories) { ?>
<div class="heading"><?php echo $text_product; ?></div>
<?php } ?>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<select name="page" onchange="this.form.submit();">
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<option value="<?php echo $p['value']; ?>" SELECTED><?php echo $p['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $p['value']; ?>"><?php echo $p['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</form>
</div>
</div>
<?php foreach ($products as $product) { ?>
<div class="products"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a><br />
<b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b><br />
<?php echo $product['price']; ?></div>
<?php } ?>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<select name="page" onchange="this.form.submit();">
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<option value="<?php echo $p['value']; ?>" SELECTED><?php echo $p['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $p['value']; ?>"><?php echo $p['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</form>
</div>
</div>
<?php } ?>
Re: A few questions...
Posted: Thu Mar 06, 2008 7:57 pm
by bruce
Here is the answer to the bonus question
It is the same template file as before with both dropdown and numbers functioning together.
I leave it to you to make it pretty.
Code: Select all
<script type="text/javascript">
<!--
function doSubmit(page_no)
{
document.freddo.page_link.value = page_no;
document.freddo.submit();
}
-->
</script>
<div class="heading"><?php echo $heading_title; ?></div>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<div class="categories"><a href="<?php echo $category['href']; ?>"></a><br />
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></div>
<?php } ?>
<?php } ?>
<?php if ($products) { ?>
<?php if ($categories) { ?>
<div class="heading"><?php echo $text_product; ?></div>
<?php } ?>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<select name="page" onchange="this.form.submit();">
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<option value="<?php echo $p['value']; ?>" SELECTED><?php echo $p['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $p['value']; ?>"><?php echo $p['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</form>
</div>
</div>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);" style="font-weight: bold;"><?php echo($p['value']); ?></A>
<?php } else { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);"><?php echo($p['value']); ?></A>
<?php } ?>
<?php } ?>
</div>
</div>
<?php foreach ($products as $product) { ?>
<div class="products"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a><br />
<b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b><br />
<?php echo $product['price']; ?></div>
<?php } ?>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<select name="page" onchange="this.form.submit();">
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<option value="<?php echo $p['value']; ?>" SELECTED><?php echo $p['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $p['value']; ?>"><?php echo $p['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</form>
</div>
</div>
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form name="freddo" action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="page" id="page_link" value="2">
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);" style="font-weight: bold;"><?php echo($p['value']); ?></A>
<?php } else { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);"><?php echo($p['value']); ?></A>
<?php } ?>
<?php } ?>
</form>
</div>
</div>
<?php } ?>
Pagination Issue.
Posted: Tue Sep 16, 2008 3:43 pm
by osglass
I had used bruce method on paginations and it works.
Bruce, My current pagination look like this:
1 |
2 | 3 | 4 | 5 |
How can I make it like this:
« Prev | 1 |
2 | 3 | 4 | Next »
help is appreciated
Heres a sample of simple pagination script:
http://it.newinstance.it/wp-content/upl ... g-demo.zip
Re: next page button at bottom of page
Posted: Tue Sep 16, 2008 10:12 pm
by dmbrownfield
I replaced my category.tpl file with the one that Bruce posted on March 06, 2008 at 10:14:03 a.m. to have the next page button repeated at the bottom of each page (which it did) but now my category images are gone. Anyone have a fix? Thanks much.
Re: A few questions...
Posted: Fri Sep 19, 2008 4:15 pm
by osglass
any help here >:(
Re: A few questions...
Posted: Fri Sep 19, 2008 4:39 pm
by bruce
Sure Chris,
note that a simplistic definition of prev is just $page - 1 and next is $page + 1 You should also take into account whether you are at the first or last page and not show prev or next accordingly
The simplistic link for prev could look like
Code: Select all
<A href="javascript:doSubmit(<?php echo($page -1); ?>);" style="font-weight: bold;"><?php echo($text_previous); ?></A>
assuming you have provided $text_previous to the template.
cheers
Bruce
Re: A few questions...
Posted: Fri Sep 19, 2008 4:40 pm
by bruce
dmbrownfield,
If you still have missing images, then please post a url where we can view the problem.
cheers
Bruce
Re: A few questions...
Posted: Fri Sep 19, 2008 10:07 pm
by osglass
Code: Select all
<A href="javascript:doSubmit(<?php echo($page -1); ?>);" style="font-weight: bold;"><?php echo($text_previous); ?></A>
Heres my code bruce:
Code: Select all
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);" style="font-weight: bold;"><?php echo($p['value']); ?></A>
<?php } else { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);"><?php echo($p['value']); ?></A>
<?php } ?>
<?php } ?>
</div>
</div>
Re: A few questions...
Posted: Fri Sep 19, 2008 10:22 pm
by osglass
This is what i did and its working:
Code: Select all
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<?php $text_previous="previous"; ?>
<?php $text_next="next"; ?>
<A href="javascript:doSubmit(<?php echo($page -1); ?>);" style="font-weight: bold;"><?php echo($text_previous); ?></A>
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);" style="font-weight: bold;"><?php echo($p['value']); ?></A>
<?php } else { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);"><?php echo($p['value']); ?></A>
<?php } ?>
<?php } ?>
<A href="javascript:doSubmit(<?php echo($page +1); ?>);" style="font-weight: bold;"><?php echo($text_next); ?></A>
</div>
</div>
I have 1 problem is when i click the next button 3 times i cant see any of my product anymore? is there some way i cant make it go back then make the prev and next button invinsible?
Re: A few questions...
Posted: Sun Oct 19, 2008 1:40 am
by jty
osglass wrote:
I have 1 problem is when i click the next button 3 times i cant see any of my product anymore? is there some way i cant make it go back then make the prev and next button invinsible?
Try this
Code: Select all
<div class="results">
<div class="left"><?php echo $text_results; ?></div>
<div class="right"><?php echo $entry_page; ?>
<form name="freddo" action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="page" id="page_link" value="2">
<?php if ($page > 1) { ?>
<A href="javascript:doSubmit(<?php echo($page -1); ?>);" style="font-weight: bold;"><?php echo 'Prev' ?></A>
<?php } ?>
<?php foreach ($pages as $p) { ?>
<?php if ($p['value'] == $page) { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);" style="font-weight: bold;"><?php echo($p['value']); ?></A>
<?php } else { ?>
<A href="javascript:doSubmit(<?php echo($p['value']); ?>);"><?php echo($p['value']); ?></A>
<?php } ?>
<?php } ?>
<?php if (($p['value'] > 1) and ($page < $p['value'])) { ?>
<A href="javascript:doSubmit(<?php echo($page +1); ?>);" style="font-weight: bold;"><?php echo 'Next' ?></A>
<?php } ?>
</form>
</div>
</div>
<?php } ?>