php - 如何获得外部页面优惠券/代金券表格以在 OpenCart 中使用?

标签 php forms opencart coupon

我的 OpenCart 环境中有另一个页面,比方说关于我们的页面,它在下面有这些表格,假设用户在他们的购物车中有元素,这些表格应该有效但它们不:

在此输入您的优惠券代码:

<form action="index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="basket">
    <input type="text" value="" id="coupon" name="coupon"/>
    <input type="hidden" value="coupon" name="next"/>
    <input type="submit" class="button" value="Apply Coupon"/>
</form>

在此输入您的礼券代码:

<form action="index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="basket">
    <input type="text" value="" name="voucher"/>
    <input type="hidden" value="voucher" name="next"/>
    <input type="submit" class="button" value="Apply Voucher"/>
</form>

这是用于优惠券代码系统但它不起作用(此代码默认未编辑):

/catalog/controller/checkout/cart.php

// VOUCHER
// IF THE USER HAS ENTERED A VOUCHER
if (isset($this->request->post['voucher']) && $this->request->post['voucher']) {
    foreach ($this->request->post['voucher'] as $key) {
        if (isset($this->session->data['vouchers'][$key])) {
            unset($this->session->data['vouchers'][$key]);
        }
    }
}

最佳答案

优惠券/代金券/运费

这三个系统 block 是OpenCart中的模块。它们循环在一起,您可以编辑文件,例如制作一些空白或使用 if/else 语句仅显示某些模块。

您不能在 cart.tpl 中调用表单本身,它必须是:

<div class="right"> 
    <!-- eVoucher System -->
    <?php foreach ($modules as $module) { ?>
        <?=$module?>
    <?php } ?>
    <!-- eVoucher System --> 
</div>

Shipping/Voucher 和 Coupon 模块的文件位置

这将循环并显示模块 tpl 文件、运输、优惠券和凭证。他们的位置很奇怪

/catalog/view/theme/default/total/coupon.tpl
/catalog/view/theme/default/total/shipping.tpl
/catalog/view/theme/default/total/voucher.tpl

我们不会全部使用它们,因此我们已将优惠券和运费留空。优惠券表格如下:

<div>
  <div class="cart-heading"><?php echo $heading_title; ?></div>
  <div class="cart-content" id="coupon"><?php echo $entry_coupon; ?>&nbsp;
    <input type="text" name="coupon" value="<?php echo $coupon; ?>" />
    &nbsp;<a id="button-coupon" class="button"><span><?php echo $button_coupon; ?></span></a></div>
</div>
<script type="text/javascript">
<!--
//
//  jQuery dependent based on .post so make sure
//  your footer or header jQuery call is before this
//
$('#button-coupon').bind('click', function() {
    $.ajax({
        type: 'POST',
        url: 'index.php?route=total/coupon/calculate',
        data: $('#coupon :input'),
        dataType: 'json',       
        beforeSend: function() {
            $('.success, .warning').remove();
            $('#button-coupon').attr('disabled', true);
            $('#button-coupon').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
        },
        complete: function() {
            $('#button-coupon').attr('disabled', false);
            $('.wait').remove();
        },      
        success: function(json) {
            if (json['error']) {
                $('#basket').before('<div class="warning">' + json['error'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
            }

            if (json['redirect']) {
                location = json['redirect'];
            }
        }
    });
});
//-->
</script>

这就是这些文件的方式和位置,total 还有一个 Controller 和 coupon,所有其他模块都是 Controller 和标准 MVC 驱动的。

外部优惠券购物车表格

因此,如果您希望在外部页面上使用,提取 tpl 文件以及 $modules$module 循环,代码应该是:

(确保在 SEO URI 的情况下“斜线”index.php)

当然,例如,在您的“关于我们”页面上:

<strong>Please enter your coupon:</strong>

<form action="/index.php?route=total/coupon/calculate" method="post" enctype="multipart/form-data" id="basket">
    <input type="text" value="" id="coupon" name="coupon"/>
    <input type="hidden" value="coupon" name="next"/>
    <input type="submit" class="button" value="Apply Coupon"/>
</form>

关于php - 如何获得外部页面优惠券/代金券表格以在 OpenCart 中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12280666/

相关文章:

php - 将表单的文本字段映射到实体的 ArrayCollection

javascript - 协助js函数/警报删除表单输入

mysql - 使用内连接和子查询后 MYSQL 查询变慢

php - DateTime "first day of last month"第一天不返回

php - 防止JSON域欺骗

php - 如何使用 Google Sheets API v4 通过 PHP 在电子表格中创建新工作表或标签

php - Opencart Admin 如何将选项卡添加到模块中

php - Mysql NOW() 没有更新数据库

php - 如何将表单输入值传递给php函数

.htaccess - nginx 上的 OpenCart