Skip to content

Commit

Permalink
Merge pull request #289 from razorpay/1cc-update-conflict
Browse files Browse the repository at this point in the history
[PLG-211] Handled the dual shipping charge issue on magic.
  • Loading branch information
ChetanGN authored Jun 8, 2022
2 parents 0e4b2ae + 381426a commit 64077c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions includes/api/shipping-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ function getCodShippingInfo1cc($instanceId, $methodId, $orderId, $address)

$availablePaymentMethods = WC()->payment_gateways->payment_gateways();

$minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0;
$maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0;

if (!isset($availablePaymentMethods['cod']) || 'no' == $availablePaymentMethods['cod']->enabled || !(($minCODAmount1cc <= $amount) && ($maxCODAmount1cc <= $amount))) {
return false;
}

$minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0;
$maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0;

$order = wc_get_order($orderId);
$amount = floatval($order->get_total());

Expand Down Expand Up @@ -431,6 +431,7 @@ function smartCodRestriction($addresses, $order)
$postals = explode(',', trim($restriction['restrict_postals']));
$postals = array_map('trim', $postals);
$customerZipcode = $addresses['zipcode'];
$flag = 0;

foreach ($postals as $p) {
if (!$p) {
Expand Down
15 changes: 15 additions & 0 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,9 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId)
//Apply coupon to woo-order
if (empty($couponKey) === false)
{
// Remove the same coupon, if already being added to order.
$order->remove_coupon($couponKey);

//TODO: Convert all razorpay amount in paise to rupees
$discount_total = $razorpayData['promotions'][0]['value']/100;

Expand All @@ -1463,6 +1466,18 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId)
//Apply shipping charges to woo-order
if(isset($razorpayData['shipping_fee']) === true)
{

//To remove by default shipping method added on order.
$existingItems = (array) $order->get_items('shipping');
rzpLogInfo("Shipping details updated for orderId: $wcOrderId is".json_encode($existingItems));

if (sizeof($existingItems) != 0) {
// Loop through shipping items
foreach ($existingItems as $existingItemId) {
$order->remove_item($existingItemId);
}
}

// Get a new instance of the WC_Order_Item_Shipping Object
$item = new WC_Order_Item_Shipping();

Expand Down

0 comments on commit 64077c5

Please sign in to comment.