简体   繁体   English

如果产品数量为零,则不显示“打开购物车”

[英]If product quantity is zero display none “Open cart”

I have a shipping info timer on my product page, how can i not display it if my stock is zero, i am running opencart 1.5.5.1. 我的产品页面上有一个运送信息计时器,如果我的库存为零,我正在运行opencart 1.5.5.1,怎么不能显示它。 this is my file : catalog\\controller\\product\\product.php 这是我的文件:catalog \\ 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');
            }

This is the coundown timer code catalog/view/theme/journal2/template/product/product.tpl 这是计时器的代码目录/视图/主题/新闻2 /模板/product/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&nbsp;&nbsp;</span>
<br>
<span id="countdownTimer">
00:00.<small>
00</small>
</span>
      <p>
<span class="cdbox_1";>
We guarantee same-day Shipping (Monday&nbsp;&#45;&nbsp;Friday) Before 2pm</p>
</span>
</div>
<script type="text/javascript" src="catalog/view/theme/journal2/js/caseSensitiveCountdownTimer.js">
</script>

If product quantity is zero i do not want to show the Script. 如果产品数量为零,我不想显示脚本。 Can anyone help me solve this please. 谁能帮我解决这个问题。

Just add a stock flag to controller (if there is no other way to get it in tpl) wrap your HTML/JS snippet in PHP conditional statement. 只需向控制器添加一个stock标志(如果没有其他方法可以将其放入tpl中),则将您的HTML / JS代码片段包装在PHP条件语句中。

Try something like below: 尝试以下内容:

Not tested 未测试

In controller: 在控制器中:

 $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;
        }

In tpl: 在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&nbsp;&nbsp;</span>
<br>
<span id="countdownTimer">
00:00.<small>
00</small>
</span>
      <p>
<span class="cdbox_1";>
We guarantee same-day Shipping (Monday&nbsp;&#45;&nbsp;Friday) Before 2pm</p>
</span>
</div>
<script type="text/javascript" src="catalog/view/theme/journal2/js/caseSensitiveCountdownTimer.js">
</script>

<?php } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 产品页面中显示数量变化的产品总数和购物车小计 - Display product total and cart subtotal on quantity change in WooCommerce product page 产品库存数量 - 购物车中的产品数量 - Product Stock Quantity - No of Products in Cart 如何使用 opencart 3 在特色/产品列表内容中显示/显示产品购物车数量 - How to Show/Display Product Cart Quantity in Featured/Product Listing Content using opencart 3 获取 WooCommerce Ajax 上的产品 ID、名称和数量添加到购物车以显示通知 - Get product id, name and quantity on WooCommerce Ajax added to cart to display a notice Prestashop将产品添加到购物车奇数 - Prestashop add product to cart strange quantity 将定制产品价格乘以 WooCommerce 购物车中的数量 - Multiply custom product price by the quantity in WooCommerce cart 我的电子商务购物车中产品数量未更新 - Product quantity is not updating in my ecommerce cart Woocommerce将购物车中特定产品的数量相乘 - Woocommerce multiply the quantity of a specific product in cart "基于数量计算的产品类别的购物车折扣" - Cart discount for a product category based on quantity calculations 从购物车更新产品表中的库存数量 - Updating stocks quantity in Product Table from Cart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM