Jump to content

Make password for products


royal27
 Share

Recommended Posts

Hi can anyone tell me if is a module for protect products with password?

 

 

I tried something but i cant get it work,if someone knows how to do it please let me know

 

Here it is

 

{if ($_POST["codurideaccess"] == '$product->getProductName($codurideaccess.id_product)')}

{else}

<form  action="{$link->getPageLink}" method="post">
  <input type="text" name="codurideaccess">
      <input type="submit" name="Submit" value="GET ACCESS" class="exclusive" />
</form>

{/if}

Share this post


Link to post
Share on other sites

I would change your if statement to this. Remove the quotes and use $smarty instead of _POST

{if ($smarty.post.codurideaccess == $product->getProductName($codurideaccess.id_product))}

 

Also, I'm not sure what $codurideaccess.id_product is supposed to be? You are comparing it against the product name, but what is it?

 

You should also clarify what doesn't 'work'? Is the post failing? Are you getting a blank page? Are you not seeing your form?

  • Like 1

Share this post


Link to post
Share on other sites

$codurideaccess is made by me in dbase table ps_product

 

 

I would change your if statement to this. Remove the quotes and use $smarty instead of _POST

{if ($smarty.post.codurideaccess == $product->getProductName($codurideaccess.id_product))}

 

Also, I'm not sure what $codurideaccess.id_product is supposed to be? You are comparing it against the product name, but what is it?

 

You should also clarify what doesn't 'work'? Is the post failing? Are you getting a blank page? Are you not seeing your form?

Edited by royal27 (see edit history)

Share this post


Link to post
Share on other sites

i am not getting anything,it's shows me this form,but is not working because when i am writing the code shows me the same form

 

 

<form action="{$link->getPageLink}" method="post">

<input type="text" name="codurideaccess">

<input type="submit" name="Submit" value="GET ACCESS" class="exclusive" />

</form>

Share this post


Link to post
Share on other sites

can you provide the actual HTML output of the form when the page is loaded?

 

I would also revise you code to include some debug statements so you can see what the id_product is

 

{if ($_POST["codurideaccess"] == '$product->getProductName($codurideaccess.id_product)')}

{else}
<p>The codurideaccess product id is: {$codurideaccess.id_product}</p>
<p>The product id is: {$id_product}</p>
<form  action="{$link->getPageLink}" method="post">
  <input type="text" name="codurideaccess">
   <input type="submit" name="Submit" value="GET ACCESS" class="exclusive" />
</form>

{/if}

Share this post


Link to post
Share on other sites

Ok, to begin with your form action is not being set so you should correct that

<form  action="" method="post">
 <input type="text" name="codurideaccess">
 <input type="submit" name="Submit" value="GET ACCESS" class="exclusive" />
</form>

 

In your product.tpl, you are executing php sql query. You should avoid doing this. This type of coding belongs in a module or Product controller override.

<?php $codurideaccess=mysql_fetch_array(mysql_query("SELECT codurideaccess FROM marked_cards_factory_product WHERE id_product='".$product.id_product."'")); ?>

 

And finally I had suggested to add some debug statements to the product.tpl so that you can confirm what these values actually are.

Share this post


Link to post
Share on other sites

Ok,i put the code in controllers/productcontroller.php and still dosent work

 

$codurideaccess=mysql_fetch_array(mysql_query("SELECT codurideaccess FROM marked_cards_factory_product WHERE id_product='".$product.id_product."'"));

 

i tried with this code in product.tpl and still dont work,i am not familiar with prestashop.....and i dont know where to put it and where must finish the code....

 

 

{if($smarty.post.codurideaccess == $product->getProductName($codurideaccess.id_product))}

Share this post


Link to post
Share on other sites

In productcontroller, did you add the $codurideaccess variable to the smarty array? If not, then go back and do that.

 

And a third time, have you added any debug statements to the product.tpl to confirm what the values are? For example...

<p>The codurideaccess product id is: {$codurideaccess.id_product}</p>
<p>The product id is: {$id_product}</p>

Share this post


Link to post
Share on other sites

just search for smarty in productcontroller and you will see that an array of name/value pairs are registered with the smarty engine. This is how information (data) is transferred from the controller to the view in an MVC pattern. (model view controller).

 

In your case the model is the sql query you are executing. The controller is the productcontroller, and the view is product.tpl

 

So now that you have the information you need in the $codurideaccess array. You need to make that information available to the view, by adding the information to smarty. Try and come back if you have questions.

Share this post


Link to post
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More