Opencart minimum order price - php

I am trying to implement below code from here in catalogue/view/theme/default/template/checkout/confirm.tpl
<?php if ($this->cart->getSubtotal() >= 1000) { ?>
<div id="payment"><?php echo $payment; ?></div>
<?php } else { ?>
<div class="warning">Minimum 10 Euro to checkout</div>
<?php } ?>
but i am getting an error
Notice: Undefined property: Loader::$cart in C:\xampp\htdocs\optest\catalog\view\theme\default\template\checkout\confirm.tpl on line 51
Fatal error: Call to a member function getSubtotal() on null in C:\xampp\htdocs\optest\catalog\view\theme\default\template\checkout\confirm.tpl on line 51
reference taken:
Opencart minimum order price exclude one category
http://forum.opencart.com/viewtopic.php?t=53810

Not the same way but you can do it like this:
Add this line in your checkout.php controller file.
if ($this->cart->getSubtotal() < 1000) {
$this->session->data['error'] = 'Your warning message';
$this->response->redirect($this->url->link('checkout/cart'));
}
After
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
Thats it.

The code below is working for me:
<?php if($this->session->data['currency'] == 'USD') : ?>
<?php if($this->cart->getSubtotal() < 2enter code here0) : ?>
<div class="warning"><center><?php echo $text_comandamin_eur; ?></center></div>
<?php endif; ?>
<?php } elseif($this->session->data['currency'] == 'INR') : ?>
<?php if($this->cart->getSubtotal() < 1000) : ?>
<div class="warning"><center><?php echo $text_comandamin_ron; ?></center></div>
<?php endif; ?>
<?php endif; ?>

Related

"Unexpected { on line …": Can't find the cause [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I’m going mad over this – I can’t find the reason for the "unexpected {"-error being thrown right after the last "else" (7th line from below). Does anyone see something that I don’t?
<?php
$i = 0;
foreach($bgs as $bg) { ?>
<?php $i++; ?>
<div class="item <?php if($i == '1') echo "active"; ?> img-responsive" style="background-image: url('/new/images/<?=$bg['b_url']?>')" >
<div class="metabox">
<?php if(($bg['b_weight']) != '1000') { ?>
<h1><?=$bg['w_titel']?></h1>
<p><?=$bg['w_info']?> // <?=$bg['w_jahr']?> // <?=$bg['w_ort']?><?=$bg['w_function']?></p>
<?php if (isset($_GET['w']) && (is_numeric($_GET['w']))) { ?>
<?=$bg['w_desc']?>
<?php } else { ?>
<p>More</p>
<?php } ?>
<?php } else { ?>
<h1><?=$bg['w_titel']?></h1>
<p><?=$bg['w_info']?></p>
<?php } ?>
</div>
</div>
<?php } ?>
This is very hard to read, you have my sympathies. Have you thought about using an alternative syntax for if
try using
<?php if (condition) :?> <?php do something; ?>
<?php else: do something; ?>
<?php endif; ?>
This was odd: Right before said last else statement was an invisible item (have no idea what it could have been?) – when I deleted the space between the preceding } and else, and inserted a new blank space, the code parsed fine.
Everything looks right. Try to use following syntax it will be more readable.
foreach($bgs as $bg) :
$i++;
if(1 != '1000') :
echo 3;
if ( 1 != 2) :
echo 4;
else:
echo 1;
endif;
else:
echo 2;
endif;
endforeach;
Also try to replace:
<?php if($i == '1') echo "active"; ?>
to:
<?= $i == '1' ? "active" : ''; ?>

joomla module position if else and

I am creating an responsive template and for that to happen I need to use and if else and function. This is what I have so far.
<?php if ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
I am now receiving the error:
Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND) in index.php on line 197
Line 197 =
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
I have tried adding an extra () but that did not work:
<?php } elseif (($this->countModules('left')) && ($this->countModules('right'))) { ?>
I am forgetting something but what.
The order is wrong and instead of adding the () you should remove a set. See the adapted code below.
<?php if ($this->countModules('left') && $this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
Hopefully this puts you in the right lane.
You have your brackets in the wrong place. Try replacing the following:
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
with this:
<?php } elseif ($this->countModules('left') && $this->countModules('right')) { ?>

PHP Notice: Undefined variable: http_type

I get the following PHP Notice in my opencart log file.
Undefined variable: http_type in /home/AAA/public_html/vqmod/vqcache/vq2-catalog_view_theme_template_product_product.tpl on line 3
Here is what I have in my product.php file's few first few lines
<?php if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$http_type = "https:";} else {$http_type = "http:";}
<!---THIS IS LINE 3---> ?>
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb" xmlns:v="<?php echo $http_type;?>//rdf.data-vocabulary.org/#" id="brd-crumbs" >
<ul>
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li typeof="v:Breadcrumb">
<?php echo $breadcrumb['separator']; ?><a property="v:title" rel="v:url" href="<?php echo $breadcrumb['href']; ?>"><span><?php echo $breadcrumb['text']; ?></span></a></li>
<?php } ?>
</ul>
</div>
Any help is highly appreciated
Firstly, it's just a notice so I expect everything is working as you would expect.
The notice is generated because when the $http_type variable is echoed, it hasn't necessarily been set to anything. If you add $http_type = ''; before the initial if statement, that will get rid of the notice.

if else error message always shows else statement message

I think this is a simple problem. But, I don't know how to solve this problem. I have posted my codes below. Here, In this below code if else statement always shows No Sarees. I got the result from mysql table but it always shows with No Sarees text. I have checked this using var_dump($categories) it returns array(0){} . How can I solve this problem?
<?php if ($categories) { ?>
<!--BOF Refine Search Result-->
<div class="refine-search-result">
<?php if (count($categories) <= 5) { ?>
<?php foreach ($categories as $category) { ?>
<div class="refine-block">
<p><?php echo $category['name']; ?></p>
</div>
<?php } ?>
<?php } else { ?>
<?php for ($i = 0; $i < count($categories);) { ?>
<?php $j = $i + ceil(count($categories) / 4); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($categories[$i])) { ?>
<div class="refine-block">
<p><?php echo $categories[$i]['name']; ?></p>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<div class="clear"></div>
</div><!--EOF Refine Search Result-->
<?php } else {
?>
<div class="refine-search-result">
<div class="refine-block">
<p>No Sarees</p>
</div>
<div class="clear"></div>
</div>
<?php } ?>
If your $categories is empty array then in if($categories) your array is converted to boolean value. If it's empty array (and you say it is) then it's get converted to false.
Check this:
$categories = array(); //empty array
var_dump((boolean)$categories); //this will show what variable will look like after converting to boolean value
if ($categories){
echo '$categories IS NOT empty';
}else{
echo '$categories IS empty';
}

Show Ads In Middle Of Results

I'm currently using sphider on one of my websites, my questions is how can I break the results page into 2 parts to add a 200px break to place a ad slot.
Code:
<?php
extract($search_results);
?>
<?php if ($search_results['did_you_mean']){?>
<div id="did_you_mean">
<?php echo $sph_messages['DidYouMean'];?>: <?php print $search_results['did_you_mean_b']; ?>?
</div>
<?php }?>
<?php if ($search_results['ignore_words']){?>
<div id="common_report">
<?php while ($thisword=each($ignore_words)) {
$ignored .= " ".$thisword[1];
}
$msg = str_replace ('%ignored_words', $ignored, $sph_messages["ignoredWords"]);
echo $msg; ?>
</div>
<?php }?>
<?php if ($search_results['total_results']==0){?>
<div id ="result_report">
<?php
$msg = str_replace ('%query', $ent_query, $sph_messages["noMatch"]);
echo $msg;
?>
</div>
<?php }?>
<?php if ($total_results != 0 && $from <= $to){?>
<div id ="result_report">
<?php
$result = $sph_messages['Results'];
$result = str_replace ('%from', $from, $result);
$result = str_replace ('%to', $to, $result);
$result = str_replace ('%all', $total_results, $result);
$matchword = $sph_messages["matches"];
if ($total_results== 1) {
$matchword= $sph_messages["match"];
} else {
$matchword= $sph_messages["matches"];
}
$result = str_replace ('%matchword', $matchword, $result);
$result = str_replace ('%secs', $time, $result);
echo $result;
?>
</div>
<?php }?>
<?php if (isset($qry_results)) {
?>
<div id="results">
<!-- results listing -->
<?php foreach ($qry_results as $_key => $_row){
$last_domain = $domain_name;
extract($_row);
if ($show_query_scores == 0) {
$weight = '';
} else {
$weight = "[$weight%]";
}
?>
<?php if ($domain_name==$last_domain && $merge_site_results == 1 && $domain == "") {?>
<div class="idented">
<?php }?>
<b><?php print $num?>.</b> <?php print $weight?>
<?php print ($title?$title:$sph_messages['Untitled'])?><br/>
<div class="description"><?php print $fulltxt?></div>
<div class="url"><?php print $url2?> - <?php print $page_size?></div>
<?php if ($domain_name==$last_domain && $merge_site_results == 1 && $domain == "") {?>
[ More results from <?php print $domain_name?> ]
</div class="idented">
<?php }?>
<br/>
<?php }?>
</div>
<?php }?>
<!-- links to other result pages-->
<?php if (isset($other_pages)) {
if ($adv==1) {
$adv_qry = "&adv=1";
}
if ($type != "") {
$type_qry = "&type=$type";
}
?>
<div id="other_pages">
<?php print $sph_messages["Result page"]?>:
<?php if ($start >1){?>
<?php print $sph_messages['Previous']?>
<?php }?>
<?php foreach ($other_pages as $page_num) {
if ($page_num !=$start){?>
<?php print $page_num?>
<?php } else {?>
<b><?php print $page_num?></b>
<?php }?>
<?php }?>
<?php if ($next <= $pages){?>
<?php print $sph_messages['Next']?>
<?php }?>
</div>
<?php }?>
<div class="divline">
</div>
I'm also not aware of a live PHP code editor, if you know of one please comment and share so I can add a link!
Presuming $from and $to are the result numbers, so you're displaying "Showing results 10 to 30 of 100" for example:
<div id="results">
<!-- results listing -->
<?php $adbreak = ($to - $from) / 2;
<?php foreach ($qry_results as $_key => $_row){
<?php if ($adbreak == 0) { ?>
<div id="results-adbreak">
<img src="buy-a-car.jpg" alt="one careful owner!" />
</div>
<?php }
$adbreak--;
?>
// rest of your code
This will put a div approximately (give or take one) half way down your page of results. You can obviously replace the ad with a call to whatever you want.
adding something like:
<?php $adbreak = ($to - $from) / 2;
<?php if ($adbreak < 5) $adbreak = -1; ?>
will ensure that it doesn't display at all if the results list is too short.
If you don't know $to and $from in advance, you can still do it, but you'll have to calculate the equivalent from the query result first.

Categories