Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Checkout page: don't show shipping options if products don't require shipping (digital products), don't show payment options if total is zero (for free digital products download)

givanz0ed66bfacc8f
diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sql
index fb6c207..1d10c05 100755
--- a/admin/sql/mysqli/post.sql
+++ b/admin/sql/mysqli/post.sql
@@ -267,7 +267,7 @@
)
BEGIN
- SELECT _.*,pd.*,ad.admin_id,ad.username,ad.display_name,ad.email
+ SELECT _.*,pd.*,_.post_id,ad.admin_id,ad.username,ad.display_name,ad.email
@IF isset(:comment_count)
THEN
@@ -300,12 +300,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
THEN
AND pd.slug = :slug
END @IF
- @IF isset(:post_id)
+ @IF isset(:post_id) && :post_id > 0
THEN
AND _.post_id = :post_id
END @IF
diff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sql
index 2a6c303..56e1d99 100755
--- a/admin/sql/mysqli/product.sql
+++ b/admin/sql/mysqli/product.sql
@@ -32,7 +32,7 @@
)
BEGIN
-- product
- SELECT pc.*,_.*,
+ SELECT pc.*,_.*, _.product_id,
mf.slug as manufacturer_slug, mf.name as manufacturer_name,
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
@@ -144,12 +144,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
THEN
AND pc.slug = :slug
END @IF
- @IF isset(:product_id)
+ @IF isset(:product_id) && :product_id > 0
THEN
AND _.product_id = :product_id
END @IF
@@ -741,11 +741,17 @@
IN taxonomy_item_id INT,
IN manufacturer_id ARRAY,
IN vendor_id ARRAY,
+ IN option_value_id ARRAY,
IN related INT,
IN variant INT,
IN status INT,
IN search CHAR,
IN like CHAR,
+ IN sku CHAR,
+ IN barcode CHAR,
+ IN upc CHAR,
+ IN ean CHAR,
+ IN isbn CHAR,
IN slug ARRAY,
-- pagination
@@ -940,8 +946,18 @@
@IF !empty(:variant)
THEN
INNER JOIN product_variant pv ON (pv.product_variant_id = products.product_id)
- END @IF
+ END @IF
+ @IF !empty(:option_value_id)
+ THEN
+ INNER JOIN product_option_value pov ON (pov.product_id = products.product_id)
+ END @IF
+
+ @IF !empty(:product_attribute) AND !empty(:product_attribute_id)
+ THEN
+ INNER JOIN product_attribute pa ON (pa.product_id = products.product_id)
+ END @IF
+
WHERE p2s.site_id = :site_id
@@ -997,6 +1013,11 @@
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
+ END @IF
+
+ @IF isset(:barcode) && :barcode !== ""
+ THEN
+ AND products.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
@@ -1048,7 +1069,6 @@
AND pt.taxonomy_item_id = :taxonomy_item_id
END @IF
-
@IF isset(:slug) && count(:slug) > 0
THEN
@@ -1057,7 +1077,24 @@
END @IF
-
+ @IF !empty(:option_value_id)
+ THEN
+ AND pov.option_value_id IN (:option_value_id)
+ END @IF
+
+
+ @IF !empty(:product_attribute_id)
+ THEN
+ pa.product_attribute_id IN (:product_attribute_id)
+ END @IF
+
+
+ @IF !empty(:product_attribute)
+ THEN
+ pa.text IN (:product_attribute)
+ END @IF
+
+
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
diff --git a/admin/sql/pgsql/comment.sql b/admin/sql/pgsql/comment.sql
index 90f6f2e..9ac885a 100755
--- a/admin/sql/pgsql/comment.sql
+++ b/admin/sql/pgsql/comment.sql
@@ -30,7 +30,7 @@
END @IF
FROM comment AS comment
- LEFT JOIN "user" ON (comment.user_id = comment.user_id)
+ LEFT JOIN user ON (user.user_id = comment.user_id)
@IF isset(:post_title) AND :post_title
THEN
diff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sql
index b0122ca..8cdf552 100755
--- a/admin/sql/pgsql/post.sql
+++ b/admin/sql/pgsql/post.sql
@@ -207,7 +207,7 @@
)
BEGIN
- SELECT _.*,pd.*,ad.admin_id,ad.username,ad.display_name,ad.email
+ SELECT _.*,pd.*,_.post_id,ad.admin_id,ad.username,ad.display_name,ad.email
@IF isset(:comment_count)
THEN
@@ -240,12 +240,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
THEN
AND pd.slug = :slug
END @IF
- @IF isset(:post_id)
+ @IF isset(:post_id) && :post_id > 0
THEN
AND _.post_id = :post_id
END @IF
diff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sql
index bea96b5..4b283fc 100755
--- a/admin/sql/pgsql/product.sql
+++ b/admin/sql/pgsql/product.sql
@@ -32,7 +32,7 @@
)
BEGIN
-- product
- SELECT pc.*,_.*,
+ SELECT pc.*,_.*, _.product_id,
mf.slug as manufacturer_slug, mf.name as manufacturer_name,
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
@@ -144,12 +144,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
THEN
AND pc.slug = :slug
END @IF
- @IF isset(:product_id)
+ @IF isset(:product_id) && :product_id > 0
THEN
AND _.product_id = :product_id
END @IF
@@ -745,6 +745,11 @@
IN status INT,
IN search CHAR,
IN like CHAR,
+ IN sku CHAR,
+ IN barcode CHAR,
+ IN upc CHAR,
+ IN ean CHAR,
+ IN isbn CHAR,
IN slug ARRAY,
-- pagination
@@ -1000,6 +1005,11 @@
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
+ END @IF
+
+ @IF isset(:barcode) && :barcode !== ""
+ THEN
+ AND products.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
diff --git a/admin/sql/sqlite/comment.sql b/admin/sql/sqlite/comment.sql
index c465d64..7ddc58e 100755
--- a/admin/sql/sqlite/comment.sql
+++ b/admin/sql/sqlite/comment.sql
@@ -30,7 +30,7 @@
END @IF
FROM comment AS comment
- LEFT JOIN user ON (comment.user_id = comment.user_id)
+ LEFT JOIN user ON (user.user_id = comment.user_id)
@IF isset(:post_title) AND :post_title
THEN
diff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sql
index 9195448..0b108fc 100755
--- a/admin/sql/sqlite/post.sql
+++ b/admin/sql/sqlite/post.sql
@@ -202,7 +202,7 @@
)
BEGIN
- SELECT _.*,pd.*,ad.admin_id,ad.username,ad.display_name,ad.email
+ SELECT _.*,pd.*,_.post_id,ad.admin_id,ad.username,ad.display_name,ad.email
@IF isset(:comment_count)
THEN
@@ -235,12 +235,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
THEN
AND pd.slug = :slug
END @IF
- @IF isset(:post_id)
+ @IF isset(:post_id) && :post_id > 0
THEN
AND _.post_id = :post_id
END @IF
diff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sql
index d4ba487..8c1b5b6 100755
--- a/admin/sql/sqlite/product.sql
+++ b/admin/sql/sqlite/product.sql
@@ -32,7 +32,7 @@
)
BEGIN
-- product
- SELECT pc.*,_.*,
+ SELECT pc.*,_.*, _.product_id,
mf.slug as manufacturer_slug, mf.name as manufacturer_name,
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
@@ -144,12 +144,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
THEN
AND pc.slug = :slug
END @IF
- @IF isset(:product_id)
+ @IF isset(:product_id) && :product_id > 0
THEN
AND _.product_id = :product_id
END @IF
@@ -750,6 +750,11 @@
IN status INT,
IN search CHAR,
IN like CHAR,
+ IN sku CHAR,
+ IN barcode CHAR,
+ IN upc CHAR,
+ IN ean CHAR,
+ IN isbn CHAR,
IN slug ARRAY,
-- pagination
@@ -1002,6 +1007,11 @@
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
+ END @IF
+
+ @IF isset(:barcode) && :barcode !== ""
+ THEN
+ AND products.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.php
index eaca4e9..87eaae0 100755
--- a/app/controller/checkout/checkout.php
+++ b/app/controller/checkout/checkout.php
@@ -81,7 +81,7 @@ class Checkout extends Base {
$options = $this->global;
$options['status'] = 1;
unset($options['limit']);
- $country = $countryModel->getAll($options);
+ $country = $countryModel->getAll($options);
$this->view->countries = $country['country'] ?? [];
//set default contry and region
@@ -116,28 +116,35 @@ class Checkout extends Base {
return $this->redirect('cart/cart/index');
}
- $order = Order::getInstance();
-
if (isset($this->request->post['login'])) {
return $this->login();
}
- $checkoutInfo = $this->session->get('checkout') ?? [];
+ $order = Order::getInstance();
- $payment = Payment::getInstance();
- $shipping = Shipping::getInstance();
+ $checkoutInfo = $this->session->get('checkout') ?? [];
+ $grandTotal = $cart->getGrandTotal();
+ $hasShipping = $cart->hasShipping();
+ $hasPayment = ($grandTotal > 0);
+ $this->view->hasShipping = $hasShipping;
+ $this->view->hasPayment = $hasPayment;
+ $payment = Payment::getInstance();
$this->view->payment = $payment->getMethods($checkoutInfo);
- $this->view->shipping = $shipping->getMethods($checkoutInfo);
- if (isset($this->request->post['shipping_method'])) {
+ if ($hasShipping) {
+ $shipping = Shipping::getInstance();
+ $this->view->shipping = $shipping->getMethods($checkoutInfo);
+ }
+
+ if ($hasShipping && isset($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'])) {
+ if ($hasPayment && isset($this->request->post['payment_method'])) {
$payment_method = $this->request->post['payment_method'];
$payment->setMethod($payment_method);
$checkoutInfo['payment_method'] = $payment_method;
@@ -195,39 +202,57 @@ class Checkout extends Base {
if ($address) {
$this->request->post['billing_address'] = $address;
- $this->request->post += prefixArrayKeys('billing_', $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';
+ //if card data then validate
+ if (isset($this->request->post['card'])) {
+ $rules[] = 'card';
+ }
- 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 ($hasShipping) {
+ //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['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['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']);
+ }
}
}
//allow only fields that are in the validator list and remove the rest
- $validator = new Validator($rules);
- $checkoutInfo = ($validator->filter($this->request->post) ?? []) + $checkoutInfo;
+ $post = $this->request->post;
+ $validator = new Validator($rules);
+
+ if (! $hasShipping) {
+ $validator->removeRule('shipping_method');
+ }
+
+ if (! $hasPayment) {
+ $validator->removeRule('payment_method');
+ }
+ $checkoutInfo = ($validator->filter($this->request->post) ?? []) + $checkoutInfo;
$this->session->set('checkout', $checkoutInfo);
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['total'] = $grandTotal;
+ $checkoutInfo += prefixArrayKeys('shipping_', $checkoutInfo['shipping_address']);
+ $checkoutInfo += prefixArrayKeys('billing_', $checkoutInfo['billing_address']);
$checkoutInfo += $this->global;
//create user account if password is provided
@@ -244,8 +269,16 @@ class Checkout extends Base {
if ($result = User::add($userInfo)) {
$checkoutInfo['user_id'] = $result['user'] ?? NULL;
+ $userInfo = User::get(['user_id' => $user_id]);
+ //check if user was added before automatic login
+ if ($userInfo) {
+ \Vvveb\session(['user' => $userInfo]);
+ $this->view->global['user_id'] = $userInfo['user_id'];
+ }
} else {
$this->view->errors[] = $error;
+
+ return;
}
}
@@ -267,8 +300,17 @@ class Checkout extends Base {
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']] ?? []);
+ $checkoutInfo['shipping_data'] = '';
+
+ if ($hasShipping) {
+ $checkoutInfo['shipping_data'] = json_encode($this->view->shipping[$checkoutInfo['shipping_method']] ?? []);
+ }
+
+ $checkoutInfo['payment_data'] = '';
+
+ if ($hasPayment) {
+ $checkoutInfo['payment_data'] = json_encode($this->view->payment[$checkoutInfo['payment_method']] ?? []);
+ }
//default order status
$checkoutInfo['order_status_id'] = 1;
@@ -299,8 +341,27 @@ class Checkout extends Base {
$cart->empty();
$site = siteSettings();
+ $shippingData = $checkoutInfo['shipping_data'];
+ $paymentData = $checkoutInfo['payment_data'];
+
+ try {
+ if ($hasShipping) {
+ $shippingOk = $shipping->ship($checkoutInfo);
+ }
+
+ if ($hasPayment) {
+ $paymentOk = $payment->authorize($checkoutInfo);
+ }
+ } catch (\Exception $e) {
+ $this->view->errors[] = $e->getMessage();
+ }
+
list($checkoutInfo, $order_id, $site) = Event::trigger(__CLASS__, 'add:after', $checkoutInfo, $order_id, $site);
+ if (($shippingData != $checkoutInfo['shipping_data']) || ($paymentData != $checkoutInfo['payment_data'])) {
+ $order->edit(['shipping_data' => $checkoutInfo['shipping_data'], 'payment_data' => $checkoutInfo['payment_data']], $order_id);
+ }
+
try {
$error = __('Error sending order confirmation mail!');
diff --git a/app/controller/product/product.php b/app/controller/product/product.php
index b3a5a94..cee9de9 100755
--- a/app/controller/product/product.php
+++ b/app/controller/product/product.php
@@ -52,11 +52,12 @@ class Product extends Base {
}
$language = $this->request->get['language'] ?? $this->global['language'] ?? $this->global['default_language'];
+ $product_id = $this->request->get['product_id'] ?? '';
$slug = $this->request->get['slug'] ?? '';
if ($slug) {
$contentSql = new ProductSQL();
- $options = $this->global + ['slug' => $slug, 'type' => $this->type, 'status' => 1];
+ $options = $this->global + ['product_id' => $product_id, 'slug' => $slug, 'type' => $this->type, 'status' => 1];
$content = $contentSql->getContent($options);
list($content, $language, $slug) = Event :: trigger(__CLASS__,__FUNCTION__, $content, $language, $slug);
@@ -100,6 +101,8 @@ class Product extends Base {
} else {
$this->notFound(true, ['message' => $error, 'title' => $error]);
}
+
+ list($content, $languageContent, $language, $slug) = Event :: trigger(__CLASS__,__FUNCTION__ . ':after', $content, $languageContent, $language, $slug);
} else {
$this->notFound(true, ['message' => $error, 'title' => $error]);
}
diff --git a/app/template/components/checkout/payment.tpl b/app/template/components/checkout/payment.tpl
index 63a322f..284f950 100755
--- a/app/template/components/checkout/payment.tpl
+++ b/app/template/components/checkout/payment.tpl
@@ -15,7 +15,7 @@ $_pagination_limit = isset($payments['limit']) ? $payments['limit'] : 5;
@payment|before = <?php
-$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['payment_id' => 1]] : false;
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['payment_id' => 1, 'name' => 'payment', 'title' => 'Payment name',]] : false;
$payments['payment'] = empty($payments['payment']) ? $_default : $payments['payment'];
if($payments && is_array($payments['payment'])) {
diff --git a/app/template/components/checkout/shipping.tpl b/app/template/components/checkout/shipping.tpl
index 2ce0163..eb27947 100755
--- a/app/template/components/checkout/shipping.tpl
+++ b/app/template/components/checkout/shipping.tpl
@@ -15,7 +15,7 @@ $_pagination_limit = isset($shippings['limit']) ? $shippings['limit'] : 5;
@shipping|before = <?php
-$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['shipping_id' => 1]] : false;
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['shipping_id' => 1, 'name' => 'shipping', 'title' => 'Shipping name',]] : false;
$shippings['shipping'] = empty($shippings['shipping']) ? $_default : $shippings['shipping'];
if($shippings && is_array($shippings['shipping'])) {
diff --git a/system/cart/cart.php b/system/cart/cart.php
index 0049b76..9e433c2 100755
--- a/system/cart/cart.php
+++ b/system/cart/cart.php
@@ -26,6 +26,7 @@ use function \Vvveb\model;
use function \Vvveb\url;
use Vvveb\Sql\Product_Option_ValueSQL;
use Vvveb\Sql\ProductSQL;
+use Vvveb\Sql\Subscription_PlanSQL;
use Vvveb\System\Images;
use Vvveb\System\Session;
@@ -143,6 +144,16 @@ class Cart {
['product_option_value_id' => array_values($productOptions)] + $this->options
)['product_option_value'] ?? [];
}
+
+ // if products have subscriptions get all subscriptions in one query
+ $subscriptionResults = [];
+
+ if ($productSubscriptions) {
+ $subscriptionPlanSql = new Subscription_PlanSQL();
+ $subscriptionResults = $subscriptionPlanSql->getAll(
+ ['subscription_plan_id' => array_values($productSubscriptions)] + $this->options
+ )['subscription_plan'] ?? [];
+ }
}
$products = $results['products'] ?? [];
@@ -202,7 +213,13 @@ class Cart {
}
}
- $url = ['slug' => $product['slug']];
+ //add subscription data
+ if (isset($prod['subscription_plan_id'])) {
+ $prod['subscription'] = $subscriptionResults[$prod['subscription_plan_id']] ?? [];
+ $prod['subscription_name'] = $prod['subscription']['name'];
+ }
+
+ $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']];
$prod['url'] = htmlentities(url('product/product/index', $url));
$prod['remove-url'] = htmlentities(url('cart/cart/remove', $url));
@@ -335,7 +352,7 @@ class Cart {
$weight = 0;
foreach ($this->products as $product) {
- if ($product['requires_shipping']) {
+ if (isset($product['requires_shipping']) && $product['requires_shipping']) {
$weight += $this->weight->convert($product['weight'], $product['weight_type_id'], $this->options['weight_type_id']) * $product['quantity'];
}
}
@@ -375,7 +392,7 @@ class Cart {
public function hasShipping() {
foreach ($this->products as $product) {
- if ($product['shipping']) {
+ if ($product['requires_shipping']) {
return true;
}
}
@@ -385,7 +402,7 @@ class Cart {
public function hasDownload() {
foreach ($this->products as $product) {
- if ($product['download']) {
+ if ($product['digital_asset']) {
return true;
}
}
diff --git a/system/cart/order.php b/system/cart/order.php
index 16c36b7..5eddd5e 100755
--- a/system/cart/order.php
+++ b/system/cart/order.php
@@ -46,6 +46,14 @@ class Order {
return $this->model->getData();
}
+ public function get($order_id) {
+ return $this->model->get(['order_id' => $order_id]);
+ }
+
+ public function edit($data, $order_id) {
+ return $this->model->edit(['order' => $data, 'order_id' => $order_id]);
+ }
+
public function add($data) {
//set defaults
$defaults = ['invoice_format', 'order_id_format', 'order_status_id', 'remote_ip', 'forwarded_for_ip'];
diff --git a/system/payment-method.php b/system/payment-method.php
index ed7d401..de6a994 100755
--- a/system/payment-method.php
+++ b/system/payment-method.php
@@ -34,4 +34,6 @@ abstract class PaymentMethod {
abstract public function getMethod($checkoutInfo = []);
abstract public function setMethod();
+
+ abstract public function authorize();
}
diff --git a/system/payment.php b/system/payment.php
index ec86a19..ae16c49 100755
--- a/system/payment.php
+++ b/system/payment.php
@@ -31,6 +31,8 @@ class Payment {
private $instances = [];
+ private $instance;
+
public static function getInstance($options = []) {
static $inst = null;
@@ -69,6 +71,16 @@ class Payment {
foreach ($this->instances as $instance) {
$instance->init();
}
- $this->instances[$method]->setMethod();
+
+ if (isset($this->instances[$method])) {
+ $this->instance = $this->instances[$method];
+ $this->instance->setMethod();
+ }
+ }
+
+ public function authorize(&$checkoutInfo = []) {
+ if ($this->instance) {
+ $this->instance->authorize($checkoutInfo);
+ }
}
}
diff --git a/system/shipping-method.php b/system/shipping-method.php
index 53a52a9..a652ab1 100755
--- a/system/shipping-method.php
+++ b/system/shipping-method.php
@@ -34,4 +34,6 @@ abstract class ShippingMethod {
abstract public function getMethod($checkoutInfo = []);
abstract public function setMethod();
+
+ abstract public function ship();
}
diff --git a/system/shipping.php b/system/shipping.php
index 9a4623e..12e465f 100755
--- a/system/shipping.php
+++ b/system/shipping.php
@@ -31,6 +31,8 @@ class Shipping {
private $instances = [];
+ private $instance;
+
public static function getInstance($options = []) {
static $inst = null;
@@ -69,6 +71,16 @@ class Shipping {
foreach ($this->instances as $instance) {
$instance->init();
}
- $this->instances[$method]->setMethod();
+
+ if (isset($this->instances[$method])) {
+ $this->instance = $this->instances[$method];
+ $this->instance->setMethod();
+ }
+ }
+
+ public function ship(&$checkoutInfo = []) {
+ if ($this->instance) {
+ $this->instance->ship($checkoutInfo);
+ }
}
}