Login to buy

I've seen that some users have added a bit of javascripting in order to only allow registered customers to buy things from our shop.

As I'm a newbie concerning javascript I think the community would be very thankful if someone posted that bit of code here, allowing other users to use it.

Thanks.


If you have seen...

martv's picture

Hi.

If you have seen that some users have done it with JavaScript, then maybe you can use their script. Hopefully someone is willing to share his/her script with the community.

-Märt

Yes that's what I would like

Yes that's what I would like to happen.

It would be very useful.

Can anyone share it please?

Thx.

I haven't enabled it on my

I haven't enabled it on my site, but a simple script to disable the "Add to cart" button if $customer_answer_name$= ""

Please be aware that I have added a number one to the end of $customer_answer_name$ on purpose and is required...

<script type="text/javascript">
if ("$customer_answer_name$1" == "1")
{
document.write ("<img title='Please log in to purchase this item' alt='Please log in to purchase this item' src='/images/add-gray.gif' border='0'>")
}
else {
document.write ("<input alt='&product_title1$' src='/images/btn3_add.gif' value='' class='ProductAddButton' name='add$product_open_field2$' type='image'><a name='$product_code$'></a>")
}
</script>

I have tested this script on my site and seamed to work fine...a few things you will need to change with your product/images etc for it to work...

Open Field 2 should contain the product number
Be aware that this isn't the item code that you create, go to Products --> Products --> Products and hover your mouse over the product title (where it details which groups the product belongs in but don't click), there should be a number detailed at the bottom of the window saying something like "javascript:ModifyProduct('410',1,0)" - it's the first number we are interested in - add that to the open field 2 (or any other open field, but remember to change the code detailed above to match) of that product...it may take some time to do this if you have a lot of products.

Save the "Add to cart" image to your computer and make it grey (or dull looking to make it look disabled), save this as "add-gray.gif" and name the original coloured image as "btn3_add.gif".

Create a folder in File Manager called "Images" and upload these new images to this new folder.

If they don't log in "$customer_answer_name$" will equal nothing so "$customer_answer_name$1" will equal "1" and run the first part of the script.

If they log in $customer_answer_name$ will equal their name, ie "fred blogs" so "$customer_answer_name$1" will equal "fred blogs1" therefore it will run the second part of the code.

Forgot to log in before

Forgot to log in before posting this reply...any Qs, let me know

great thanks! I'll try that

great thanks! I'll try that as soon as possible and then give you the feedback!

The reason you have to add

The reason you have to add the product code to the open field is because with the javascript you use the document.write commands and the html code you want to add must be within the quotes.

If you use $product_add_action$ parameter it will add the code required to display the button, but that automatic coding contains double quotes...and it's these double quotes that make the script fail.

So make sure you use single quotes where you would normally use double quotes within the document.write(" ") quotes