Skip to content

Commit

Permalink
Merge pull request #2 from JoaoRibeiroDeveloper/master
Browse files Browse the repository at this point in the history
Fix in OpenCart Version 3.0
  • Loading branch information
webmaniabr authored Jul 9, 2024
2 parents ccd5863 + 6433685 commit 7237925
Show file tree
Hide file tree
Showing 11 changed files with 1,778 additions and 1,614 deletions.
50 changes: 37 additions & 13 deletions 3.0/admin/controller/extension/module/webmaniabrnfe.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function index() {
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('webmaniabrnfe', $this->request->post);

if (isset($this->request->post['module_webmaniabrnfe_status'])) {
if ($this->request->post['module_webmaniabrnfe_status'] === "1") $this->activeModule();
else $this->disableModule();
}
// Displays the success text on data save
$this->session->data['success'] = $this->language->get('text_success');

Expand Down Expand Up @@ -152,6 +156,7 @@ public function index() {

}

$data['module_webmaniabrnfe_status'] = isset($this->request->post['module_webmaniabrnfe_status']) ? $this->request->post['module_webmaniabrnfe_status'] : $this->config->get('module_webmaniabrnfe_status');
$data['webmaniabrnfe_carriers_d'] = json_decode(stripslashes(html_entity_decode($data['webmaniabrnfe_carriers'])), true);

$data['header'] = $this->load->controller('common/header');
Expand Down Expand Up @@ -213,7 +218,7 @@ public function cleanCache(){
'catalog/product/edit',
'sale/order/info',
'sale/order/edit',
'module/webmaniabrnfe'
'extension/module/webmaniabrnfe'
])
){

Expand Down Expand Up @@ -251,16 +256,8 @@ public function cleanCache(){
*/
public function install(){

// Install vqMod file
$filename = 'nfe.ocmod.xml';
$dest = __DIR__.'/../../../../vqmod/xml/';
$file_copy = __DIR__.'/../nfe/xml/nfe.ocmod.xml';
$oc_mod_exist = file_exists($dest.$filename);

// Copy vqMod
if ($oc_mod_exist === false){
copy($file_copy, $dest.$filename);
}
//Activate the module and place the XML in VQMod
$this->activeModule();

// Try to insert Required custom Fields on Install
$this->getCustomFieldsIds( $this );
Expand Down Expand Up @@ -349,13 +346,40 @@ public function install(){

public function uninstall(){

$this->load->model('extension/module/webmaniabrnfe');

// Delete vqMod file
$filepath = __DIR__.'/../../../../vqmod/xml/nfe.ocmod.xml';
$filepath = __DIR__ . '/../../../../vqmod/xml/nfe.ocmod.xml';
$oc_mod_exist = file_exists($filepath);
if($oc_mod_exist === true){
if ($oc_mod_exist === true) {
unlink($filepath);
}

$this->model_extension_module_webmaniabrnfe->setModuleStatus('0');

}

private function disableModule()
{
$this->uninstall();
}

private function activeModule()
{
$this->load->model('extension/module/webmaniabrnfe');

// Install vqMod file
$filename = 'nfe.ocmod.xml';
$dest = __DIR__ . '/../../../../vqmod/xml/';
$file_copy = __DIR__ . '/../nfe/xml/nfe.ocmod.xml';
$oc_mod_exist = file_exists($dest . $filename);

// Copy vqMod
if ($oc_mod_exist === false) {
copy($file_copy, $dest . $filename);
}

$this->model_extension_module_webmaniabrnfe->setModuleStatus('1');
}

/* Function that validates the data when Save Button is pressed */
Expand Down
125 changes: 96 additions & 29 deletions 3.0/admin/controller/extension/nfe/xml/nfe.ocmod.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</operation>
<operation info="Add Backend Info">
<search position="before" ><![CDATA[
// Payment Address
if ($order_info['payment_address_format']) {
]]></search>
<add><![CDATA[
$custom_fields_ids = $this->load->controller('extension/module/webmaniabrnfe/getCustomFieldsIds');
Expand Down Expand Up @@ -108,7 +108,7 @@
</operation>
<operation info="Add Backend Info">
<search position="before" ><![CDATA[
// Shipping Address
if ($order_info['shipping_address_format']) {
]]></search>
<add><![CDATA[
$custom_fields_ids = $this->load->controller('extension/module/webmaniabrnfe/getCustomFieldsIds');
Expand All @@ -135,6 +135,21 @@
'complemento' => $complemento,
]]></add>
</operation>
<operation info="Insert number and complement into the format of the address details of the order">
<search position="replace" ><![CDATA[
. '{address_1}' .
]]></search>
<add><![CDATA[. '{address_1} {address_number} {complemento}' .]]></add>
</operation>
<operation info="Insert number and complement into the find of the address details of the order">
<search position="after" ><![CDATA[
'{address_1}',
]]></search>
<add><![CDATA[
'{address_number}',
'{complemento}',
]]></add>
</operation>
<operation info="Get Nfe Info">
<search position="before" ><![CDATA[
$this->response->setOutput($this->load->view('sale/order_info', $data));
Expand Down Expand Up @@ -317,6 +332,22 @@
{% endif %}
]]></add>
</operation>
<operation info="Disable the NF-e action button">
<search position="after"><![CDATA[
$('#button-shipping, #button-invoice').prop('disabled', true);
]]></search>
<add><![CDATA[
$('#button-emitir-nfe, #button-imprimir-danfe, #button-imprimir-danfe-simples, #button-imprimir-danfe-etiqueta').prop('disabled', true);
]]></add>
</operation>
<operation info="Enable the NF-e action button">
<search position="after"><![CDATA[
$('#button-invoice').prop('disabled', false);
]]></search>
<add><![CDATA[
$('#button-emitir-nfe, #button-imprimir-danfe, #button-imprimir-danfe-simples, #button-imprimir-danfe-etiqueta').prop('disabled', false);
]]></add>
</operation>
</file>

<file name="admin/controller/common/footer.php">
Expand All @@ -327,6 +358,7 @@
<add><![CDATA[
if(isset($this->request->get['route'])){
$route = $this->request->get['route'];
$data['route'] = $route;
if($route == 'customer/customer/add' || $route == 'customer/customer/edit' || $route == 'sale/order/add'){
$data['run_script'] = true;
$this->load->model('setting/setting');
Expand Down Expand Up @@ -365,11 +397,10 @@
<file name="admin/view/template/common/footer.twig">
<operation info="Include module CSS and JS">
<search position="before" ><![CDATA[
<footer id="footer">{{ text_footer }}<br />{{ text_version }}</footer></div>
<footer id="footer">
]]></search>
<add><![CDATA[
{{ app.request.parameter.get('route') }}
{% if app.request.parameter.get('route') is defined and app.request.parameter.get('route') == 'extension/module/webmaniabrnfe' %}
{% if route is defined and route == 'extension/module/webmaniabrnfe' %}
<script type="text/javascript" src="./view/javascript/wmbr_scripts.js"></script>
{% endif %}
Expand Down Expand Up @@ -852,7 +883,7 @@
</file>


<file name="catalog/view/theme/*/template/account/register.twig">
<file name="catalog/view/theme/*/template/checkout/register.twig">
<operation info="Insert loading div">
<search position="after"><![CDATA[
<fieldset id="address">
Expand Down Expand Up @@ -955,7 +986,7 @@
$value = $this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']];
$valid = $this->load->controller('extension/module/webmaniabrnfe/is_cpf', array($value));
if($valid === false){
$this->error['custom_field'][$custom_field['custom_field_id']] = 'CPF inválido!';
$json['error']['custom_field' . $custom_field['custom_field_id']] = 'CPF inválido!';
continue;
}
}
Expand All @@ -968,7 +999,7 @@
$value = $this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']];
$valid = $this->load->controller('extension/module/webmaniabrnfe/is_cnpj', array($value));
if($valid === false){
$this->error['custom_field'][$custom_field['custom_field_id']] = 'CNPJ inválido!';
$json['error']['custom_field' . $custom_field['custom_field_id']] = 'CNPJ inválido!';
continue;
}
}
Expand Down Expand Up @@ -1075,6 +1106,26 @@

</file>

<file name="catalog/view/theme/default/template/account/address_form.twig">
<operation info="Assign error div for address 2">
<search position="after"><![CDATA[
<input type="text" name="address_2" value="{{ address_2 }}" placeholder="{{ entry_address_2 }}" id="input-address-2" class="form-control" />
]]></search>
<add><![CDATA[
{% if error_address_2 %}
<div class="text-danger">{{ error_address_2 }}</div>
{% endif %}
]]></add>
</operation>
<operation info="Assign loading to the ZIP code search">
<search position="after"><![CDATA[
<div id="content" class="{{ class }}">
]]></search>
<add><![CDATA[
<div class="correios-loading"></div>
]]></add>
</operation>
</file>

<file name="catalog/controller/account/address.php">
<operation info="Assign error variable">
Expand Down Expand Up @@ -1186,19 +1237,21 @@
</file>

<file name="admin/model/catalog/category.php">
<operation info="Save category NCM">
<search position="after"><![CDATA[
public function editCategory($category_id, $data) {
]]></search>
<add><![CDATA[
try{
$this->db->query("UPDATE " . DB_PREFIX . "category SET category_ncm = '" .$data['category_ncm']. "' WHERE category_id = '" . (int)$category_id . "'");
}catch(Exception $e){
<operation info="Save category NCM">
<search position="before"><![CDATA[
if (isset($data['image'])) {
]]></search>
<add><![CDATA[
if (isset($data['category_ncm'])) {
try{
$this->db->query("UPDATE " . DB_PREFIX . "category SET category_ncm = '" .$data['category_ncm']. "' WHERE category_id = '" . (int)$category_id . "'");
}catch(Exception $e){
}
]]></add>
</operation>
</file>
}
}
]]></add>
</operation>
</file>

<file name="admin/controller/catalog/category.php">
<operation info="Assign custom fields variables">
Expand Down Expand Up @@ -1243,7 +1296,7 @@
<div class="form-group">
<label class="col-sm-2 control-label" for="input-ignorar-nfe">Ignorar produto ao emitir NFe</label>
<div class="col-sm-10">
<input type="checkbox" name="ignorar_nfe" value="1" id="input-ignorar-nfe" class="form-control" style="margin-top:15px;" {% if ifnorar_nfe == '1' %} {{ 'checked' }} {% endif %} />
<input type="checkbox" name="ignorar_nfe" value="1" id="input-ignorar-nfe" class="form-control" style="margin-top:15px;" {% if ignorar_nfe == '1' %} {{ 'checked' }} {% endif %} />
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -1297,7 +1350,7 @@
}
%}
{% for value, option in options %}
{% if value == webmaniabrnfe_ind_escala%}
{% if value == ind_escala%}
{{ '<option value="'~value~'" selected>'~option~'</option>' }}
{% else %}
{{ '<option value="'~value~'">'~option~'</option>' }}
Expand Down Expand Up @@ -1325,10 +1378,10 @@
}
%}
{% for value, option in options %}
{% if value == webmaniabrnfe_product_source%}
{{ '<option value="'~option~'" selected>'~option~'</option>' }}
{% if value == product_source%}
{{ '<option value="'~value~'" selected>'~option~'</option>' }}
{% else %}
{{ '<option value="'~option~'">'~option~'</option>' }}
{{ '<option value="'~value~'">'~option~'</option>' }}
{% endif %}
{% endfor %}
</select>
Expand All @@ -1341,11 +1394,13 @@
</file>
<file name="admin/model/catalog/product.php">
<operation info="Update product with custom info">
<search position="after"><![CDATA[
public function editProduct($product_id, $data) {
<search position="before"><![CDATA[
if (isset($data['image'])) {
]]></search>
<add><![CDATA[
try{
$this->db->query("UPDATE " . DB_PREFIX . "product SET classe_imposto = '" . $this->db->escape($data['classe_imposto']) . "', ean_barcode = '" . $this->db->escape($data['ean_barcode']) . "', gtin_tributavel = '" . $this->db->escape($data['gtin_tributavel']) . "', ncm_code = '" . $this->db->escape($data['ncm_code']) . "', cest_code = '" . $this->db->escape($data['cest_code']) . "', cnpj_fabricante = '" . $this->db->escape($data['cnpj_fabricante']) . "', ind_escala = '" . $this->db->escape($data['ind_escala']) . "', product_source = '" . $this->db->escape($data['product_source']) . "', ignorar_nfe = '" . $this->db->escape($data['ignorar_nfe']) . "' WHERE product_id = '" . (int)$product_id . "'");
}catch(Exception $e){}
]]></add>
</operation>
</file>
Expand Down Expand Up @@ -1539,5 +1594,17 @@
]]></add>
</operation>
</file>
</modification>
<file name="admin/model/setting/setting.php">
<operation info="Add module status of Webmania to setting">
<search position="before"><![CDATA[
if (substr($key, 0, strlen($code)) == $code) {
]]></search>
<add><![CDATA[
if($key === 'module_webmaniabrnfe_status' && $code === 'webmaniabrnfe'){
$this->load->model('extension/module/webmaniabrnfe');
$this->model_extension_module_webmaniabrnfe->setModuleStatus($value, $store_id);
}
]]></add>
</operation>
</file>
</modification>
Loading

0 comments on commit 7237925

Please sign in to comment.