I have a specific information page (page id is 12) and from admin panel i have assigned this page ID to particular product. For example, Information-id 12 is assigned to to Product1. When a user buys that product, and when the order status is set to 'Complete', user should have access to that page(information-id). I mean , to access this page, user should buy that product and order status is to be complete and user should logged in.
I am not getting how to do it. In order.tpl, i tried doing like this, but if i copy the URL and paste , it can be accessible without logging in.
here is my order_list.tpl
$end_date= date('Y-m-d', strtotime($start_date. ' + '.$date1. 'days'));
echo date('d/m/Y',strtotime($end_date));
?></td>
</tr>
<tr>
<td class="history">Product Name</td>
<?php $today = date('Y-m-d'); ?>
<?php if(($order['status']='Complete') AND ($today > $end_date)) { ?>
<td><strong><h4><font color="#FF0000">Either Your Course date is Expired or Order is not completed!!</font></h4></strong> </td>
<?php }
else { ?>
<td><strong><?php echo $order['pname']; ?></strong></td>
<?php } ?>
</tr>
Here i am also checking the expiry date, which am capturing through admin.
If i put customer_islogged(), in information.php(controller), i cannot access any other pages.
Create a function where you can pass list of products, any of that needs to be purchased to access that particular page
//catalog/model/account/order.php
public function checkForAccess($product_id_list){
$exists = false;
$query = $this->db->query("SELECT product_id FROM ".DB_PREFIX."order o LEFT JOIN ".DB_PREFIX."order_product op ON (o.order_id=op.order_id) WHERE o.order_status_id=5 AND o.customer_id = '" . (int)$this->customer->getId() ."'");
foreach($query->rows as $product){
if(in_array($product['product_id'],$product_id_list)){
$exists = true;
break;
}
}
return $exists;
}
Now in that particular page you can check if the customer has completed purchased or not
$this->load->model('account/order');
//Eg Customer will have access who have purchased product 20 and 22
$product_list = array(20,22);
$results = $this->model_account_order->checkForAccess($product_list);
if(!$results){
//where to redirect if not valid
$this->response->redirect($this->url->link('common/home'));
}
Related
How can I show the the weight (with units) in product page in 1.5.6.
Example: Weight - 2.5 kg; Weight - 250 mg ...
I've been reading some articles, but nothing working correctly.
You can format weight with Opencart's weight class format() method like this:
$this->weight->format($weight,$weight_class_id);
The getProduct() method already supplies both values you need so you can easily call it from the product controller like so:
$this->data['product_weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
Then display $product_weight wherever you want in the tpl as you would any other variable. This will give you exactly what you want but with no space (i.e., '250mg').
If you want more control over the formatting, you can also get only the unit abbreviation (e.g., 'kg', 'oz', 'lb', etc) with the getUnit() method like this:
$this->weight->getUnit($product_info['weight_class_id']);
You could then put them together however you want. If you want a space for instance:
$this->data['product_weight'] = $product_info['weight'] . ' ' . $this->weight->getUnit($product_info['weight_class_id']);
go to catalog/language/english/product/product.php,Find:
$_['text_model'] = 'Product Code:';
Add below code after it
$_['text_weight'] = 'Weight:';
open catalog/controller/product/product.php, Find:
$data['text_stock'] = $this->language->get('text_stock');
Add below code after it:
$data['text_weight'] = $this->language->get('text_weight');
In same file search for the code:
$data['model'] = $product_info['model'];
Paste below code after it:
$data['weight'] = $product_info['weight'];
$tablewunit = $this->db->query("SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE (wcd.weight_class_id = " . $product_info['weight_class_id'] . ") AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
$data['weight_unit'] = $tablewunit->row['unit'];
Now open catalog/view/theme/---yourtheme---/template/product/product.tpl, and find:
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
Add below code after it:
<td><b><?php echo $text_weight; ?></b></td>
<td><?php echo round ($weight, 2) . ' ' . $weight_unit; ?></td>
<tr>
<?php if ($weight) { ?>
<tr>
<?php } ?>
Thats all
Hello fellow Bulgarian i assume by your name.
If you want to display weight on products it's very simple.
Open your FTP and go to catalog/view/theme/YOURTHEME/template/product and download product.tpl
find this line
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span><br />
<?php } ?>
Right after it paste this
<?php
echo round($weight,2). "kg";
?>
(Or paste it where ever you want to see it on the product page.)
after that go to /catalog/controller/product and open product.php
find this line
$this->data['model'] = $product_info['model'];
and right after it paste this line:
$this->data['weight'] = $product_info['weight'];
and you are pretty much done with that.
Hopefully i understood your question correctly.
I have created an ordering system which has a page that allows the end user to place/add to an order and then move to the next page to review the entire order.
I want to be able to have the user move back to the order page from the review order page and see the quantity that was just added/placed...so if I order 2 of widget A, I move to the review page and see that I have an order with 2 A widgets for a particular cost; I then move back to the order page and the quantity of 2 should still be visible to the end user and displayed with Widget A.
I have worked all of this out UNTIL I try to redisplay the Order page and its associated fields.
I get a Value cannot be null or empty error; I realize the meaning of this error and I have stepped through the code and can see that I have data!! I see nothing that is null nor empty that should not be.
What am I doing wrong?
My code:
menuIndex = 0;
intMenuTable1 = 3;
foreach (var menu_item in Model.OrderMenu)
{
if (menuIndex < intMenuTable1)
{
<tr>
<td align="center">
#Html.TextBoxFor(m => m.OrderMenu[menuIndex].Quantity, new { #class = "form-control", #style = "width:50px; height:50px;text-align:center; margin-top:50px; margin-left:10px;"})
#Html.TextBoxFor(m => m.OrderMenu[menuIndex].ID)
#Html.TextBoxFor(m => m.OrderMenu[menuIndex].ProductPrice) - **error is here**
</td>
<td align="center">
<img id="imgProduct" src=#Url.Content(#menu_item.ProductImage) />
</td>
</tr>
}
}
The error was actually BELOW the line that was coming across as an error.
I was not passing all of the model elements that I needed to recreate the view, hence the NULL values.
I am using this module which allows me to run a simple blog / news feed in OC which does what I need apart from one thing, I need to display the first 4 articles on the homepage.
I have got the following so far:
<?php
$sql = "SELECT * FROM " . DB_PREFIX . "blog b LEFT JOIN " . DB_PREFIX . "blog_description bd ON (b.blog_id = bd.blog_id) WHERE b.status = 1 AND b.date <= NOW() AND bd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
$query = $this->db->query($sql);
$blogs = array();
?>
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php
foreach($query->rows as $result){
$blogs[] = $result;
}
?>
</div>
</div>
I have been developing OC templates for a while but modules are a whole new ball game for me, any help would be appreciated
First of all You should learn and understand how the MVC (or whatever it tends to be) is implemented in OpenCart - we have controllers, models and view templates.
Your approach is mixing all the controller and model part into a view template which is completely wrong.
So what should go where:
SQL query should go into the model
A new method for retrieving the data from the model and preparing it for the view template should go into the controller
Only HTML markup should be present in the view template
Let's say the extension You have downloaded has a controller here: catalog/controller/information/news.php - You should extend it's index() (or other appropriate) method (or even create a new one if needed) so that it calls the news model where You place Your new method getLastFourArticles() which should look like:
public function getLastFourArticles() {
$sql = "
SELECT *
FROM " . DB_PREFIX . "blog b
LEFT JOIN " . DB_PREFIX . "blog_description bd ON b.blog_id = bd.blog_id
WHERE b.status = 1
AND b.date <= NOW()
AND bd.language_id = " . (int)$this->config->get('config_language_id') . "
ORDER BY b.date DESC
LIMIT 4";
return $this->db->query($sql);
}
ORDER BY part will sort the blog entries from the newest to the latest and the LIMIT 4 part will make sure we only receive 4 rows maximally.
Now in the controller You should do something like:
$this->data['latest_entries'] = $this->model_information_news->getLastFourArticles();
while expecting the model to be catalog/model/information/news.php and that it is loaded ($this->load->model('information/news');).
Now in Your template only this part is needed:
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php foreach($latest_entries as $entry) { ?>
<span class="date"><?php echo $entry['date']; ?></span>
<span class="entry"><?php echo $entry['text']; ?></span>
<?php } ?>
</div>
</div>
Keep in mind this is only instruction-like answer and You should pass in the right names and variables (and indices for the blog entry in the template).
I have one form text field in index.php and i fill 8080
http_port : <input size="5" name="http_port" value="3128">
and table 'squid' like this
no | tag | value
1 | http_port | 3128
when i click submit button its redirect to submit.php but the table didnt update the value or still 3128.
submit.php
<?php
include("conn.php");
$value = $_POST['http_port'];
$query = mysql_query("update squid set http_port='$value' where '$no'=1");
echo "Update was Succesful<br>
Bac";
?>
whats wrong with my script? Thanks and sorry for my bad english :)
There's a mistake in your mysql_query call, it should be:
$query = mysql_query("update squid set tag ='$value' where no=1");
I haven't coded anything in PHP for ages, but there are plenty of tutorials for such simple MySQL/PHP forms. Code I provided updates tag column, and in similar way you can update other columns...
$query = mysql_query("update squid set value ='$value' where no=1 and tag = 'http_port'");
Try this:
index.html:
<html>
<body>
<form action="submit.php" method="post">
http_port :
<input size="5" name="http_port" value="3128" />
<input type="submit" />
</form>
</body>
</html>
submit.php:
<?php
require("conn.php");
if(isset($_POST['http_port']))
{
$value = $_POST['http_port'];
//You should sanitize data before inserting into table
$value = mysql_real_escape_string(htmlentities(strip_tags(trim($value))));
$no="your table field name";
$sql = "UPDATE squid SET http_port=".$value." where ".$no."=1";
$query = mysql_query($sql) OR die("Err:".mysql_error());
echo "Update was Successful<br />Back";
}
else
{
echo "Something else";
}
?>
$value is in single quotes so will not get the value of variable $value.
$sql = "update squid set http_port='".$value."'where no=1";
I'm looking for the most elegant way to lock a Django user account after several failed login attempts.
"What have I tried?":
I have looked unsuccessfully for similar questions on SO (If this question is a dup please, post a comment to delete this one).
At the moment I'm looking for other developers' experiences. I would prefer not to talk about what I've tried in order to not condition the answers.
As additional information, the app doesn't have UserProfile enabled (but, of course, I can enable it if it's worth it).
Take a look at django-axes or django-brutebuster
We used django-lockout and it worked really well
UPDATE: django-lockout's last release was 2011: https://pypi.org/project/django-lockout/. The Github project does not exist anymore (404).
One simple solution would be to create a variable in the User Profile that is initialy 0 and increased by 1 every time the user unsuccessfully tries to login. If this variable reaches a certain threshold(which is checked every time the user tries to login), the user account can be suspended. Of course when the user does succesfully login, the variable must be set back to 0.
Create model called "failed_logins" with two fields, a "User" field/foreign key and a "Timestamp" field.
When a user successfully logs in, delete all "failed_logins" entries for that user.
When a user unsuccessfully logs in, create an entry in "failed_logins" for that user with the current timestamp.
On every login attempt for a given user, BEFORE checking to see if password is correct/incorrect:
run a query deleting all "failed_logins" entries older than 15 minutes (or w/e time period).
run a query checking the count of entries in failed_logins for the user attempting to login. If it's 5, kill the login attempt, notifying the user they have been locked out of their account and to try back in a little while.
Result:
Users are locked out after 5 failed login attempts for a short while.
You can try this snippet:
<?php
session_start();
$conn = mysql_connect("localhost","root","root");
$select = mysql_select_db("Gayathri",$conn) or die("connection error");
if(isset($_COOKIE['login'])&&$_COOKIE['login']>=3){
echo " you have to wait for sometimes to enable your login"."<br>";
}
if(isset($_POST["username"],$_POST["userpassword"])){
$username = $_POST['username'];
$userpassword = $_POST['userpassword'];
$query = "SELECT * from userlogin where username='".$username."' and userpassword='".$userpassword."'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
if($row){
echo"login successfull";
}
else{
echo"Invalid password"."<br>";
if(isset($_COOKIE['login'])){
$attempts=$_COOKIE['login']+1;
}else{
$attempts=1;
}
setcookie('login', $attempts, time()+60*60);
}
}
?>
<form method = "post" action = "">
<table border=1>
<tr>
<td>Username:</td>
<td><input type="text" name="username" value=""></td>
</tr>
<tr>
<td>Userpassword:</td>
<td><input type="password" name="userpassword" value=""></td>
</tr>
<tr>
<td colspan="2" align=center><input type="submit" name="submit" value="login"></td>
</tr>
</table>