Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Pass checkout info to payment and shipping methods to allow showing shipping and payment options based on adddress location like country/region
givanzd7c01a4604b1
diff --git a/app/component/checkout/payment.php b/app/component/checkout/payment.phpindex 0947502..e38bb88 100755--- a/app/component/checkout/payment.php+++ b/app/component/checkout/payment.php@@ -22,23 +22,31 @@namespace Vvveb\Component\Checkout;+use function Vvveb\session as sess;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Payment as PaymentApi;class Payment extends ComponentBase {public static $defaultOptions = [+ 'checkout' => null,];- //disable cache- function cache() {+ function cacheKey() {+ //disable cachingreturn false;}function results() {+ $checkoutInfo = [];++ if ($this->options['checkout']) {+ $checkoutInfo = sess('checkout', []) ?? [];+ }+$results = [];$payment = PaymentApi::getInstance();- $results['payment'] = $payment->getMethods();+ $results['payment'] = $payment->getMethods($checkoutInfo);$results['count'] = $results['payment'] ? count($results['payment']) : 0;list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);diff --git a/app/component/checkout/shipping.php b/app/component/checkout/shipping.phpindex 69cfec5..498e29e 100755--- a/app/component/checkout/shipping.php+++ b/app/component/checkout/shipping.php@@ -22,18 +22,31 @@namespace Vvveb\Component\Checkout;+use function Vvveb\session as sess;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Shipping as ShippingApi;class Shipping extends ComponentBase {public static $defaultOptions = [+ 'checkout' => null,];+ function cacheKey() {+ //disable caching+ return false;+ }+function results() {+ $checkoutInfo = [];++ if ($this->options['checkout']) {+ $checkoutInfo = sess('checkout', []) ?? [];+ }+$results = [];$shipping = ShippingApi::getInstance();- $results['shipping'] = $shipping->getMethods();+ $results['shipping'] = $shipping->getMethods($checkoutInfo);$results['count'] = $results['shipping'] ? count($results['shipping']) : 0;list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.phpindex 5389d51..c1f5d74 100755--- a/app/controller/checkout/checkout.php+++ b/app/controller/checkout/checkout.php@@ -35,7 +35,6 @@ use Vvveb\Sql\User_AddressSQL;use Vvveb\System\CacheManager;use Vvveb\System\Cart\Cart;use Vvveb\System\Cart\Order;-use Vvveb\System\Core\View;use Vvveb\System\Event;use Vvveb\System\Payment;use Vvveb\System\Shipping;@@ -70,14 +69,14 @@ class Checkout extends Base {$options['status'] = 1;unset($options['limit']);$options['country_id'] = $country_id;- $regions = $region->getAll($options)['region'] ?? [];+ $regions = $region->getAll($options)['region'] ?? [];}$this->response->setType('json');$this->response->output($regions);}- private function data() {+ private function data(&$checkoutInfo) {$countryModel = new CountrySQL();$options = $this->global;$options['status'] = 1;@@ -85,14 +84,19 @@ class Checkout extends Base {$country = $countryModel->getAll($options);$this->view->countries = $country['country'] ?? [];- //set Regions for default store country- /*- $region = new RegionSQL();- $regions = $countryModel->getAll($options);+ //set default contry and region+ $checkoutInfo['billing_country_id'] = $checkoutInfo['billing_country_id'] ?? $this->global['site']['country_id'] ?? false;+ $checkoutInfo['shipping_country_id'] = $checkoutInfo['shipping_country_id'] ?? $this->global['site']['country_id'] ?? false;+ $checkoutInfo['shipping_region_id'] = $checkoutInfo['shipping_region_id'] ?? $this->global['site']['region_id'] ?? false;+ $checkoutInfo['billing_region_id'] = $checkoutInfo['billing_region_id'] ?? $this->global['site']['region_id'] ?? false;+ $country_id = $checkoutInfo['billing_country_id'] ?? $checkoutInfo['shipping_country_id'] ?? false;- $options['country_id'] = $country_id;- $this->view->regions = $regions['region'] ?? [];- */+ if ($country_id) {+ $region = new RegionSQL();+ $regions = $region->getAll(['country_id' => $country_id]);++ $this->view->regions = $regions['region'] ?? [];+ }$this->view->regionsUrl = url(['module' => 'checkout/checkout', 'action' => 'regions']);}@@ -110,206 +114,221 @@ class Checkout extends Base {return $this->redirect('cart/cart/index');}- $payment = Payment::getInstance();- $shipping = Shipping::getInstance();$order = Order::getInstance();- $this->view->payment = $payment->getMethods();- $this->view->shipping = $shipping->getMethods();- $this->data();-if (isset($this->request->post['login'])) {return $this->login();}+ $checkoutInfo = $this->session->get('checkout') ?? [];++ $payment = Payment::getInstance();+ $shipping = Shipping::getInstance();++ $this->view->payment = $payment->getMethods($checkoutInfo);+ $this->view->shipping = $shipping->getMethods($checkoutInfo);+if (isset($this->request->post['shipping_method'])) {- $shipping->setMethod($this->request->post['shipping_method']);- $this->view->shipping_method = $this->request->post['shipping_method'];+ $shipping_method = $this->request->post['shipping_method'];+ $shipping->setMethod($shipping_method);+ $checkoutInfo['shipping_method'] = $shipping_method;+ $this->view->shipping_method = $shipping_method;}if (isset($this->request->post['payment_method'])) {- $payment->setMethod($this->request->post['payment_method']);- $this->view->payment_method = $this->request->post['payment_method'];+ $payment_method = $this->request->post['payment_method'];+ $payment->setMethod($payment_method);+ $checkoutInfo['payment_method'] = $payment_method;+ $this->view->payment_method = $payment_method;}- if ($this->request->post && (- isset($this->request->post['phone_number']) ||+ $this->data($checkoutInfo);++ if ($this->request->post) {+ if (isset($this->request->post['phone_number']) ||isset($this->request->post['billing_address']) ||- isset($this->request->post['billing_address_id']) ||- isset($this->request->post['email']))) {- $rules = ['checkout'];-- // guest checkout- if (! $this->global['user_id']) {- //password is provided- if (isset($this->request->post['register']) && $this->request->post['register'] == 'true') {- $rules[] = 'checkout_signup';+ isset($this->request->post['billing_address_id']) || /*+ isset($this->request->post['shipping_method']) ||+ isset($this->request->post['payment_method']) ||*/+ isset($this->request->post['email'])) {+ $rules = ['checkout'];++ // guest checkout+ if (! $this->global['user_id']) {+ //password is provided+ if (isset($this->request->post['register']) && $this->request->post['register'] == 'true') {+ $rules[] = 'checkout_signup';+ } else {+ $rules[] = 'guest';+ }} else {+ //registered user$rules[] = 'guest';- }- } else {- //registered user- $rules[] = 'guest';- foreach (['first_name', 'last_name', 'email', 'phone_number'] as $field) {- $this->request->post[$field] = $this->request->post[$field] ?? $this->global['user'][$field];+ foreach (['first_name', 'last_name', 'email', 'phone_number'] as $field) {+ $this->request->post[$field] = $this->request->post[$field] ?? $this->global['user'][$field];+ }}- }- //billing address address check- if (empty($this->request->post['billing_address_id'])) {- $rules[] = 'checkout_billing';+ //billing address address check+ if (empty($this->request->post['billing_address_id'])) {+ $rules[] = 'checkout_billing';- if (isset($this->request->post['billing_address'])) {- //if billing name is missing use account name- //$this->request->post['billing_address']['first_name'] ??= $this->request->post['first_name'];- //$this->request->post['billing_address']['last_name'] ??= $this->request->post['last_name'];- $this->request->post['billing_address']['first_name'] = $this->request->post['billing_address']['first_name'] ?? $this->request->post['first_name'];- $this->request->post['billing_address']['last_name'] = $this->request->post['billing_address']['last_name'] ?? $this->request->post['last_name'];+ if (isset($this->request->post['billing_address'])) {+ //if billing name is missing use account name+ //$this->request->post['billing_address']['first_name'] ??= $this->request->post['first_name'];+ //$this->request->post['billing_address']['last_name'] ??= $this->request->post['last_name'];+ $this->request->post['billing_address']['first_name'] = $this->request->post['billing_address']['first_name'] ?? $this->request->post['first_name'] ?? '';+ $this->request->post['billing_address']['last_name'] = $this->request->post['billing_address']['last_name'] ?? $this->request->post['last_name'] ?? '';- $billing_address = $this->request->post['billing_address'];- $this->request->post += prefixArrayKeys('billing_', $billing_address);- }- } else {- //user address- $rules[] = 'checkout_billing';- $billing_address_id = $this->request->post['billing_address_id'];- $addressSql = new User_AddressSQL();- $address = $addressSql->get($this->global + ['user_address_id' => $billing_address_id]);-- if ($address) {- $this->request->post['billing_address'] = $address;- $this->request->post += prefixArrayKeys('billing_', $address);+ $billing_address = $this->request->post['billing_address'];+ $this->request->post += prefixArrayKeys('billing_', $billing_address);+ }+ } else {+ //user address+ $rules[] = 'checkout_billing';+ $billing_address_id = $this->request->post['billing_address_id'];+ $addressSql = new User_AddressSQL();+ $address = $addressSql->get($this->global + ['user_address_id' => $billing_address_id]);++ if ($address) {+ $this->request->post['billing_address'] = $address;+ $this->request->post += prefixArrayKeys('billing_', $address);+ }}- }- //different shipping address is selected- if (isset($this->request->post['different_shipping_address']) && ! empty($this->request->post['different_shipping_address'])) {- $rules[] = 'checkout_shipping';+ //different shipping address is selected+ if (isset($this->request->post['different_shipping_address']) && ! empty($this->request->post['different_shipping_address'])) {+ $rules[] = 'checkout_shipping';- if (isset($this->request->post['shipping_address'])) {- $shipping_address = $this->request->post['shipping_address'];- $this->request->post += prefixArrayKeys('shipping_', $shipping_address);- }- } else {- //use billing address as shipping address- $rules[] = 'checkout_shipping';+ if (isset($this->request->post['shipping_address'])) {+ $shipping_address = $this->request->post['shipping_address'];+ $this->request->post += prefixArrayKeys('shipping_', $shipping_address);+ }+ } else {+ //use billing address as shipping address+ $rules[] = 'checkout_shipping';- if (isset($this->request->post['billing_address'])) {- $this->request->post['shipping_address'] = $this->request->post['billing_address'];- $this->request->post += prefixArrayKeys('shipping_', $this->request->post['shipping_address']);+ if (isset($this->request->post['billing_address'])) {+ $this->request->post['shipping_address'] = $this->request->post['billing_address'];+ $this->request->post += prefixArrayKeys('shipping_', $this->request->post['shipping_address']);+ }}- }- $validator = new Validator($rules);- $checkoutInfo = $validator->filter($this->request->post);-- if (($errors = $validator->validate($this->request->post)) === true) {//allow only fields that are in the validator list and remove the rest+ $validator = new Validator($rules);+ $checkoutInfo = ($validator->filter($this->request->post) ?? []) + $checkoutInfo;- $checkoutInfo = $validator->filter($this->request->post);- $checkoutInfo['products'] = $cart->getAll();- $checkoutInfo['product_options'] = $cart->getProductOptions();- $checkoutInfo['totals'] = $cart->getTotals();- $checkoutInfo['total'] = $cart->getGrandTotal();- $checkoutInfo += $this->global;+ $this->session->set('checkout', $checkoutInfo);- //create user account if password is provided- if (isset($checkoutInfo['password']) && ! $this->global['user_id']) {- $userInfo = [];+ if (($errors = $validator->validate($this->request->post)) === true) {+ $checkoutInfo['products'] = $cart->getAll();+ $checkoutInfo['product_options'] = $cart->getProductOptions();+ $checkoutInfo['totals'] = $cart->getTotals();+ $checkoutInfo['total'] = $cart->getGrandTotal();+ $checkoutInfo += $this->global;- foreach (['first_name', 'last_name', 'email', 'phone_number', 'password'] as $field) {- $userInfo[$field] = $checkoutInfo[$field] ?? NULL;- }- $userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];- $userInfo['username'] = str_replace(' ', '', $userInfo['first_name'] . $userInfo['last_name']);+ //create user account if password is provided+ if (isset($checkoutInfo['password']) && ! $this->global['user_id']) {+ $userInfo = [];++ foreach (['first_name', 'last_name', 'email', 'phone_number', 'password'] as $field) {+ $userInfo[$field] = $checkoutInfo[$field] ?? NULL;+ }+ $userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];+ $userInfo['username'] = str_replace(' ', '', $userInfo['first_name'] . $userInfo['last_name']);- $error = __('Error creating account!');+ $error = __('Error creating account!');- if ($result = User::add($userInfo)) {- $checkoutInfo['user_id'] = $result['user'] ?? NULL;- } else {- $this->view->errors[] = $error;+ if ($result = User::add($userInfo)) {+ $checkoutInfo['user_id'] = $result['user'] ?? NULL;+ } else {+ $this->view->errors[] = $error;+ }}- }- $user_id = $checkoutInfo['user_id'] ?? $this->global['user_id'];+ $user_id = $checkoutInfo['user_id'] ?? $this->global['user_id'];- //if new address add to user account- if (empty($this->request->post['billing_address_id']) && $user_id) {- $addressSql = new User_AddressSQL();- $address = $addressSql->add(['user_address' => $this->request->post['billing_address'] + ['user_id' => $user_id]]);- }+ //if new address add to user account+ if (empty($this->request->post['billing_address_id']) && $user_id) {+ $addressSql = new User_AddressSQL();+ $address = $addressSql->add(['user_address' => $this->request->post['billing_address'] + ['user_id' => $user_id]]);+ }- //if account does not have a phone number set add phone number to user profile for next order- if ($this->global['user_id'] && ! $this->global['user']['phone_number']) {- User::update(['phone_number' => $checkoutInfo['phone_number']], ['user_id' => $this->global['user_id']]);- User::session(['phone_number' => $checkoutInfo['phone_number']]);- }+ //if account does not have a phone number set add phone number to user profile for next order+ if ($this->global['user_id'] && ! $this->global['user']['phone_number']) {+ User::update(['phone_number' => $checkoutInfo['phone_number']], ['user_id' => $this->global['user_id']]);+ User::session(['phone_number' => $checkoutInfo['phone_number']]);+ }- if (! $checkoutInfo['user_id']) {- unset($checkoutInfo['user_id']); //if anonymous then unset user_id- }+ if (! $checkoutInfo['user_id']) {+ unset($checkoutInfo['user_id']); //if anonymous then unset user_id+ }- $checkoutInfo['shipping_data'] = json_encode($this->view->shipping[$checkoutInfo['shipping_method']] ?? []);- $checkoutInfo['payment_data'] = json_encode($this->view->payment[$checkoutInfo['payment_method']] ?? []);- //default order status- $checkoutInfo['order_status_id'] = 1;+ $checkoutInfo['shipping_data'] = json_encode($this->view->shipping[$checkoutInfo['shipping_method']] ?? []);+ $checkoutInfo['payment_data'] = json_encode($this->view->payment[$checkoutInfo['payment_method']] ?? []);+ //default order status+ $checkoutInfo['order_status_id'] = 1;- $site = Sites :: getSiteData();+ $site = Sites :: getSiteData();- $order_url = url('user/orders', [- 'host' => $site['host'] ?? false,- 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',- ]);+ $order_url = url('user/orders', [+ 'host' => $site['host'] ?? false,+ 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',+ ]);- $checkoutInfo['site_url'] = $site['host'];- $checkoutInfo['site_name'] = $site['name'];+ $checkoutInfo['site_url'] = $site['host'];+ $checkoutInfo['site_name'] = $site['name'];- $this->view->errors = [];+ $this->view->errors = [];- list($checkoutInfo) = Event::trigger(__CLASS__, 'add', $checkoutInfo);+ list($checkoutInfo) = Event::trigger(__CLASS__, 'add', $checkoutInfo);- $checkoutInfo = $order->add($checkoutInfo);+ $checkoutInfo = $order->add($checkoutInfo);- if ($checkoutInfo && $checkoutInfo['order_id']) {- $order_id = $checkoutInfo['order_id'];- $customer_order_id = $checkoutInfo['customer_order_id'];- $this->request->request['order_id'] = $order_id;- $checkoutInfo['order_id'] = $order_id;+ if ($checkoutInfo && $checkoutInfo['order_id']) {+ $order_id = $checkoutInfo['order_id'];+ $customer_order_id = $checkoutInfo['customer_order_id'];+ $this->request->request['order_id'] = $order_id;+ $checkoutInfo['order_id'] = $order_id;- $this->view->messages[] = __('Order placed!');- $this->session->set('order', $checkoutInfo);- $cart->empty();- $site = siteSettings();+ $this->view->messages[] = __('Order placed!');+ $this->session->set('order', $checkoutInfo);+ $cart->empty();+ $site = siteSettings();- list($checkoutInfo, $order_id, $site) = Event::trigger(__CLASS__, 'add:after', $checkoutInfo, $order_id, $site);+ list($checkoutInfo, $order_id, $site) = Event::trigger(__CLASS__, 'add:after', $checkoutInfo, $order_id, $site);- try {- $error = __('Error sending order confirmation mail!');+ try {+ $error = __('Error sending order confirmation mail!');- if (! email([$checkoutInfo['email'], $site['admin-email']], sprintf(__('Order confirmation #%s'), $customer_order_id), 'order/new', $checkoutInfo)) {+ if (! email([$checkoutInfo['email'], $site['admin-email']], sprintf(__('Order confirmation #%s'), $customer_order_id), 'order/new', $checkoutInfo)) {+ $this->session->set('errors', $error);+ $this->view->errors[] = $error;+ }+ } catch (\Exception $e) {+ if (DEBUG) {+ $error .= "\n" . $e->getMessage();+ }$this->session->set('errors', $error);$this->view->errors[] = $error;}- } catch (\Exception $e) {- if (DEBUG) {- $error .= "\n" . $e->getMessage();- }- $this->session->set('errors', $error);- $this->view->errors[] = $error;- }- // clear notifications cache- CacheManager :: clearObjectCache('component', 'notifications');+ // clear notifications cache+ CacheManager :: clearObjectCache('component', 'notifications');- return $this->redirect('checkout/confirm/index');+ return $this->redirect('checkout/confirm/index');+ } else {+ $this->view->errors[] = __('Error creating checkout!');+ }} else {- $this->view->errors[] = __('Error creating checkout!');+ $this->view->errors = $errors;}- } else {- $this->view->errors = $errors;}++ $this->session->set('checkout', $checkoutInfo);}++ $this->view->checkout = $checkoutInfo;}}diff --git a/app/template/checkout/checkout.tpl b/app/template/checkout/checkout.tplindex 42c60ca..20d8b66 100755--- a/app/template/checkout/checkout.tpl+++ b/app/template/checkout/checkout.tpl@@ -4,7 +4,7 @@/* input elements */input[type="text"]|value =<?php- $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';+ $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';$value = '@@__value__@@';if ($post)echo $post;@@ -13,7 +13,7 @@ input[type="text"]|value =input[type="email"]|value =<?php- $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';+ $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';$value = '@@__value__@@';if ($post)echo $post;@@ -22,7 +22,7 @@ input[type="email"]|value =input[type="password"]|value =<?php- $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';+ $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';$value = '@@__value__@@';if ($post)echo $post;@@ -33,7 +33,7 @@ input[type="password"]|value =/* textarea elements */textarea =<?php- $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';+ $post = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout@@macro postNameToArrayKey("@@__name__@@")@@ ?? '';$value = '@@__value__@@';if ($post)echo $post;@@ -74,19 +74,26 @@ input[name="different_shipping_address"]|addNewAttribute =[data-v-payment] input[name="payment_method"]|addNewAttribute = <?php- if (isset($_POST['payment_method']) && ($_POST['payment_method'] == $payment['name'])) echo ' checked';+ $payment_method = $_POST['payment_method'] ?? $this->checkout['payment_method'] ?? '';+ if ($payment_method == $payment['name']) echo ' checked';?>[data-v-shipping] input[name="shipping_method"]|addNewAttribute = <?php- if (isset($_POST['shipping_method']) && ($_POST['shipping_method'] == $shipping['name'])) echo ' checked';+ $shipping_method = $_POST['shipping_method'] ?? $this->checkout['shipping_method'] ?? '';+ if ($shipping_method == $shipping['name']) echo ' checked';?>@country = [data-v-countries] option@country|deleteAllButFirstChild+[data-v-countries]|before = <?php+ $country_id = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout["@@__id__@@"] ?? false;+?>+@country|before = <?php$count = 0;$country_index = 0;+if(isset($this->countries) && is_array($this->countries)) {foreach ($this->countries as $country_index => $country) {?>@@ -95,7 +102,7 @@ if(isset($this->countries) && is_array($this->countries)) {@country|innerText = $country['name']@country|value = $country['country_id']- @country|addNewAttribute = <?php if (isset($region['country_id']) && ($country['country_id'] == $region['country_id'])) echo 'selected';?>+ @country|addNewAttribute = <?php if ($country_id && ($country['country_id'] == $country_id)) echo 'selected';?>@country|after = <?php$count++;@@ -103,4 +110,31 @@ if(isset($this->countries) && is_array($this->countries)) {}?>+@region = [data-v-regions] option+@region|deleteAllButFirstChild++[data-v-regions]|before = <?php+ $region_id = $_POST@@macro postNameToArrayKey("@@__name__@@")@@ ?? $this->checkout["@@__id__@@"] ?? false;+?>++@region|before = <?php+$count = 0;+$region_index = 0;++if(isset($this->regions) && is_array($this->regions)) {+ foreach ($this->regions as $region_index => $region) {?>++ [data-v-region-*]|innerText = $region['@@__data-v-region-(*)__@@']+ option[data-v-region-*]|value = $region['@@__data-v-region-(*)__@@']++ @region|innerText = $region['name']+ @region|value = $region['region_id']+ @region|addNewAttribute = <?php if ($region_id && ($region['region_id'] == $region_id)) echo 'selected';?>++ @region|after = <?php+ $count++;+ }+}?>++import(common.tpl)diff --git a/app/template/components/checkout/payment.tpl b/app/template/components/checkout/payment.tplindex a1ce476..7d27c92 100755--- a/app/template/components/checkout/payment.tpl+++ b/app/template/components/checkout/payment.tpl@@ -25,6 +25,8 @@ if($payments && is_array($payments['payment'])) {@payment input[data-v-payment-*] = $payment['@@__data-v-payment-(*)__@@']+ @payment input[data-v-payment-name][type=radio]|addNewAttribute = <?php if ($payment_method == $payment['name']) echo 'checked';?>+@payment img[data-v-payment-*]|src = $payment['@@__data-v-payment-(*)__@@']@payment [data-v-payment-render]|innerText = <?php echo $payment['@@__data-v-payment-(*)__@@'] ?? '';?>diff --git a/app/template/components/checkout/shipping.tpl b/app/template/components/checkout/shipping.tplindex de03ec8..fe04a3d 100755--- a/app/template/components/checkout/shipping.tpl+++ b/app/template/components/checkout/shipping.tpl@@ -25,6 +25,8 @@ if($shippings && is_array($shippings['shipping'])) {@shipping input[data-v-shipping-*] = $shipping['@@__data-v-shipping-(*)__@@']+ @payment input[data-v-shipping-name]|addNewAttribute = <?php if ($shipping_method == $shipping['name']) echo 'checked';?>+@shipping img[data-v-shipping-*]|src = $shipping['@@__data-v-shipping-(*)__@@']@shipping [data-v-shipping-*]|innerText = $shipping['@@__data-v-shipping-(*)__@@']diff --git a/system/payment-method.php b/system/payment-method.phpindex 2b32695..ed7d401 100755--- a/system/payment-method.php+++ b/system/payment-method.php@@ -29,7 +29,9 @@ abstract class PaymentMethod {$this->cart = $cart;}- abstract public function getMethod();-abstract public function init();++ abstract public function getMethod($checkoutInfo = []);++ abstract public function setMethod();}diff --git a/system/payment.php b/system/payment.phpindex f9cccfc..ec86a19 100755--- a/system/payment.php+++ b/system/payment.php@@ -44,15 +44,14 @@ class Payment {public function __construct($options = []) {}- public function getMethods() {+ public function getMethods($checkoutInfo) {$data = [];- foreach ($this->methods as $name => $options) {- $class = $options[0];- $params = $options[1];- $obj = new $class(Cart::getInstance());- $this->instances[$name] = $obj;- $paymentData = $obj->getMethod($params);+ foreach ($this->methods as $name => $method) {+ list($class, $options) = $method;+ $obj = new $class(Cart::getInstance());+ $this->instances[$name] = $obj;+ $paymentData = $obj->getMethod($checkoutInfo, $options);//if payment method returns false or no data then don't add it to the listif ($paymentData) {$data[$name] = $paymentData;@@ -62,8 +61,8 @@ class Payment {return $data;}- public function registerMethod($method, $class, $params = []) {- $this->methods[$method] = [$class, $params];+ public function registerMethod($method, $class, $options = []) {+ $this->methods[$method] = [$class, $options];}public function setMethod($method) {diff --git a/system/shipping-method.php b/system/shipping-method.phpindex 6d9b834..53a52a9 100755--- a/system/shipping-method.php+++ b/system/shipping-method.php@@ -31,7 +31,7 @@ abstract class ShippingMethod {abstract public function init();- abstract public function getMethod();+ abstract public function getMethod($checkoutInfo = []);abstract public function setMethod();}diff --git a/system/shipping.php b/system/shipping.phpindex ab08a2a..9a4623e 100755--- a/system/shipping.php+++ b/system/shipping.php@@ -44,13 +44,14 @@ class Shipping {public function __construct($options = []) {}- public function getMethods() {+ public function getMethods($checkoutInfo) {$data = [];- foreach ($this->methods as $name => $class) {- $obj = new $class(Cart::getInstance());- $this->instances[$name] = $obj;- $shippingData = $obj->getMethod();+ foreach ($this->methods as $name => $method) {+ list($class, $options) = $method;+ $obj = new $class(Cart::getInstance());+ $this->instances[$name] = $obj;+ $shippingData = $obj->getMethod($checkoutInfo, $options);//if shipping method returns false or no data then don't add it to the listif ($shippingData) {$data[$name] = $shippingData;@@ -60,8 +61,8 @@ class Shipping {return $data;}- public function registerMethod($method, $class) {- $this->methods[$method] = $class;+ public function registerMethod($method, $class, $options = []) {+ $this->methods[$method] = [$class, $options];}public function setMethod($method) {