Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?



Find us on Facebook

Follow us on Twitter

View our YouTube channel


 All Forums
 Technical
 PHP (Unix / Linux / Apache) versions
 email for price... suggestions please
 New Topic  Reply to Topic
 Printer Friendly
Previous Page | Next Page
Author  Topic 
Page: of 4

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/26/2018 :  08:26:19  
:)

Honestly excellent solution - wporks on the product page as well as the proddetail

how would you go about hiding the add to cart button too so there isnt an option to try and buy a zero proced item? I am guessing with my clients that will be the next issue :)

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/26/2018 :  09:04:41  
Ok, I tested this on my dev site there so give it a try.

In the javascript section of my code change that to the following - the part I added in red there

<script>
if (document.getElementById('butnoprc') != null) {
document.getElementById('butnoprc').innerHTML = document.getElementById('nopricebutton').innerHTML;
document.getElementsByClassName("buybutton")[0].style.display='none';
}
</script>

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/26/2018 :  09:06:59  
Andy, I think this might be useful if someone wanted to trigger the ask a question from the product description, or add the button to one of the custom fields.
I think I will form up a new post with some added details on what a store owner might want to do with this.

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/26/2018 :  09:53:34  
I reckon this is a great bit of code and a great idea.. I do know there are customers of mine that would like it worded.. click for a quote or something similar

Excellent work dave..

by the way I still got my add to cart button lol - but then thats probably just me :)

Andy
ECT Moderator

95440 Posts

Posted - 07/26/2018 :  09:54:01  
quote:
Andy, I think this might be useful if someone wanted to trigger the ask a question from the product description, or add the button to one of the custom fields.
I think I will form up a new post with some added details on what a store owner might want to do with this.
Thanks again David, let me know if you need anything tested too.

Andy

Please feel free to review / rate our software

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/26/2018 :  09:58:08  
http://www.baby-barn.co.uk/products.php

as you can see it has the desired effect on the wrong product :) lol

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/26/2018 :  13:02:04  
quote:
as you can see it has the desired effect on the wrong product :) lol


This is because I didn't write it for the products page

This line - document.getElementsByClassName("buybutton")[0].style.display='none';
The zero there is telling the code to look for the first instance of the class "buybutton" and hide it.
That works on product details because there is only one instance.
Now for the products page where you will have multiple instances of the add to cart button, that becomes an issue.

I would need to do some more work. We basically need to iterate through all of the products on the page and look for any that have zero price, then see the best way to hide the add to cart for just those.
I will see what I can whip up this evening. I'm in the office for a while, so it will be a few hours.

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/26/2018 :  19:23:41  
Ok, here (below) is the javascript for the products page to target the add to cart for the one with zero price.
In my testing it seems to work, but give it a go and let me know.
I also see that ask a question on your products page does not have a product ID in the textarea.
Have you actually tested that to see what the email looks like? If that's not working, I may have an idea to get it going.

<script>
var prodcount = document.getElementsByClassName("product");
for(var i = 0; i < prodcount.length; i++) {
var detectzeroprice = document.getElementById('pricediv' + i).innerText
if (detectzeroprice == '') {
document.getElementById('butnoprc').innerHTML = document.getElementById('nopricebutton').innerHTML;
document.getElementsByClassName("buybutton")[i].style.display='none';}
}
</script>

Edited by - dbdave on 07/26/2018 19:32:39

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/26/2018 :  20:53:30  
Ok, I suspect you will have problems with the product ID not being populated in the ask-a-question for the products page, so I worked up a solution.
Keep in mind I am testing on my site that is setup different from your site.
For example, I had to isolate the product ID differently for your site because you are not showing the product ID there.
I am actually pulling the product ID from the link in the product name.
I also changed things up for the div with the link, it's included in the script now.

So the instructions for the products page are
just before the include line that calls up the products, add this
<?php $pricezeromessage="<div id='butnoprc'></div>";?> (you already have that)

and just after that include line add this

<script>
var prodcount = document.getElementsByClassName("product");
for(var i = 0; i < prodcount.length; i++) {
var detectzeroprice = document.getElementById('pricediv' + i).innerText
if (detectzeroprice == '') {
var detectprodid = document.getElementsByClassName('prodname')[i].innerHTML;
var pidis = detectprodid.slice(46);
var pidis2 = pidis.indexOf('"');
var pidis3 = pidis.slice(0 , pidis2);
console.log (detectprodid); //debug line can be removed after you know it works
console.log (pidis3); //debug line can be removed after you know it works
var askque = ('<input value="Email for Price" class="askaquestion" onclick="openEFWindow(\''+pidis3+'\',true)" type="button">');
document.getElementById('butnoprc').innerHTML = askque;
document.getElementsByClassName("buybutton")[i].style.display='none';}
}
</script>


I left 2 lines in there for debug purposes. If it's not working we can see what's being returned for those variables by hitting F12 and view the console in your browser.
Once we know it works, you can remove those two lines.

For both the proddetail and the products pages, if you want the wording for the buttons to show something different just change the "value" there
value="Email for Price" change to
value="Some other message"

I also just realized that if you have multiple products on the page with zero price, the ID for the div would be repeated. Correct html says an ID should only be used on a page once. Now I think this will still work, but do test and if there are problems, I'll see if we can work it out.
So, see what happens when you set the price to zero on more that one product on the products page.

Let me know how you get along.

Edited by - dbdave on 07/27/2018 07:05:01

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/27/2018 :  02:13:21  
Thank you Dave

The product page is working fine with your changes to the script

The only thing left is the add to cart on the product detail page I have
http://www.baby-barn.co.uk/proddetail.php?prod=JoieEvaliteDuoStrollerBlack1
have you any suggestions how I can remove it on the product detail page?

Kind Regards and many thanks
Richard

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/27/2018 :  06:50:11  
Hi, that was my earlier post - was intended for the detail page - did you change the script there?
quote:

In the javascript section of my code change that to the following - the part I added in red there

<script>
if (document.getElementById('butnoprc') != null) {
document.getElementById('butnoprc').innerHTML = document.getElementById('nopricebutton').innerHTML;
document.getElementsByClassName("buybutton")[0].style.display='none';
}
</script>

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/27/2018 :  07:01:57  
Hi Dave

yes I have this in the proddetail.cphp
<script>
if (document.getElementById('butnoprc') != null) {
document.getElementById('butnoprc').innerHTML = document.getElementById('nopricebutton').innerHTML;
document.getElementsByClassName("buybutton")[0].style.display='none';
}
</script>

and still showing the add to cart on the proddetail page: http://www.baby-barn.co.uk/proddetail.php?prod=JoieEvaliteDuoStrollerBlack1

Kind Regards
Richard

Sorry

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/27/2018 :  07:07:01  
Ok, I will take a look now.

I noticed the ask a question is not poping up on the products page. I forget to escape the single quotes for the product ID so here is the corrected code for the products page

<script>
var prodcount = document.getElementsByClassName("product");
for(var i = 0; i < prodcount.length; i++) {
var detectzeroprice = document.getElementById('pricediv' + i).innerText
if (detectzeroprice == '') {
var detectprodid = document.getElementsByClassName('prodname')[i].innerHTML;
var pidis = detectprodid.slice(46);
var pidis2 = pidis.indexOf('"');
var pidis3 = pidis.slice(0 , pidis2);
console.log (detectprodid); //debug line can be removed after you know it works
console.log (pidis3); //debug line can be removed after you know it works
var askque = ('<input value="Email for Price" class="askaquestion" onclick="openEFWindow(\''+pidis3+'\',true)" type="button">');
document.getElementById('butnoprc').innerHTML = askque;
document.getElementsByClassName("buybutton")[i].style.display='none';}
}
</script>

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/27/2018 :  07:10:03  
just changed it thank you - and working

Kind Regards
Richard

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/27/2018 :  07:23:45  
Ok, for the details page, that add to cart button is the 2nd one on the page - the first one is hidden, so lets target them both

use this

<script>
if (document.getElementById('butnoprc') != null) {
document.getElementById('butnoprc').innerHTML = document.getElementById('nopricebutton').innerHTML;
document.getElementsByClassName("buybutton")[0].style.display='none';
document.getElementsByClassName("buybutton")[1].style.display='none';
}
</script>

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/27/2018 :  07:39:52  
thats got it !!!!!!!! :) :) :) :) :) :) thank you :)

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/27/2018 :  07:47:36  
Great, now keep in mind that I set this code up based on your current setup.
There are some things you might change on your site, that can affect this code.
I'm also just a ect customer just like you, so this custom code is not supported by ect.
With that said, if you have problems, I am probably just a post away to help.

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/27/2018 :  07:53:39  
thank you Dave

much appreciated :)

webspaceunlimited
Advanced Member

United Kingdom
136 Posts

Posted - 07/29/2018 :  00:08:57  
hi

ok still not 100% there yet (sorry) needed to get some products in to get a better idea

I have turned set: $notifybackinstock=FALSE; as the notifier was showing up under the "email for discount price" button
I have the stock management turned offf
So its showing out of stock on both the product admin and product lists (this I need to hide)

on the products page:
http://www.baby-barn.co.uk/products.php
we are getting just the fist mention of the button

Any more suggestions dave (feeling guilty asking now ) sorry

Kind Regards
Richard

dbdave
ECT Moderator

USA
8590 Posts

Posted - 07/29/2018 :  06:32:24  
I'm not sure what's going on there.
Are you sure you have not "unticked" the sell button on those products?
If you are not using stock management, then unticking the sell button would show the out of stock message.

By having the out of stock message there, it removes the add to cart button, so this is why the add to cart button is hidden on that next product.
look in the admin at those products to see if the sell button is unticked.
Page: of 4  Topic   
Previous Page | Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2019 ecommercetemplates.com
This page was generated in 0.03 seconds. Snitz Forums 2000