Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WOOCS Currency Switcher plugin support #316

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions includes/api/coupon-apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* for coupon related API
*/


require_once __DIR__ . '/../support/woocs-multicurrency.php';

function applyCouponOnCart(WP_REST_Request $request)
{
global $woocommerce;
Expand Down Expand Up @@ -165,6 +168,17 @@ function applyCouponOnCart(WP_REST_Request $request)
$promotion["value"] = round($discountAmount ?? 0);
$response["promotion"] = $promotion;



if(is_plugin_active('woocommerce-currency-switcher/index.php')){
$is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0);

if($is_multiple_allowed==1){
$order = wc_get_order($orderId);
$response['promotion']['value'] = currencyConvert($response['promotion']['value'],$order);
}
}

if ($couponError["failure_reason"] === "") {
$logObj["response"] = $response;
rzpLogInfo(json_encode($logObj));
Expand Down
2 changes: 1 addition & 1 deletion includes/api/save-abandonment-data.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,4 @@ function checkRecordBySession($cookie)
);

return $results;
}
}
25 changes: 19 additions & 6 deletions includes/api/shipping-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @return array|WP_Error|WP_REST_Response
* @throws Exception If failed to add items to cart or no shipping options available for address.
*/
require_once __DIR__ . '/../support/woocs-multicurrency.php';

function calculateShipping1cc(WP_REST_Request $request)
{
$params = $request->get_params();
Expand Down Expand Up @@ -62,7 +64,16 @@ function calculateShipping1cc(WP_REST_Request $request)
// Cleanup cart.
WC()->cart->empty_cart();
$logObj['response'] = $response;
rzpLogInfo(json_encode($logObj));

if(is_plugin_active('woocommerce-currency-switcher/index.php')){
$is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0);

if($is_multiple_allowed==1){
$order = wc_get_order($orderId);
$response['0']['shipping_fee'] = currencyConvertCS($response['0']['shipping_fee'],$order);
}
}

return new WP_REST_Response(array('addresses' => $response), 200);
}

Expand Down Expand Up @@ -141,6 +152,7 @@ function shippingCalculatePackages1cc($id, $orderId, $address)
$vendorId[] = $packages[$key]['vendor_id'];
}
}

$calculatedPackages = wc()->shipping()->calculate_shipping($packages);

return getItemResponse1cc($calculatedPackages, $id, $vendorId, $orderId, $address);
Expand Down Expand Up @@ -247,7 +259,6 @@ function prepareRatesResponse1cc($package, $vendorId, $orderId, $address)

function getRateResponse1cc($rate, $vendorId, $orderId, $address)
{

return array_merge(
array(
'rate_id' => getRateProp1cc($rate, 'id'),
Expand Down Expand Up @@ -598,11 +609,13 @@ function smartCodRestriction($addresses, $order)
* @returns int
*/
function convertToPaisa($price)
{
{
if (is_string($price)) {
$price = (int) $price;
$price = floatval($price);
}
return $price * 100;
round($price,2);

return ($price * 100);
}

/**
Expand Down Expand Up @@ -695,4 +708,4 @@ function prepareHtmlResponse1cc($response)
return array_map('prepareHtmlResponse1cc', $response);
}
return is_scalar($response) ? wp_kses_post(trim(convert_chars(wptexturize($response)))) : $response;
}
}
18 changes: 18 additions & 0 deletions includes/support/woocs-multicurrency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
function currencyConvertCS($amountInPaise,$order){
global $WOOCS;
$orderCurrency = getOrderCurrencyCS($order);
$currencies = $WOOCS->get_currencies();
$orderRate = $currencies[$orderCurrency]['rate'];
return round($orderRate*$amountInPaise,0);
}

function getOrderCurrencyCS($order)
{
if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>='))
{
return $order->get_currency();
}

return $order->get_order_currency();
}
6 changes: 6 additions & 0 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,12 @@ public function getDefaultCheckoutArguments($order)
*/
private function getOrderCurrency($order)
{
if(is_plugin_active('woocommerce-currency-switcher/index.php')){
$is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0);
if($is_multiple_allowed==0){
return get_option('woocs_welcome_currency',0);
}
}
if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>='))
{
return $order->get_currency();
Expand Down