我的产品页面上有一个发货信息计时器,如果我的库存为零,我怎么能不显示它,我正在运行opencart 1.5.5.1。这是我的档案: 目录\ controller \ product \ product.php
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
这是coundown计时器代码 目录/视图/主题/ journal2 /模板/产品/ product.tpl
<div class="cdbox";>
<span class="cdbox_2";>
<img src="../image/data/delivery_van_sml.png">
</span>
<span class="cdbox_0";>
Order Within the next </span>
<br>
<span id="countdownTimer">
00:00.<small>
00</small>
</span>
<p>
<span class="cdbox_1";>
We guarantee same-day Shipping (Monday - Friday) Before 2pm</p>
</span>
</div>
<script type="text/javascript" src="catalog/view/theme/journal2/js/caseSensitiveCountdownTimer.js">
</script>
如果产品数量为零,我不想显示脚本。任何人都可以帮我解决这个问题。
答案 0 :(得分:0)
只需向控制器添加一个股票标志(如果没有其他方法可以在tpl中获取它)将您的HTML / JS片段包装在PHP条件语句中。
尝试以下内容:
未经过测试
在控制器中:
$this->data['in_stock'] = false;
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
$this->data['in_stock'] = true;
} else {
$this->data['stock'] = $this->language->get('text_instock');
$this->data['in_stock'] = true;
}
在tpl:
<?php if($in_stock) { ?>
<div class="cdbox";>
<span class="cdbox_2";>
<img src="../image/data/delivery_van_sml.png">
</span>
<span class="cdbox_0";>
Order Within the next </span>
<br>
<span id="countdownTimer">
00:00.<small>
00</small>
</span>
<p>
<span class="cdbox_1";>
We guarantee same-day Shipping (Monday - Friday) Before 2pm</p>
</span>
</div>
<script type="text/javascript" src="catalog/view/theme/journal2/js/caseSensitiveCountdownTimer.js">
</script>
<?php } ?>