News:

Support the VirtueMart project and become a member

Main Menu

Sold-out product filter - few lines for cup of coffee

Started by mrbizzy, February 03, 2011, 13:30:17 PM

Previous topic - Next topic

mrbizzy

Hello Friends!
Idea: Put a checkbox on product browse page:

*when checked - show products that are out of stock
*when un-checked do not show out-of-stock products.

I can make it work for one page load by using form POST or GET.
I can even make it work for the whole session by using joomla sessions.

But i can't make it change the session value when unchecked.

So basically i need a few lines that will:

1. Set session to state "A"  when checkbox is checked
2. Set session to state "B"  when checkbox is un-checked

Also - after setting it to state "A" it should stay in that state and checkbox should appear as CHECKED until it is unchecked by the user.

The product sorting and filtering i will do myself.

I am open to any other solutions too.

It looks to me that this will only take a few lines of code but i can't find the correct approach.

I would love to buy you a cup of coffee if you help me out with this :)


Regards, Casper

Joseph Kwan

You can use the $_SESSION global variable to record the state. Say $_SESSION['out_of_stock']=1;
Joomla/VM Upgrade Services. Problems with your migration? We can help.
Custom extensions to VM. Performance Tuning. Template modifications and advices.
Pay service to make VM work according to your needs. Your Joomla/VM solutions are just a PM away.

lowmips

You'll need to use 2 inputs...the checkbox and a hidden input to indicate that the user has clicked the checkbox  (when a checkbox is unchecked, its value is not posted).

The show out of stock form:

<?
$checked = '';
if($_SESSION['showoos']=='1') $checked=' checked ';
?>
<form name="showoos-form" method="post">
<input type="checkbox" name="showoos" <?=$checked ?> onClick="document.showoos-form.submit" /> Show out of stock items
<input type="hidden" name="oosclick" value="1" />
</form>



Then, place the following in a global file, probably the best would be /components/com_virtuemart/virtuemart.php:

if($_POST['oosclick']=='1'){
if($_POST['showoos']=='1'){
$_SESSION['showoos']==1;
}else{
$_SESSION['showoos']==0;
}
}



You'll probably want to use a few 'isset()' in there to stop any warnings on the front end.


Large, two sugars, extra cream pls =)
Visit my website at www.lowmips.com
View my newsletters Here (sign up for newsletters on the front page of my website)

mrbizzy

Thank you for the effort. but something is missing/not-working here.
After submitting the form checkbox is unchecked again..
Also onClick does not work.. so i tried to add a submit button to test it.

Please keep in mind that when it comes to the coding i am not the brightest person around. So maybe there was something i should ADD in there which i did not understand i have to ????

lowmips

I goofed the second piece of code...I did a boolean comparison instead of actually setting the variables.  Change it to this:

if($_POST['oosclick']=='1'){
if($_POST['showoos']=='1'){
$_SESSION['showoos']=1;
}else{
$_SESSION['showoos']=0;
}
}
Visit my website at www.lowmips.com
View my newsletters Here (sign up for newsletters on the front page of my website)

lowmips

and the first bit of code javascript should have parens..

<?
$checked = '';
if($_SESSION['showoos']=='1') $checked=' checked ';
?>
<form name="showoos-form" method="post">
<input type="checkbox" name="showoos" <?=$checked ?> onClick="document.showoos-form.submit()" /> Show out of stock items
<input type="hidden" name="oosclick" value="1" />
</form>
Visit my website at www.lowmips.com
View my newsletters Here (sign up for newsletters on the front page of my website)

mrbizzy

GREAT - it is functioning perfectly!
Now when it works it looks even better than i imagined :)

karlozzz

Hi guys, please could you guide how and where to put which code to make it work ?
It looks like great feature, but i cant make it work just with these code //

Free coffees includes ! 8)