Okay, it starts to write something ...
Specifically, Zen Cart and again to see today how to achieve a reduction in percentage of the total order which is activated when the user selects a particular payment system.
In the case of my example will use the module as a transfer payment system on which to apply the discount.
discounts, price increases (both in percentage is calculated otherwise) going to change the order total is accomplished by creating a new form of 'serious' order_total
In this case, since it will also add a small note as to seen in Phase 2 of the checkout (ie the choice of payment system) at the payment system affected by this discount, we will also make a small change to the payment form and the corresponding language file. This note is optional, useful for the buyer to understand that if you choose this payment system will get a discount (the percentage is taken by dynamically configuring the module that will create total order and the note disappears if you disable the discount).
since the creation of form order_total:
position: includes / modules / order_total /
name: ot_sconto_bonifico.php
contents of the file:
/ ** *
sconto_bonifico order-total module
* * @ package OrderTotal
* @copyright Copyright 2008 Paolo De Dionigi aka spike00 http://www.atfriends.net
* @copyright Portions Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @copyright Portions Copyright (c) 2002 Thomas Plänkers http://www.oscommerce.at
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: ot_sconto_bonifico.php 2008-07-03 spike00 $
*/
/**
* sconto_bonifico Order Totals Module
*
*/
class ot_sconto_bonifico {
var $title, $output;
function ot_sconto_bonifico() {
$this->code = 'ot_sconto_bonifico';
$this->title = MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TITLE;
$this->description = MODULE_ORDER_TOTAL_SCONTO_BONIFICO_DESCRIPTION;
$this->enabled = ((MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS == 'true') ? true : false);
$this->sort_order = MODULE_ORDER_TOTAL_SCONTO_BONIFICO_SORT_ORDER;
$this->output = array();
}
function process() {
global $order, $currencies, $sconto_valore, $sconto_bonifico_country, $shipping, $db;
if (MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS == 'true') {
if ($_SESSION['payment'] == 'bonifico') {
$sconto_valore = MODULE_ORDER_TOTAL_SCONTO_BONIFICO_VALORE;
$importo_sconto = ($order->info['total'] * $sconto_valore / 100);
$sconto_bonifico_tax_address = zen_get_tax_locations();
$tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TAX_CLASS, $sconto_bonifico_tax_address['country_id'], $sconto_bonifico_tax_address['zone_id']);
$order->info['total'] -= $importo_sconto;
if ($tax > 0) {
$tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TAX_CLASS, $sconto_bonifico_tax_address['country_id'], $sconto_bonifico_tax_address['zone_id']);
$order->info['tax'] -= zen_calculate_tax($importo_sconto, $tax);
$order->info['tax_groups'][$tax_description] -= zen_calculate_tax($importo_sconto, $tax);
$order->info['total'] -= zen_calculate_tax($importo_sconto, $tax);
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$importo_sconto -= zen_calculate_tax($importo_sconto, $tax);
}
}
$this->output[] = array('title' => $this->title . ':',
'text' => '- ' . $currencies->format($importo_sconto, true, $order->info['currency'], $order->info['currency_value']),
'value' => $importo_sconto);
}
}
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
//lagt tilk servicepakke her!!!!
function keys() {
return array('MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_SORT_ORDER', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_VALORE', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TAX_CLASS');
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values \u200b\u200b('Supplement View', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS', 'true', 'Activate the form?', '6 ', '1', 'zen_cfg_select_option (array (\\' true \\ ', \\' false \\ '), ', now ())");
$ db-> Execute ("insert into". TABLE_CONFIGURATION. "(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values \u200b\u200b(' Display Order ',' MODULE_ORDER_TOTAL_SCONTO_BONIFICO_SORT_ORDER ' , '991 ',' display order. ', '6', '2 ', now ())");
$ db-> Execute ("insert into". TABLE_CONFIGURATION. "(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values \u200b\u200b('Value discount bank', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_VALORE', '2 .00 ',' Set the value of the discount to be applied for payment by bank transfer. If you want eg 3 % 3:00 write ', '6', '3 ', now ())");
$ db-> Execute ("insert into". TABLE_CONFIGURATION. "(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function , set_function, date_added) values \u200b\u200b('Class IVA', 'MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TAX_CLASS', '0 ',' Use this rate VAT reduction for payment. ', '6', '25 ',' Zen_get_tax_class_title ',' zen_cfg_pull_down_tax_classes (', now ())");
} function remove () {global $ db
;
$ keys = '';
keys_array $ = $ this-> keys ();
$ keys_size = sizeof ($ keys_array)
for ($ i = 0; <$keys_size; $i++) {
$ i $ keys .= "'". keys_array $ [$ i] . "',";
} $ keys = substr ($ keys, 0, -1);
$ db-> Execute ("delete from". TABLE_CONFIGURATION. "where configuration_key in (". $ keys. ") ");}
} ?>
Note the line that says this form of 'entering function' if the user has selected the bank as payment system:
if ($ _SESSION ['payment'] == 'transfer ')
as it is in quotation marks'' or the word bank, must be exactly what is contained in quotes the line: $ this-> code = 'bank';
which is located near the top of file on the payment form (in this case: includes / modules / payment / bonifico.php), ie the 'code' to attribute the payment form. Other
file to create is the language file:
position: includes / languages \u200b\u200b/ italian / modules / order_total /
nome: ot_sconto_bonifico.php
contenuto del file:
/**
* @package languageDefines
* @copyright Copyright 2008 Paolo De Dionigi aka spike00 http://www.atfriends.net
* @copyright Portions Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: ot_sconto_bonifico.php 2008-07-03 spike00 $
*/
define('MODULE_ORDER_TOTAL_SCONTO_BONIFICO_TITLE', 'Sconto per pagamento con bonifico');
define('MODULE_ORDER_TOTAL_SCONTO_BONIFICO_DESCRIPTION', 'Sconto per pagamenti tramite bonifico');
?>
Infine apportiamo le modifiche al file del modulo di pagamento per inserire la nota di cui sopra:
Subito dopo la riga
$this->title = MODULE_PAYMENT_BONIFICO_TEXT_TITLE;
inseriamo queste righe:
if (MODULE_ORDER_TOTAL_SCONTO_BONIFICO_STATUS == 'true') {
$this->title = MODULE_PAYMENT_BONIFICO_TEXT_TITLE . '
Nota: previsto sconto pari al ' . MODULE_ORDER_TOTAL_SCONTO_BONIFICO_VALORE .'%
'; }
Qui ho scritto direttamente il testo in italiano, ovviamente se si ha un sito multilingua questa operazione comporterà che anche nelle lingue diverse dall'italiano, il messaggio si veda in italiano, quindi invece di fare così, si deve creare una o più nuove defines di lingua e usarle al posto del testo scritto direttamente nel modulo.
Ok, ora rimano soltanto da attivare il modulo e configurarlo.
Si va nell'amministrazione, in moduli, totale ordine. Qui comparirà il nostro nuovo modulo 'Sconto per pagamento con bonifico', lo installiamo come qualsiasi altro modulo. Di default ho inserito come posizionamento il valore 991, che dovrebbe essere subito dopo il calcolo dell'iva e subito prima del totale, così il tutto risulta coerente in visualizzazione da parte del cliente, comunque ovviamente è possibile modificare the display order.
Other key parameter is obviously the value of the discount. If you want to set such a discount of 3%, write 3:00 in the appropriate field.
last thing: the module is switched off course and / or uninstalled. If you disable or uninstall course will no longer apply the discount will disappear and the note at the system of payment on page 2 of checkout.
End;)
Special discounts to all;)
0 comments:
Post a Comment