Added: Configuration in Preferences->order tab for price display currency in order list page

This commit is contained in:
Sumit Panwar
2023-10-05 18:35:14 +05:30
parent ce93a9826f
commit 3e09c4c2c5
5 changed files with 56 additions and 4 deletions

View File

@@ -34,6 +34,10 @@ class OrderCore extends ObjectModel
const ORDER_PAYMENT_TYPE_FULL = 1;
const ORDER_PAYMENT_TYPE_ADVANCE = 2;
//Consts for: In the order list in which currency prices should be displayed
const ORDER_LIST_PRICE_DISPLAY_IN_PAYMENT_CURRENCY = 1;
const ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY = 2;
/** @var int Delivery address id */
public $id_address_delivery;
@@ -1835,6 +1839,10 @@ class OrderCore extends ObjectModel
}
}
// Whenever payment is adding in any order then set a cumulative conversion rate for the payment currency in the order
$this->conversion_rate = $order_payment->getCumulativeConversionRate($this->reference, $this->id_currency);
$this->save();
return $res;
}
@@ -2660,4 +2668,4 @@ class OrderCore extends ObjectModel
{
$this->transaction_id = $transactionId;
}
}
}

View File

@@ -148,4 +148,15 @@ class OrderPaymentCore extends ObjectModel
return new OrderInvoice((int)$res);
}
/**
* Provides the cumulative conversion rate for a given order in any currency
* @param [string] $order_reference
* @param [int] $idCurrency
* @return float
*/
public function getCumulativeConversionRate($order_reference, $idCurrency)
{
return Db::getInstance()->getValue('SELECT (SUM(`conversion_rate`) / COUNT(*)) FROM `'._DB_PREFIX_.'order_payment` WHERE `order_reference` = \''.pSQL($order_reference).'\' AND `id_currency` = '.(int)$idCurrency);
}
}

View File

@@ -58,6 +58,18 @@ class AdminOrderPreferencesControllerCore extends AdminController
)
);
// Options to display currency in order list
$displayCurrencyOptions = array(
array(
'value' => Order::ORDER_LIST_PRICE_DISPLAY_IN_PAYMENT_CURRENCY,
'name' => $this->l('Payment currency')
),
array(
'value' => Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY,
'name' => $this->l('Default currency')
)
);
$this->fields_options = array(
'order_restrict' => array(
'title' => $this->l('Order Restrict'),
@@ -159,6 +171,15 @@ class AdminOrderPreferencesControllerCore extends AdminController
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY' => array(
'title' => $this->l('Display order list prices in'),
'hint' => $this->l('Choose the currency in which you want the prices in the order list to be displayed.'),
'validation' => 'isInt',
'type' => 'select',
'cast' => 'intval',
'list' => $displayCurrencyOptions,
'identifier' => 'value',
),
),
'submit' => array('title' => $this->l('Save'))
),

View File

@@ -58,11 +58,14 @@ class AdminOrdersControllerCore extends AdminController
$this->context = Context::getContext();
$this->_select = '
(a.total_paid - a.total_paid_real) AS `amount_due`, a.source AS order_source,
IF('.((Configuration::get('PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY') == Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY)? 1 : 0).', (a.total_paid_tax_incl / a.conversion_rate), total_paid_tax_incl) AS total_paid_tax_incl,
IF('.((Configuration::get('PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY') == Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY)? 1 : 0).', ((a.total_paid - a.total_paid_real) / a.conversion_rate), (a.total_paid - a.total_paid_real)) AS amount_due,
a.source AS order_source,
a.id_currency,
a.id_order AS id_pdf,
CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`, os.`color`,
cu.iso_code AS currency,
IF((SELECT so.id_order FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new,
IF(a.valid, 1, 0) badge_success,
hbil.`hotel_name`,
@@ -77,6 +80,7 @@ class AdminOrdersControllerCore extends AdminController
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `'._DB_PREFIX_.'currency` cu ON (cu.`id_currency` = a.`id_currency`)
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int) $this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = a.`id_order`)
@@ -200,6 +204,11 @@ class AdminOrdersControllerCore extends AdminController
'payment' => array(
'title' => $this->l('Payment')
),
'currency' => array(
'title' => $this->l('Payment Currency'),
'hint' => $this->l('This is the currency in which customer made the payment'),
'havingFilter' => true,
),
'osname' => array(
'title' => $this->l('Status'),
'type' => 'select',
@@ -5494,4 +5503,4 @@ class AdminOrdersControllerCore extends AdminController
}
}
}
}
}

View File

@@ -224,6 +224,9 @@
<configuration id="PS_CONDITIONS_CMS_ID" name="PS_CONDITIONS_CMS_ID">
<value>3</value>
</configuration>
<configuration id="PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY" name="PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY">
<value>1</value>
</configuration>
<configuration id="TRACKING_DIRECT_TRAFFIC" name="TRACKING_DIRECT_TRAFFIC">
<value>0</value>
</configuration>
@@ -906,4 +909,4 @@
<value>1</value>
</configuration>
</entities>
</entity_configuration>
</entity_configuration>