Files
2019-11-20 07:44:43 +01:00

119 lines
5.1 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
*/
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
class InstallmentpaymentInstallmentpaymentModuleFrontController extends ModuleFrontController
{
public $ssl = true;
public function __construct()
{
parent::__construct();
}
public function initContent()
{
$this->display_column_left = false;
$this->display_column_right = false;
parent::initContent();
$id_order = Tools::getValue('select');
if (!Context::getContext()->customer->isLogged() && (int) $id_order > 0) {
Tools::redirect(
'index.php?controller=authentication&back=' . urlencode($this->context->link->getModuleLink('installmentpayment', 'installmentpayment', array('select' => $id_order)))
);
}
$order = new Order((int) $id_order);
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'installmentpayment` WHERE id_cart=' . (int) $order->id_cart;
$installment = Db::getInstance()->getRow($sql);
if (isset($installment['rest']) && (float) $installment['rest'] > 0) {
$rest_paid = $installment['rest'];
} else {
Tools::redirect(
'index.php?controller=authentication&back=' . urlencode($this->context->link->getModuleLink('installmentpayment', 'installmentpayment', array('select' => $id_order)))
);
}
if ((int) $id_order > 0) {
Context::getContext()->cookie->__set('installmentpayment_id_order', $id_order);
}
$oldCart = new Cart($order->id_cart);
$cart = $oldCart->duplicate();
$this->context->cookie->id_cart = $cart['cart']->id;
$context = $this->context;
$context->cart = $cart['cart'];
$this->context->cookie->write();
$this->context->smarty->assign('hide_left_column', true);
$this->context->smarty->assign('hide_right_column', true);
if (Tools::substr(str_replace('.', '', _PS_VERSION_), 0, 2) == 16) {
if (Context::getContext()->customer->id) {
$cartdata = new Cart($order->id_cart);
$total = (float) $cartdata->getOrderTotalGross(true, Cart::BOTH);
$this->context->smarty->assign(array(
'reference' => $order->reference,
'total' => $total,
'HOOK_PAYMENT' => Hook::exec('displayPayment')
));
$this->setTemplate('order-payment-classic.tpl');
}
} else {
if (Context::getContext()->customer->id) {
$b = new PaymentOptionsFinder();
$data = $b->present();
$cartdata = new Cart($order->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;
$dataprice = Db::getInstance()->getRow($sql);
if(!empty($data)){
$acompte = (float) $total - ($total * (100 - $dataprice['price']) / 100);
$percent = $dataprice['price'];
}
else
{
$acompte = (float) $total - ($total * (100 - Configuration::get('ACOMPTE_PERCENTAGE')) / 100);
$percent = Configuration::get('ACOMPTE_PERCENTAGE');
}
$presentedCart = $this->cart_presenter->present($this->context->cart);
$this->context->smarty->assign(array(
'reference' => $order->reference,
'payment_options' => $data,
'cart' => $presentedCart,
'selected_payment_option' => 1,
'show_final_summary' => Configuration::get('PS_FINAL_SUMMARY_ENABLED'),
'installmentpayment_type' => (int) Context::getContext()->cookie->installmentpayment_type,
'percent' => $percent,
'acompte_chose' => Configuration::get('ACOMPTE_CHOICE'),
'acompte' => $acompte,
));
$this->setTemplate('module:installmentpayment/views/templates/front/checkout.tpl');
}
}
}
public function setMedia() {
parent::setMedia();
$this->addCSS( _THEME_CSS_DIR_ . 'modules/stripe_official/views/css/front.css');
}
}