60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* installmentpayment.php, Allows you to set a percentage payment for orders
|
|
* @author Magavenue <contact@magavenue.com>
|
|
* @copyright Magavenue
|
|
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
|
|
* @category modules
|
|
*
|
|
* @note If you want to customize the module, contact us at contact@magavenue.com
|
|
*/
|
|
|
|
require_once(dirname(__FILE__) . '/../../config/config.inc.php');
|
|
include(dirname(__FILE__) . '/../../init.php');
|
|
include(dirname(__FILE__) . '/installmentpayment.php');
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
if (Tools::getIsset('installmentpayment_type')) {
|
|
$id_cart = (int) Context::getContext()->cart->id;
|
|
if ((int) Tools::getValue('installmentpayment_type') == 0) {
|
|
Db::getInstance()->delete('installmentpayment', 'id_cart=' . (int) $id_cart);
|
|
} else {
|
|
//$installement = InstallmentPayment::getinstallmentInfos($id_cart);
|
|
$cartdata = new Cart($id_cart);
|
|
$total = (float) $cartdata->getOrderTotalGross(true, Cart::BOTH);
|
|
|
|
$id_defaultgroup = Db::getInstance()->executeS('SELECT id_default_group FROM ' . _DB_PREFIX_ . 'customer WHERE id_customer = ' . (int) Context::getContext()->customer->id);
|
|
if(is_array($id_defaultgroup))
|
|
{
|
|
$id_defaultgroup = $id_defaultgroup[0]['id_default_group'];
|
|
}
|
|
$sql = 'SELECT price FROM `' . _DB_PREFIX_ . 'installmentpayment_group` WHERE id_group=' . (int) $id_defaultgroup;
|
|
|
|
$data = Db::getInstance()->getRow($sql);
|
|
if(!empty($data)){
|
|
$percent = $data['price'];
|
|
}
|
|
else
|
|
{
|
|
$percent = Configuration::get('ACOMPTE_PERCENTAGE');
|
|
}
|
|
|
|
$acompte = (float) $total - ($total * (100 - $percent) / 100);
|
|
$rest = $total - $acompte;
|
|
$data_insert = array(
|
|
'id_cart' => (int) $id_cart,
|
|
'total' => $total,
|
|
'payer' => $acompte,
|
|
'rest' => $rest,
|
|
'state' => 0,
|
|
);
|
|
Db::getInstance()->insert('installmentpayment', $data_insert);
|
|
}
|
|
Context::getContext()->cookie->__set('installmentpayment_type', (int) Tools::getValue('installmentpayment_type'));
|
|
|
|
die(Hook::exec('displayPayment'));
|
|
die(Hook::exec('displayPaymentTop'));
|
|
}
|