Página 1 de 1

CEP no produto - adaptar ao tema

Enviado: 09 Out 2015, 14:47
por emersonmorais
Olá, baixei o módulo abaixo na opencart (vqmod), ele simula o frete na página do produto, funciona perfeitamente no tema padrão, porém no meu tema, jornal2, o campo não aparece, alguém pode me ajudar, oque devo mudar?

<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Calculo de frete no produto</id>
<version>1.0</version>
<vqmver>2.x</vqmver>
<author>contato@cakephptutorial.com</author>

<file name="catalog/controller/product/product.php">
<operation info="add text of shipping">
<search position="after" offset="1"><![CDATA[
$this->data['tab_related'] = $this->language->get('tab_related');
]]></search>
<add>
<![CDATA[
//Set cart texts

$this->load->language('checkout/cart');

$this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate');
$this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['entry_country'] = $this->language->get('entry_country');
$this->data['entry_zone'] = $this->language->get('entry_zone');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');
$this->data['button_quote'] = $this->language->get('button_quote');
$this->data['button_shipping'] = $this->language->get('button_shipping');
$this->data['text_none'] = $this->language->get('text_none');

$this->load->model('setting/setting');
$_data = $this->model_setting_setting->getSetting('product_shipping');
$this->data['shipping_page'] = $_data;
]]>
</add>
</operation>
<operation info="add actions of shipping">
<search position="after" offset="1"><![CDATA[
$this->model_catalog_product->updateViewed($this->request->get['product_id']);
]]></search>
<add>
<![CDATA[
//Shipping in product
$product = $this->cart->getProducts();

if (isset($this->request->post['country_id'])) :
$this->data['country_id'] = $this->request->post['country_id'];
elseif (isset($this->session->data['shipping_country_id'])) :
$this->data['country_id'] = $this->session->data['shipping_country_id'];
else :
$this->data['country_id'] = $this->config->get('config_country_id');
endif;

$this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping();

$this->load->model('localisation/country');
$this->data['countries'] = $this->model_localisation_country->getCountries(); //Set the countries

//Check postcode
if (isset($this->request->post['postcode'])):
$this->data['postcode'] = $this->request->post['postcode'];
elseif(isset($this->session->data['shipping_postcode'])) :
$this->data['postcode'] = $this->session->data['shipping_postcode'];
else :
$this->data['postcode'] = '';
endif;

//Check zone_id
if (isset($this->request->post['zone_id'])) :
$this->data['zone_id'] = $this->request->post['zone_id'];
elseif (isset($this->session->data['shipping_zone_id'])) :
$this->data['zone_id'] = $this->session->data['shipping_zone_id'];
else :
$this->data['zone_id'] = '';
endif;

//Check shipping method
if (isset($this->request->post['shipping_method'])) :
$this->data['shipping_method'] = $this->request->post['shipping_method'];
elseif (isset($this->session->data['shipping_method'])) :
$this->data['shipping_method'] = $this->session->data['shipping_method']['code'];
else :
$this->data['shipping_method'] = '';
endif;
]]>
</add>
</operation>

<operation info="add functions of shipping">
<search position="after" offset="1"><![CDATA[
$captcha->showImage();
]]></search>
<add>
<![CDATA[
public function quote() {
$this->language->load('checkout/cart');
$json = array();

/*echo $this->config->get('config_country_id');
$_country_id = $this->config->get('config_country_id');
$_zone_id = $this->config->get('config_zone_id');*/

if (!$this->cart->hasProducts()) {
$json['error']['warning'] = $this->language->get('error_product');
}

if (!$this->cart->hasShipping()) {
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
}

if ($this->request->post['country_id'])
$_country_id = $this->request->post['country_id'];


if (isset($this->request->post['zone_id']) && $this->request->post['zone_id'] != '')
$_zone_id = $this->request->post['zone_id'];


$this->load->model('localisation/country');

$country_info = $this->model_localisation_country->getCountry($_country_id);

if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['postcode']) < 2) || (utf8_strlen($this->request->post['postcode']) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}

if (!$json) {
$this->tax->setShippingAddress($_country_id, $_zone_id);

// Default Shipping Address
$this->session->data['shipping_country_id'] = $_country_id;
$this->session->data['shipping_zone_id'] = $_zone_id;
$this->session->data['shipping_postcode'] = $this->request->post['postcode'];

if ($country_info) {
$country = $country_info['name'];
$iso_code_2 = $country_info['iso_code_2'];
$iso_code_3 = $country_info['iso_code_3'];
$address_format = $country_info['address_format'];
} else {
$country = '';
$iso_code_2 = '';
$iso_code_3 = '';
$address_format = '';
}

$this->load->model('localisation/zone');

$zone_info = $this->model_localisation_zone->getZone($_zone_id);

if ($zone_info) {
$zone = $zone_info['name'];
$zone_code = $zone_info['code'];
} else {
$zone = '';
$zone_code = '';
}

$address_data = array(
'firstname' => '',
'lastname' => '',
'company' => '',
'address_1' => '',
'address_2' => '',
'postcode' => $this->request->post['postcode'],
'city' => '',
'zone_id' => $_zone_id,
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => $_country_id,
'country' => $country,
'iso_code_2' => $iso_code_2,
'iso_code_3' => $iso_code_3,
'address_format' => $address_format
);

$quote_data = array();

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

$results = $this->model_setting_extension->getExtensions('shipping');

foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('shipping/' . $result['code']);

$quote = $this->{'model_shipping_' . $result['code']}->getQuote($address_data);

if ($quote) {
$quote_data[$result['code']] = array(
'title' => $quote['title'],
'quote' => $quote['quote'],
'sort_order' => $quote['sort_order'],
'error' => $quote['error']
);
}
}
}

$sort_order = array();

foreach ($quote_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}

array_multisort($sort_order, SORT_ASC, $quote_data);

$this->session->data['shipping_methods'] = $quote_data;

if ($this->session->data['shipping_methods']) {
$json['shipping_method'] = $this->session->data['shipping_methods'];
} else {
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
}
}

$this->session->data['cart'] = $this->session->data['cacheCart'];
unset($this->session->data['cacheCart']);
$this->response->setOutput(json_encode($json));
}

public function country() {
$json = array();

$this->load->model('localisation/country');

$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
if ($country_info) {
$this->load->model('localisation/zone');

$json = array(
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'iso_code_2' => $country_info['iso_code_2'],
'iso_code_3' => $country_info['iso_code_3'],
'address_format' => $country_info['address_format'],
'postcode_required' => $country_info['postcode_required'],
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
'status' => $country_info['status']
);
}

$this->response->setOutput(json_encode($json));
}

public function quoteProduct() {
$this->session->data['cacheCart'] = $this->session->data['cart'];
unset($this->session->data['cart']);

if (isset($this->request->post['product_id'])) :
$product_id = $this->request->post['product_id'];
else :
$product_id = 0;
endif;

$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);

if ($product_info) {//Add a provisory product to calcule the quote
if (isset($this->request->post['quantity'])) {
$quantity = $this->request->post['quantity'];
} else {
$quantity = 1;
}

if (isset($this->request->post['option'])) {
$option = array_filter($this->request->post['option']);
} else {
$option = array();
}

if (isset($this->request->post['profile_id'])) {
$profile_id = $this->request->post['profile_id'];
} else {
$profile_id = 0;
}

$this->cart->add($this->request->post['product_id'], $quantity, $option, $profile_id);
}
$json['success'] = "Product has a success";
$this->response->setOutput(json_encode($json));
}
]]>
</add>
</operation>
</file>

<file name="catalog/view/theme/*/template/product/product.tpl">
<operation info="add inputs in product.tpl">
<search position="before" offset="1"><![CDATA[
<div id="tabs" class="htabs"><a href="#tab-description"><?php echo $tab_description; ?></a>
]]></search>
<add>
<![CDATA[
<?php if($shipping_page['enabled']): ?>
<div class="calculaFrete"><!-- Initial calculaFrete -->
<div id="shipping" class="content">
<p><?php echo $shipping_page['header_title']; ?></p>
<table>
<?php if($shipping_page['geo_need']): ?>
<tr>
<td><span class="required">*</span> <?php echo $entry_country; ?></td>
<td><select name="country_id">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
</select></td>
</tr>
<?php endif; ?>
<tr>
<td><span id="postcode-required" class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" /></td>
</tr>
</table>
<input type="button" value="<?php echo $button_quote; ?>" id="button-quote" class="button" />
</div>
</div><!-- Final calculaFrete -->
<?php endif; ?>
]]>
</add>
</operation>

<operation>
<search position="before" offset="1"><![CDATA[
$('select[name="profile_id"], input[name="quantity"]').change(function(){
]]></search>
<add>
<![CDATA[
$('#button-quote').live('click', function() {
$.ajax({
url: 'index.php?route=product/product/quoteProduct',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-quote').attr('disabled', true);
$('#button-quote').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-quote').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.success, .warning, .attention, .error').remove();
$.ajax({
url: 'index.php?route=product/product/quote',
type: 'post',
data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
dataType: 'json',
beforeSend: function() {
$('#button-quote').attr('disabled', true);
$('#button-quote').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-quote').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
if (json['error']) {
if (json['error']['warning']) {
$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

$('.warning').fadeIn('slow');

$('html, body').animate({ scrollTop: 0 }, 'slow');
}

if (json['error']['country']) {
$('select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
}

if (json['error']['postcode']) {
$('input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
}
}

if (json['shipping_method']) {
html = '<h2><?php echo $shipping_page['popup_title'] ?></h2>';
html += ' <table class="radio">';

for (i in json['shipping_method']) {
html += '<tr>';
html += ' <td colspan="3"><b>' + json['shipping_method']['title'] + '</b></td>';
html += '</tr>';

if (!json['shipping_method']['error']) {
for (j in json['shipping_method']['quote']) {
html += '<tr class="highlight">';
html += ' <td colspan="3"><label>' + json['shipping_method']['quote'][j]['title'] + '</label></td>';
html += ' <td style="text-align: right;"><label for="' + json['shipping_method']['quote'][j]['code'] + '">' + json['shipping_method']['quote'][j]['text'] + '</label></td>';
html += '</tr>';
}
} else {
html += '<tr>';
html += ' <td colspan="3"><div class="error">' + json['shipping_method']['error'] + '</div></td>';
html += '</tr>';
}
}

html += ' </table>';
html += ' <br />';

$.colorbox({
overlayClose: true,
opacity: 0.5,
width: '600px',
height: '400px',
href: false,
html: html
});
}
}
});
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=product/product/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}

html = '<option value=""><?php echo $text_select; ?></option>';

if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone']['zone_id'] + '"';

if (json['zone']['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}

html += '>' + json['zone']['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}

$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});

$('select[name=\'country_id\']').trigger('change');
]]>
</add>
</operation>
</file>
</modification>

Re: CEP no produto - adaptar ao tema

Enviado: 10 Out 2015, 11:09
por veteranodf
Como o módulo é feito para o tema padrão você deve adaptar para o seu tema, deve ler o log de erro do vqmod que fica em "vqmod/logs", abra o log de erro da data que esta testando o script encontre a linha onde esta ocorrendo o erro e adapte para o seu tema, Conheça abaixo como o vqmod trabalha;

https://github.com/vqmod/vqmod/wiki/Examples

Re: CEP no produto - adaptar ao tema

Enviado: 14 Out 2015, 08:23
por emersonmorais
Achei..

---------- Date: 2015-10-13 16:40:32 ~ IP : 187.57.55.197 ----------
REQUEST URI : /index.php?route=product/product&product_id=350
MOD DETAILS:
modFile : /home/zipmoveiscom/public_html/vqmod/xml/product_shipping.xml
id : Calculo de frete no produto
version : 1.0
vqmver : 2.x
author : contato@cakephptutorial.com

File Name : catalog/view/theme/journal2/template/product/product.tpl(0)
VQModObject::applyMod - SEARCH NOT FOUND (ABORTING MOD): <div id="tabs" class="htabs"><a href="#tab-description"><?php echo $tab_description; ?></a>
----------------------------------------------------------------------