基于总订单的折扣
Discount based on total order
当我设定的数量达到时,下面的代码将被激活。
但是如果我设置的数量是三件符合条件的折扣,在这种情况下,如果任何客户购买四件产品,它仍然只提供三件产品的折扣。
就等另外三个打折了。但是我想如果我设定的最低数量满足,那么它会根据我设定的百分比给总订单折扣。
我不会编码。任何人都可以帮助通过编码修复它吗?
我是 Whosebug 的新手。如果我的解释能力有误,还请大家见谅。
这是代码。
admin/controller/total/total_discount.php
<?php
class ControllerTotalTotalDiscount extends Controller {
private $error = array();
public function index() {
$this->load->language('total/total_discount');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
$this->model_setting_setting->editSetting('total_discount', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL'));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['text_each'] = $this->language->get('text_each');
$data['text_once'] = $this->language->get('text_once');
$data['entry_count'] = $this->language->get('entry_count');
$data['entry_percent'] = $this->language->get('entry_percent');
$data['entry_each'] = $this->language->get('entry_each');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['help_count'] = $this->language->get('help_count');
$data['help_percent'] = $this->language->get('help_percent');
$data['help_each'] = $this->language->get('help_each');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_total'),
'href' => $this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('total/total_discount', 'token=' . $this->session->data['token'], 'SSL')
);
$data['action'] = $this->url->link('total/total_discount', 'token=' . $this->session->data['token'], 'SSL');
$data['cancel'] = $this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL');
if (isset($this->request->post['total_discount_count'])) {
$data['total_discount_count'] = $this->request->post['total_discount_count'];
} else {
$data['total_discount_count'] = $this->config->get('total_discount_count');
}
if (isset($this->request->post['total_discount_percent'])) {
$data['total_discount_percent'] = $this->request->post['total_discount_percent'];
} else {
$data['total_discount_percent'] = $this->config->get('total_discount_percent');
}
if (isset($this->request->post['total_discount_each_count'])) {
$data['total_discount_each_count'] = $this->request->post['total_discount_each_count'];
} else {
$data['total_discount_each_count'] = $this->config->get('total_discount_each_count');
}
if (isset($this->request->post['total_discount_status'])) {
$data['total_discount_status'] = $this->request->post['total_discount_status'];
} else {
$data['total_discount_status'] = $this->config->get('total_discount_status');
}
if (isset($this->request->post['total_discount_sort_order'])) {
$data['total_discount_sort_order'] = $this->request->post['total_discount_sort_order'];
} else {
$data['total_discount_sort_order'] = $this->config->get('total_discount_sort_order');
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('total/total_discount.tpl', $data));
}
private function validate() {
if (!$this->user->hasPermission('modify', 'total/total_discount')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
?>
admin>language/English/total/total_discount.php
<?php
// Heading
$_['heading_title'] = 'Percent Discount for Big Orders';
// Text
$_['text_edit'] = 'Edit';
$_['text_total'] = 'Order Totals';
$_['text_success'] = 'Success: You have modified Discount total!';
$_['text_each'] = 'Each';
$_['text_once'] = 'Once';
// Entry
$_['entry_count'] = 'Products Count:';
$_['entry_percent'] = 'Percent Discount:';
$_['entry_each'] = 'Discount:';
$_['entry_status'] = 'Status:';
$_['entry_sort_order'] = 'Sort Order:';
//help
$_['help_count'] = 'The products count the order must reach before the discount becomes active.';
$_['help_percent'] = 'of the cheapest product in the order.';
$_['help_each'] = 'for Each X products or just Once.';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Discount total!';
?>
admin/view/template/total/total_discount.tpl
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-discount" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-discount" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-count"><span data-toggle="tooltip" title="<?php echo $help_count; ?>"><?php echo $entry_count; ?></span></label>
<div class="col-sm-10">
<input type="text" name="total_discount_count" value="<?php echo $total_discount_count; ?>" placeholder="<?php echo $entry_count; ?>" id="input-count" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-percent"><span data-toggle="tooltip" title="<?php echo $help_percent; ?>"><?php echo $entry_percent; ?> <b>%</b></span></label>
<div class="col-sm-10">
<input type="text" name="total_discount_percent" value="<?php echo $total_discount_percent; ?>" placeholder="<?php echo $entry_percent; ?>" id="input-percent" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-each"><span data-toggle="tooltip" title="<?php echo $help_each; ?>"><?php echo $entry_each; ?></span></label>
<div class="col-sm-10">
<select name="total_discount_each_count" id="input-each" class="form-control">
<?php if ($total_discount_each_count) { ?>
<option value="1" selected="selected"><?php echo $text_each; ?></option>
<option value="0"><?php echo $text_once; ?>></option>
<?php } else { ?>
<option value="1"><?php echo $text_each; ?></option>
<option value="0" selected="selected"><?php echo $text_once; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
<div class="col-sm-10">
<select name="total_discount_status" id="input-status" class="form-control">
<?php if ($total_discount_status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-sort-order"><?php echo $entry_sort_order; ?></label>
<div class="col-sm-10">
<input type="text" name="total_discount_sort_order" value="<?php echo $total_discount_count; ?>" placeholder="<?php echo $entry_sort_order; ?>" id="input-sort-order" class="form-control" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php echo $footer; ?>
catalog/language/english/total/total_discount.php
<?php
$_['text_total_discount'] = 'Discount';
?>
catelog/model/total/total_discount.php
<?php
class ModelTotalTotalDiscount extends Model {
public function getTotal(&$total_data, &$total, &$taxes) {
$count = 0;
$price = 0;
$prices = array();
foreach ($this->cart->getProducts() as $product) {
$count += $product['quantity'];
for ($i = 0; $i < $product['quantity']; $i++) {
$prices[] = $product['price'];
}
}
sort($prices);
if ($count >= (int)$this->config->get('total_discount_count')) {
if ($this->config->get('total_discount_each_count')) {
$items_count = floor($count / (int)$this->config->get('total_discount_count'));
for ($i = 0; $i < $items_count; $i++) {
$price += $prices[$i];
}
} else {
$price += $prices[0];
}
$this->load->language('total/total_discount');
$price *= (float)$this->config->get('total_discount_percent') / 100;
$total_data[] = array(
'code' => 'total_discount',
'title' => $this->language->get('text_total_discount'),
'text' => $this->currency->format(-$price),
'value' => -$price,
'sort_order' => $this->config->get('total_discount_sort_order')
);
$total -= $price;
}
}
}
?>
这是预期的行为 - 如果您购买 3 件产品,您可以从最便宜的产品中获得 %age,所以当然,如果您想要两件产品的折扣,您将不得不购买 6 件。
但是您想要这样,如果您购买 3 件或更多产品,每多购买一件产品都可以享受折扣? (例如,如果您购买 4 件,则折扣适用于其中 2 件,如果您购买 5 件,则折扣适用于 3 件,依此类推?)
如果你不熟悉编码,我真的不建议你去搞乱这个(或者在你这样做之前绝对保留一个备份)但我会做的修改是在 catalog/model/total/total_discount.php
最后一个文件中您发布了:
换行
$items_count = floor($count / (int)$this->config->get('total_discount_count'));
至
if ($count > (int)$this->config->get('total_discount_count')) {
$items_count = $count - (int)$this->config->get('total_discount_count');
} else {
$items_count = 0;
}
结果是,如果您说 3 件产品作为折扣计数,则应用折扣的产品数量将为购物车中的产品数量减去 3。(即第 4、5、6 等. 将有折扣)
编辑
请重新阅读您的问题,我现在了解到如果至少订购了 X 件产品,您希望对整个订单应用折扣?
如果是,则将上面的同一行更改为
if ($count >= (int)$this->config->get('total_discount_count')) {
$items_count = $count;
} else {
$items_count = 0;
}
应该能达到预期的效果。不过,这不会影响邮费或任何其他额外费用。
当我设定的数量达到时,下面的代码将被激活。
但是如果我设置的数量是三件符合条件的折扣,在这种情况下,如果任何客户购买四件产品,它仍然只提供三件产品的折扣。
就等另外三个打折了。但是我想如果我设定的最低数量满足,那么它会根据我设定的百分比给总订单折扣。
我不会编码。任何人都可以帮助通过编码修复它吗?
我是 Whosebug 的新手。如果我的解释能力有误,还请大家见谅。
这是代码。
admin/controller/total/total_discount.php
<?php
class ControllerTotalTotalDiscount extends Controller {
private $error = array();
public function index() {
$this->load->language('total/total_discount');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
$this->model_setting_setting->editSetting('total_discount', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL'));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['text_each'] = $this->language->get('text_each');
$data['text_once'] = $this->language->get('text_once');
$data['entry_count'] = $this->language->get('entry_count');
$data['entry_percent'] = $this->language->get('entry_percent');
$data['entry_each'] = $this->language->get('entry_each');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['help_count'] = $this->language->get('help_count');
$data['help_percent'] = $this->language->get('help_percent');
$data['help_each'] = $this->language->get('help_each');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_total'),
'href' => $this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('total/total_discount', 'token=' . $this->session->data['token'], 'SSL')
);
$data['action'] = $this->url->link('total/total_discount', 'token=' . $this->session->data['token'], 'SSL');
$data['cancel'] = $this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL');
if (isset($this->request->post['total_discount_count'])) {
$data['total_discount_count'] = $this->request->post['total_discount_count'];
} else {
$data['total_discount_count'] = $this->config->get('total_discount_count');
}
if (isset($this->request->post['total_discount_percent'])) {
$data['total_discount_percent'] = $this->request->post['total_discount_percent'];
} else {
$data['total_discount_percent'] = $this->config->get('total_discount_percent');
}
if (isset($this->request->post['total_discount_each_count'])) {
$data['total_discount_each_count'] = $this->request->post['total_discount_each_count'];
} else {
$data['total_discount_each_count'] = $this->config->get('total_discount_each_count');
}
if (isset($this->request->post['total_discount_status'])) {
$data['total_discount_status'] = $this->request->post['total_discount_status'];
} else {
$data['total_discount_status'] = $this->config->get('total_discount_status');
}
if (isset($this->request->post['total_discount_sort_order'])) {
$data['total_discount_sort_order'] = $this->request->post['total_discount_sort_order'];
} else {
$data['total_discount_sort_order'] = $this->config->get('total_discount_sort_order');
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('total/total_discount.tpl', $data));
}
private function validate() {
if (!$this->user->hasPermission('modify', 'total/total_discount')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
?>
admin>language/English/total/total_discount.php
<?php
// Heading
$_['heading_title'] = 'Percent Discount for Big Orders';
// Text
$_['text_edit'] = 'Edit';
$_['text_total'] = 'Order Totals';
$_['text_success'] = 'Success: You have modified Discount total!';
$_['text_each'] = 'Each';
$_['text_once'] = 'Once';
// Entry
$_['entry_count'] = 'Products Count:';
$_['entry_percent'] = 'Percent Discount:';
$_['entry_each'] = 'Discount:';
$_['entry_status'] = 'Status:';
$_['entry_sort_order'] = 'Sort Order:';
//help
$_['help_count'] = 'The products count the order must reach before the discount becomes active.';
$_['help_percent'] = 'of the cheapest product in the order.';
$_['help_each'] = 'for Each X products or just Once.';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Discount total!';
?>
admin/view/template/total/total_discount.tpl
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-discount" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-discount" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-count"><span data-toggle="tooltip" title="<?php echo $help_count; ?>"><?php echo $entry_count; ?></span></label>
<div class="col-sm-10">
<input type="text" name="total_discount_count" value="<?php echo $total_discount_count; ?>" placeholder="<?php echo $entry_count; ?>" id="input-count" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-percent"><span data-toggle="tooltip" title="<?php echo $help_percent; ?>"><?php echo $entry_percent; ?> <b>%</b></span></label>
<div class="col-sm-10">
<input type="text" name="total_discount_percent" value="<?php echo $total_discount_percent; ?>" placeholder="<?php echo $entry_percent; ?>" id="input-percent" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-each"><span data-toggle="tooltip" title="<?php echo $help_each; ?>"><?php echo $entry_each; ?></span></label>
<div class="col-sm-10">
<select name="total_discount_each_count" id="input-each" class="form-control">
<?php if ($total_discount_each_count) { ?>
<option value="1" selected="selected"><?php echo $text_each; ?></option>
<option value="0"><?php echo $text_once; ?>></option>
<?php } else { ?>
<option value="1"><?php echo $text_each; ?></option>
<option value="0" selected="selected"><?php echo $text_once; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
<div class="col-sm-10">
<select name="total_discount_status" id="input-status" class="form-control">
<?php if ($total_discount_status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-sort-order"><?php echo $entry_sort_order; ?></label>
<div class="col-sm-10">
<input type="text" name="total_discount_sort_order" value="<?php echo $total_discount_count; ?>" placeholder="<?php echo $entry_sort_order; ?>" id="input-sort-order" class="form-control" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php echo $footer; ?>
catalog/language/english/total/total_discount.php
<?php
$_['text_total_discount'] = 'Discount';
?>
catelog/model/total/total_discount.php
<?php
class ModelTotalTotalDiscount extends Model {
public function getTotal(&$total_data, &$total, &$taxes) {
$count = 0;
$price = 0;
$prices = array();
foreach ($this->cart->getProducts() as $product) {
$count += $product['quantity'];
for ($i = 0; $i < $product['quantity']; $i++) {
$prices[] = $product['price'];
}
}
sort($prices);
if ($count >= (int)$this->config->get('total_discount_count')) {
if ($this->config->get('total_discount_each_count')) {
$items_count = floor($count / (int)$this->config->get('total_discount_count'));
for ($i = 0; $i < $items_count; $i++) {
$price += $prices[$i];
}
} else {
$price += $prices[0];
}
$this->load->language('total/total_discount');
$price *= (float)$this->config->get('total_discount_percent') / 100;
$total_data[] = array(
'code' => 'total_discount',
'title' => $this->language->get('text_total_discount'),
'text' => $this->currency->format(-$price),
'value' => -$price,
'sort_order' => $this->config->get('total_discount_sort_order')
);
$total -= $price;
}
}
}
?>
这是预期的行为 - 如果您购买 3 件产品,您可以从最便宜的产品中获得 %age,所以当然,如果您想要两件产品的折扣,您将不得不购买 6 件。
但是您想要这样,如果您购买 3 件或更多产品,每多购买一件产品都可以享受折扣? (例如,如果您购买 4 件,则折扣适用于其中 2 件,如果您购买 5 件,则折扣适用于 3 件,依此类推?)
如果你不熟悉编码,我真的不建议你去搞乱这个(或者在你这样做之前绝对保留一个备份)但我会做的修改是在 catalog/model/total/total_discount.php
最后一个文件中您发布了:
换行
$items_count = floor($count / (int)$this->config->get('total_discount_count'));
至
if ($count > (int)$this->config->get('total_discount_count')) {
$items_count = $count - (int)$this->config->get('total_discount_count');
} else {
$items_count = 0;
}
结果是,如果您说 3 件产品作为折扣计数,则应用折扣的产品数量将为购物车中的产品数量减去 3。(即第 4、5、6 等. 将有折扣)
编辑
请重新阅读您的问题,我现在了解到如果至少订购了 X 件产品,您希望对整个订单应用折扣?
如果是,则将上面的同一行更改为
if ($count >= (int)$this->config->get('total_discount_count')) {
$items_count = $count;
} else {
$items_count = 0;
}
应该能达到预期的效果。不过,这不会影响邮费或任何其他额外费用。