Skip to content

Commit

Permalink
Module updated to Opencart 3.0.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
condor2 committed Feb 1, 2021
1 parent 49fd27d commit 65f9f8d
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 5 deletions.
File renamed without changes.
50 changes: 50 additions & 0 deletions 3.0.x.x/install.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Munimal order amount</name>
<code>minimal_order_amount</code>
<version>0.3</version>

<file path="catalog/controller/checkout/checkout.php">
<operation>
<search><![CDATA[
// Validate minimum quantity requirements.
]]></search>
<add position="before"><![CDATA[
//start module minimal_order_amount
$this->load->model('setting/setting');
$minimal_order_amount = $this->model_setting_setting->getSetting('module_minimal_order_amount');
if (@$minimal_order_amount['module_minimal_order_amount_value_amount_value'] && $this->cart->getSubtotal() < $minimal_order_amount['module_minimal_order_amount_value_amount_value']){
$this->session->data['error'] = str_replace('%s', $minimal_order_amount['module_minimal_order_amount_value_amount_value'], $minimal_order_amount['module_minimal_order_amount_value_error_msg']);
$this->response->redirect($this->url->link('checkout/cart'));
}
//end module minimal_order_amount
]]></add>
</operation>
</file>

<file path="catalog/controller/checkout/cart.php">
<operation>
<search><![CDATA[
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
]]></search>
<add position="after"><![CDATA[
///start module minimal_order_amount
$this->load->model('setting/setting');
$minimal_order_amount = $this->model_setting_setting->getSetting('module_minimal_order_amount');
//end module minimal_order_amount
]]></add>
</operation>
<operation>
<search><![CDATA[
unset($this->session->data['error']);
]]></search>
<add position="after"><![CDATA[
//start module minimal_order_amount
} elseif (@$minimal_order_amount['module_minimal_order_amount_value_amount_value'] && $this->cart->getSubtotal() < $minimal_order_amount['module_minimal_order_amount_value_amount_value']) {
$this->load->language('module/minimal_order_amount');
$data['error_warning'] = str_replace('%s', $minimal_order_amount['module_minimal_order_amount_value_amount_value'], $minimal_order_amount['module_minimal_order_amount_value_error_msg']);
//end module minimal_order_amount]]></add>
</operation>
</file>
</modification>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
class ControllerExtensionModuleMinimalOrderAmount extends Controller {
private $error = array();

public function index() {
$this->load->language('extension/module/minimal_order_amount');
$this->load->model('setting/setting');

$this->document->setTitle($this->language->get('heading_title'));

if ($this->request->server['REQUEST_METHOD'] == 'POST') {
$data['value_amount_value'] = $this->request->post['module_minimal_order_amount_value_amount_value'];
$data['value_error_msg'] = $this->request->post['module_minimal_order_amount_value_error_msg'];

if ($this->validate()) {
$this->model_setting_setting->editSetting('module_minimal_order_amount', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true));
}
} else {
$minimal_order_amount = $this->model_setting_setting->getSetting('module_minimal_order_amount');

$data['value_amount_value'] = (isset($minimal_order_amount['module_minimal_order_amount_value_amount_value'])) ? $minimal_order_amount['module_minimal_order_amount_value_amount_value'] : 0;
$data['value_error_msg'] = (isset($minimal_order_amount['module_minimal_order_amount_value_error_msg'])) ? $minimal_order_amount['module_minimal_order_amount_value_error_msg'] : $this->language->get('value_error_msg');
}

$data['store_currency'] = $this->config->get('config_currency');

if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}

if (isset($this->error['amount_value'])) {
$data['amount_value'] = $this->error['amount_value'];
} else {
$data['amount_value'] = '';
}

if (isset($this->error['error_msg'])) {
$data['error_msg'] = $this->error['error_msg'];
} else {
$data['error_msg'] = '';
}

$data['breadcrumbs'] = array();

$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
);

$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
);

$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/minimal_order_amount', 'user_token=' . $this->session->data['user_token'], true),
);

$data['action'] = $this->url->link('extension/module/minimal_order_amount', 'user_token=' . $this->session->data['user_token'], true);

$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);

$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('extension/module/minimal_order_amount', $data));

}

protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/minimal_order_amount')) {
$this->error['warning'] = $this->language->get('error_permission');
}

if (!$this->request->post['module_minimal_order_amount_value_amount_value']) {
$this->error['amount_value'] = $this->language->get('error_amount_value');
}

if (!is_numeric($this->request->post['module_minimal_order_amount_value_amount_value'])) {
$this->error['amount_value'] = $this->language->get('error_int_amount_value');
}

if (!$this->request->post['module_minimal_order_amount_value_error_msg']) {
$this->error['error_msg'] = $this->language->get('error_error_msg');
}

return !$this->error;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// Heading
$_['heading_title'] = 'Minimal Order Amount';
$_['heading_label'] = 'Edit minimal amount for your orders';

// Text
$_['text_extension'] = 'Extensions';
$_['text_success'] = 'Success: You have modified minimal order amount!';

// Entry
$_['entry_currency'] = 'Store Currency:';
$_['entry_amount_value'] = 'Minimal order amount:';
$_['entry_error_msg'] = 'Warning message:';

//Button
$_['button_save'] = 'Save';
$_['button_cancel'] = 'Cancel';

//Other
$_['value_error_msg'] = 'You must have an order with a minimum of %s USD to place your order!';
$_['tip_error_msg'] = 'You can use "%s" as a placeholder for you minimal amount value';

// Errors
$_['error_permission'] = 'Warning: You do not have permission to change minimal order amount!';
$_['error_amount_value'] = 'Warning: "minimal order amount" is Required';
$_['error_int_amount_value'] = 'Warning: "minimal order amount" must be a Numeric';
$_['error_error_msg'] = 'Warning: "message" value is Required';


Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{ header }}{{ column_left }}
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-module" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
<h1>{{ heading_title }}</h1>
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<div class="container-fluid">
{% if error_warning %}
<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> {{ heading_label }}</h3>
</div>
<div class="panel-body">
<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">{{ entry_currency }}</label>
<div class="col-sm-10">
<input type="text" disabled="disabled" value="{{ store_currency }}" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">{{ entry_amount_value }}</label>
<div class="col-sm-10">
<input type="text" value="{{ value_amount_value }}" class="form-control" name="module_minimal_order_amount_value_amount_value" />
{% if amount_value %}
<div class="text-danger">{{ amount_value }}</div>
{% endif %}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">{{ entry_error_msg }}</label>
<div class="col-sm-10">
<textarea name="module_minimal_order_amount_value_error_msg" cols="40" rows="5" placeholder="{{ placeholder_error_msg }}" class="form-control">{{ value_error_msg }}</textarea>
<p>{{ tip_error_msg }}</p>
{% if error_msg %}
<div class="text-danger">{{ error_msg }}</div>
{% endif %}
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{{ footer }}
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Simple Minimum Order Amount plugin for Opencart 2
Tested with Opencart 2.3.0.2
# Simple Minimum Order Amount plugin for Opencart

**User Notification:**
![frontend](http://i.imgur.com/llMMieV.png)
Expand All @@ -9,7 +8,7 @@ Tested with Opencart 2.3.0.2

### Installation

- Upload files from **upload** dir
- In Admin go to *Extension Installer* and upload **minimal_order_cost.ocmod.xml**. Don't forget to go to *Extension -> Modification* and refresh cache.
- Go to <a href="https://github.com/condor2/oc_minimum_order_amount/releases">Releases</a> and download the corresponding version with your opencart version
- In Admin go to *Extension Installer* and upload **minimal_order_cost_xxxx.ocmod.zip**. Don't forget to go to *Extension -> Modification* and refresh cache.
- Go to *User -> User Groups* and check permissions for the module
- Go to *Extensions*, install **Minimal Order Amount** module and change its settings.
- Go to *Extensions*, install **Minimal Order Amount** module and change its settings.

0 comments on commit 65f9f8d

Please sign in to comment.