From db56e4b2df4308ab9f2a9b78975e21c32f4e94dc Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Tue, 30 Apr 2019 17:53:59 +0530 Subject: [PATCH] issue #814 --- .../Webkul/Payment/src/Config/paymentmethods.php | 9 ++++++--- packages/Webkul/Payment/src/Payment.php | 9 +++++++++ packages/Webkul/Payment/src/Payment/Payment.php | 12 +++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/Webkul/Payment/src/Config/paymentmethods.php b/packages/Webkul/Payment/src/Config/paymentmethods.php index bfd1ae357..5f5b6433c 100755 --- a/packages/Webkul/Payment/src/Config/paymentmethods.php +++ b/packages/Webkul/Payment/src/Config/paymentmethods.php @@ -5,7 +5,8 @@ return [ 'title' => 'Cash On Delivery', 'description' => 'Cash On Delivery', 'class' => 'Webkul\Payment\Payment\CashOnDelivery', - 'active' => true + 'active' => true, + 'sort' => 1 ], 'moneytransfer' => [ @@ -13,7 +14,8 @@ return [ 'title' => 'Money Transfer', 'description' => 'Money Transfer', 'class' => 'Webkul\Payment\Payment\MoneyTransfer', - 'active' => true + 'active' => true, + 'sort' => 2 ], 'paypal_standard' => [ @@ -23,6 +25,7 @@ return [ 'class' => 'Webkul\Paypal\Payment\Standard', 'sandbox' => true, 'active' => true, - 'business_account' => 'test@webkul.com' + 'business_account' => 'test@webkul.com', + 'sort' => 3 ] ]; \ No newline at end of file diff --git a/packages/Webkul/Payment/src/Payment.php b/packages/Webkul/Payment/src/Payment.php index fbd8a1ece..7de60161f 100755 --- a/packages/Webkul/Payment/src/Payment.php +++ b/packages/Webkul/Payment/src/Payment.php @@ -24,10 +24,19 @@ class Payment 'method' => $object->getCode(), 'method_title' => $object->getTitle(), 'description' => $object->getDescription(), + 'sort' => $object->getSortOrder(), ]; } } + usort ($paymentMethods, function($a, $b) { + if ($a['sort'] == $b['sort']) { + return 0; + } + + return ($a['sort'] < $b['sort']) ? -1 : 1; + }); + return [ 'jump_to_section' => 'payment', 'html' => view('shop::checkout.onepage.payment', compact('paymentMethods'))->render() diff --git a/packages/Webkul/Payment/src/Payment/Payment.php b/packages/Webkul/Payment/src/Payment/Payment.php index 5b0e90d2b..f2acea2d1 100755 --- a/packages/Webkul/Payment/src/Payment/Payment.php +++ b/packages/Webkul/Payment/src/Payment/Payment.php @@ -13,7 +13,7 @@ abstract class Payment * @var Cart */ protected $cart; - + /** * Checks if payment method is available * @@ -109,4 +109,14 @@ abstract class Payment return $this->cart->items; } + + /** + * Returns payment method sort order + * + * @return array + */ + public function getSortOrder() + { + return $this->getConfigData('sort'); + } } \ No newline at end of file