如何获得外部页面优惠券/凭单表格才能在OpenCart中使用? [英] How do I get an external page coupon/voucher form to work in OpenCart?

查看:85
本文介绍了如何获得外部页面优惠券/凭单表格才能在OpenCart中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的OpenCart环境中还有另一个页面,假设关于我们"页面在下面有以下表格,假设用户的购物车中有商品,则这些表格应该可以,但不能:

I have another page in my OpenCart environment, let say the about us page, which has these forms below, assuming the user has items in their cart, these forms should work but they do not:

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

Enter your coupon code here:

<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>

在此处输入您的礼券代码:

Enter your gift voucher code here:

<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>

这是针对优惠券代码系统的,但不起作用(默认情况下,此代码未编辑):

This is for the voucher code system but it does not work (this code is default not edited):

/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]);
        }
    }
}

推荐答案

优惠券/优惠券/运费

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

Coupons/Vouchers/Shipping

These three system blocks are modules in OpenCart. They are looped together, you can edit the files, example make some blank or use an if/else statement to show only certain modules.

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

You cannot call the form itself in the cart.tpl, it must be:

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

运输/凭单和优惠券模块的文件位置

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

File locations of Shipping/Voucher and Coupon modules

This will loop and show the module tpl files, shipping, coupon and voucher. They are strangely located

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

我们不会全部使用它们,因此我们已清空了凭证和运费.优惠券形式如下:

We do not use them all so we have blanked the voucher and shipping. Coupon form looks like:

<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还具有一个控制器和coupon,所有其他模块都是由控制器和标准MVC驱动的.

So that is how and where these files are, the total also has a controller and coupon and all the other modules are controller and standard MVC driven.

因此,要想在外部页面上使用,请拔出tpl文件以及$modules$module循环,代码应为:

So for usage on external pages as you wished, plucking for the tpl files and the $modules and $module loop, code should be:

(如果使用SEO URI,请确保斜杠" index.php)

(making sure "slash" index.php in case of SEO URI)

当然,在您的关于我们"页面上:

Sure, example, on your about us page:

<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>

这篇关于如何获得外部页面优惠券/凭单表格才能在OpenCart中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆