Skip to content

Commit

Permalink
Merge pull request #896 from sumitwebkul/gli-1607
Browse files Browse the repository at this point in the history
Added: Configuration for Showing prices in Order list in (Default currency or Payment Currency)
  • Loading branch information
rohit053 authored Mar 15, 2024
2 parents d4a72ac + 0c86d0d commit 5c4c203
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
10 changes: 10 additions & 0 deletions classes/order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

const ORDER_COMPLETE_REFUND_FLAG = 1;
const ORDER_COMPLETE_CANCELLATION_FLAG = 2;
const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3;
Expand Down Expand Up @@ -1839,6 +1843,12 @@ public function addOrderPayment($amount_paid, $payment_method = null, $payment_t
}
}

// Whenever payment is adding in any order then set a cumulative conversion rate for the payment currency in the order
if ($avgConversionRate = $order_payment->getAverageConversionRate($this->reference, $this->id_currency)) {
$this->conversion_rate = $avgConversionRate;
}
$this->save();

return $res;
}

Expand Down
11 changes: 11 additions & 0 deletions classes/order/OrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,15 @@ public function getOrderInvoice($id_order)

return new OrderInvoice((int)$res);
}

/**
* Provides the average conversion rate for a given order in any currency
* @param [string] $order_reference
* @param [int] $idCurrency
* @return float
*/
public function getAverageConversionRate($order_reference, $idCurrency)
{
return Db::getInstance()->getValue('SELECT (SUM(`amount` * `conversion_rate`) / SUM(`amount`)) FROM `'._DB_PREFIX_.'order_payment` WHERE `order_reference` = \''.pSQL($order_reference).'\' AND `id_currency` = '.(int)$idCurrency);
}
}
22 changes: 22 additions & 0 deletions controllers/admin/AdminOrderPreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public function __construct()
)
);

// Options to display currency in order list
$displayCurrencyOptions = array(
array(
'value' => Order::ORDER_LIST_PRICE_DISPLAY_IN_PAYMENT_CURRENCY,
'name' => $this->l('Order 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'),
Expand Down Expand Up @@ -159,6 +171,16 @@ public function __construct()
'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.'),
'desc' => $this->l('\'Order currency\' is the currency in which customer created the order and \'Default currency\' is the currency configured in localization.'),
'validation' => 'isInt',
'type' => 'select',
'cast' => 'intval',
'list' => $displayCurrencyOptions,
'identifier' => 'value',
),
),
'submit' => array('title' => $this->l('Save'))
),
Expand Down
21 changes: 17 additions & 4 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public function __construct()
$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`,
Expand All @@ -81,6 +84,7 @@ public function __construct()

$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`)
Expand Down Expand Up @@ -254,6 +258,11 @@ public function __construct()
'payment' => array(
'title' => $this->l('Payment')
),
'currency' => array(
'title' => $this->l('Order Currency'),
'hint' => $this->l('This is the currency in which customer created the order.'),
'havingFilter' => true,
),
'order_source' => array(
'title' => $this->l('Order Source'),
'type' => 'select',
Expand Down Expand Up @@ -321,10 +330,14 @@ public function __construct()
$this->_conf[53] = $this->l('Room in the booking is successfully swapped');
}

public static function setOrderCurrency($echo, $tr)
public static function setOrderCurrency($echo, $row)
{
$order = new Order($tr['id_order']);
return Tools::displayPrice($echo, (int)$order->id_currency);
if (Configuration::get('PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY') == Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY) {
$idCurrency = Configuration::get('PS_CURRENCY_DEFAULT');
} else {
$idCurrency = $row['id_currency'];
}
return Tools::displayPrice($echo, (int)$idCurrency);
}

public function renderForm()
Expand Down
5 changes: 4 additions & 1 deletion install/data/xml/configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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>
Expand Down Expand Up @@ -903,4 +906,4 @@
<value>1</value>
</configuration>
</entities>
</entity_configuration>
</entity_configuration>

0 comments on commit 5c4c203

Please sign in to comment.