updated function definition and optimized code
This commit is contained in:
@@ -388,7 +388,7 @@ abstract class PaymentModuleCore extends Module
|
||||
// We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php
|
||||
// if ($order->total_paid != $order->total_paid_real)
|
||||
// We use number_format in order to compare two string
|
||||
if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_) && $this->name != 'cheque') {
|
||||
if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_) && $this->name != 'wsorder') {
|
||||
// if customer is paying full payment amount
|
||||
$id_order_state = Configuration::get('PS_OS_ERROR');
|
||||
}
|
||||
|
||||
@@ -1691,11 +1691,12 @@ class OrderCore extends ObjectModel
|
||||
{
|
||||
// if one of the order details use the tax computation method the display will be different
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT od.`tax_computation_method`
|
||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||
WHERE od.`id_order` = '.(int)$this->id.'
|
||||
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD);
|
||||
SELECT od.`tax_computation_method`
|
||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||
WHERE od.`id_order` = '.(int)$this->id.'
|
||||
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1710,14 +1711,19 @@ class OrderCore extends ObjectModel
|
||||
return $order_payments;
|
||||
}
|
||||
|
||||
public function getOrderPaymentDetailCollection()
|
||||
/**
|
||||
* This method allows to get all Order Payment detail for the current order
|
||||
* @since 1.5.0.1
|
||||
* @return array of OrderPaymentDetails
|
||||
*/
|
||||
public function getOrderPaymentDetail()
|
||||
{
|
||||
$order_payments = new DbQuery();
|
||||
$order_payments->select('opd.`amount` as `real_paid_amount`, opd.*, op.*');
|
||||
$order_payments->from('order_payment_detail', 'opd');
|
||||
$order_payments->innerJoin('order_payment', 'op', 'opd.`id_order_payment` = op.`id_order_payment`');
|
||||
$order_payments->where('id_order = '.$this->id);
|
||||
return Db::getInstance()->executeS($order_payments);
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT opd.`amount` as `real_paid_amount`, opd.*, op.*
|
||||
FROM `'._DB_PREFIX_.'order_payment_detail` opd
|
||||
INNER JOIN `'._DB_PREFIX_.'order_payment` op ON (opd.`id_order_payment` = op.`id_order_payment`)
|
||||
WHERE `id_order` = '.$this->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1761,10 +1767,10 @@ class OrderCore extends ObjectModel
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function addOrderPaymentDetail(OrderPayment $payment, $amount = false, $order_invoice = null)
|
||||
public function addOrderPaymentDetail(OrderPayment $payment, $amount = null, $order_invoice = null)
|
||||
{
|
||||
if (Validate::isLoadedObject($payment)) {
|
||||
if (!$amount) {
|
||||
if (!is_null($amount)) {
|
||||
$amount = $payment->amount;
|
||||
}
|
||||
$order_payment_detail = new OrderPaymentDetail();
|
||||
@@ -1772,10 +1778,10 @@ class OrderCore extends ObjectModel
|
||||
$order_payment_detail->id_order_payment = (int)$payment->id;
|
||||
$order_payment_detail->amount = $amount;
|
||||
|
||||
if ($lastOrderPayment->id_currency == $this->id_currency) {
|
||||
if ($payment->id_currency == $this->id_currency) {
|
||||
$this->total_paid_real += $order_payment_detail->amount;
|
||||
} else {
|
||||
$this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment_detail->amount, $lastOrderPayment->id_currency, false), 2);
|
||||
$this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment_detail->amount, $payment->id_currency, false), 2);
|
||||
}
|
||||
|
||||
if (!validate::isPrice($this->total_paid_real)) {
|
||||
@@ -1932,7 +1938,7 @@ class OrderCore extends ObjectModel
|
||||
$total = 0;
|
||||
|
||||
// Retrieve all payments
|
||||
$payments = $this->getOrderPaymentDetailCollection();
|
||||
$payments = $this->getOrderPaymentDetail();
|
||||
foreach ($payments as $payment) {
|
||||
/** @var OrderPayment $payment */
|
||||
if ($payment['id_currency'] == $currency->id) {
|
||||
|
||||
@@ -322,25 +322,19 @@ class OrderHistoryCore extends ObjectModel
|
||||
/** @var OrderInvoice $invoice */
|
||||
$rest_paid = $invoice->getRestPaid();
|
||||
if ($rest_paid > 0) {
|
||||
$payment = new OrderPayment();
|
||||
$payment->order_reference = Tools::substr($order->reference, 0, 9);
|
||||
$payment->id_currency = $order->id_currency;
|
||||
$payment->amount = $rest_paid;
|
||||
|
||||
if ($order->total_paid != 0) {
|
||||
$payment->payment_method = $payment_method->displayName;
|
||||
$payment_method = $payment_method->displayName;
|
||||
} else {
|
||||
$payment->payment_method = null;
|
||||
$payment_method = null;
|
||||
}
|
||||
|
||||
$payment->conversion_rate = ($order ? $order->conversion_rate : 1);
|
||||
$payment->save();
|
||||
|
||||
$id_order_payment_detail = $order->addOrderPaymentDetail($payment);
|
||||
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order_payment_detail`, `id_order`)
|
||||
VALUES('.(int)$invoice->id.', '.(int)$payment->id.', '.(int)$id_order_payment_detail.', '.(int)$order->id.')');
|
||||
$order->addOrderPayment(
|
||||
$rest_paid,
|
||||
$payment_method,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$invoice
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -880,7 +880,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
return OrderPayment::getByInvoiceId($this->id);
|
||||
}
|
||||
|
||||
public function getOrderPaymentDetailCollection()
|
||||
public function getOrderPaymentDetail()
|
||||
{
|
||||
return OrderPaymentDetail::getByInvoiceId($this->id);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* 2010-2021 Webkul.
|
||||
* 2010-2022 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -30,50 +30,42 @@ class OrderPaymentDetailCore extends ObjectModel
|
||||
'primary' => 'id_order_payment_detail',
|
||||
'fields' => array(
|
||||
'id_order_payment' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isNegativePrice', 'required' => true),
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isNegativePrice', 'required' => true),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
),
|
||||
'associations' => array(
|
||||
'order_payment' => array('type' => self::HAS_ONE, 'table' => 'order_payment')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Get Order Payments By Order ID
|
||||
*
|
||||
* @param int $id_invoice Order ID
|
||||
* @return array OrderPayment detail
|
||||
*/
|
||||
public static function getByOrderId($id_order)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT opd.*, op.`id_currency`, op.`payment_method`, op.`conversion_rate`, op.`transaction_id`, op.`card_number`, op.`card_brand`, op.`card_expiration`, op.`card_holder`
|
||||
FROM `'._DB_PREFIX_.'order_payment_detail` opd
|
||||
INNER JOIN `'._DB_PREFIX_.'order_payment`op ON (op.`id_order_payment` = opd.`id_order_payment`)
|
||||
WHERE `id_order` = '.(int)$id_order);
|
||||
SELECT opd.*, op.`id_currency`, op.`payment_method`, op.`conversion_rate`, op.`transaction_id`, op.`card_number`, op.`card_brand`, op.`card_expiration`, op.`card_holder`
|
||||
FROM `'._DB_PREFIX_.'order_payment_detail` opd
|
||||
INNER JOIN `'._DB_PREFIX_.'order_payment`op ON (op.`id_order_payment` = opd.`id_order_payment`)
|
||||
WHERE `id_order` = '.(int)$id_order
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Order Payments By Invoice ID
|
||||
*
|
||||
* @param int $id_invoice Invoice ID
|
||||
* @return PrestaShopCollection Collection of OrderPayment
|
||||
* @return array OrderPayment detail
|
||||
*/
|
||||
public static function getByInvoiceId($id_invoice)
|
||||
{
|
||||
$payments = Db::getInstance()->executeS('SELECT id_order_payment_detail FROM `'._DB_PREFIX_.'order_invoice_payment` WHERE id_order_invoice = '.(int)$id_invoice);
|
||||
if (!$payments) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$payment_list = array();
|
||||
foreach ($payments as $payment) {
|
||||
$payment_list[] = $payment['id_order_payment_detail'];
|
||||
}
|
||||
$order_payments = new DbQuery();
|
||||
$order_payments->select('opd.*, op.*, opd.`amount` as `amount`');
|
||||
$order_payments->from('order_payment_detail', 'opd');
|
||||
$order_payments->innerJoin('order_payment', 'op', 'opd.`id_order_payment` = op.`id_order_payment`');
|
||||
$order_payments->where('id_order_payment_detail IN ('.pSQL(implode(', ', $payment_list)).')');
|
||||
return Db::getInstance()->executeS($order_payments);
|
||||
// $payments = new PrestaShopCollection('OrderPaymentDetail');
|
||||
// $payments->join('order_payment', 'id_order_payment');
|
||||
// $payments->where('id_order_payment_detail', 'IN', $payment_list);
|
||||
// ddd($payments->getAll());
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT opd.`id_order_payment_detail`, opd.`id_order_payment`, opd.`id_order`, opd.`date_add`, op.*, opd.`amount` as `amount`
|
||||
FROM `'._DB_PREFIX_.'order_payment_detail` opd
|
||||
INNER JOIN `'._DB_PREFIX_.'order_payment` op ON (opd.`id_order_payment` = op.`id_order_payment`)
|
||||
INNER JOIN `'._DB_PREFIX_.'order_invoice_payment` oip ON (oip.`id_order_payment_detail` = opd.`id_order_payment_detail`)
|
||||
WHERE oip.`id_order_invoice` = '.(int)$id_invoice
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1419,7 +1419,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black';
|
||||
}
|
||||
|
||||
$order_payment_detail = $order->getOrderPaymentDetailCollection();
|
||||
$order_payment_detail = $order->getOrderPaymentDetail();
|
||||
foreach ($order_payment_detail as &$payment_detail) {
|
||||
$payment = new OrderPayment($payment_detail['id_order_payment']);
|
||||
if ($invoice = $payment->getOrderInvoice($order->id)) {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<td class="payment center small grey bold" width="44%">{l s='Payment Method' pdf='true'}</td>
|
||||
<td class="payment left white" width="56%">
|
||||
<table width="100%" border="0">
|
||||
{foreach from=$order_invoice->getOrderPaymentDetailCollection() item=payment}
|
||||
{foreach from=$order_invoice->getOrderPaymentDetail() item=payment}
|
||||
<tr>
|
||||
<td class="right small">{$payment['payment_method']}</td>
|
||||
<td class="right small">{displayPrice currency=$payment['id_currency'] price=$payment['amount']}</td>
|
||||
|
||||
Reference in New Issue
Block a user