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
Order id format input for site settings
givanzd167dc68b658
diff --git a/admin/controller/settings/site.php b/admin/controller/settings/site.phpindex ffe1b8d..8748910 100755--- a/admin/controller/settings/site.php+++ b/admin/controller/settings/site.php@@ -63,7 +63,13 @@ class Site extends Base {}private function invoiceFormatPreview($format) {- $data = ['order_id' => 777, 'user_id' => 1000, 'site_id' => 1];+ $data = ['order_id' => 777, 'customer_order_id' => 'OI888', 'user_id' => 1000, 'site_id' => 1];++ return \Vvveb\invoiceFormat($format, $data);+ }++ private function orderIdFormatPreview($format) {+ $data = ['order_id' => 777, 'customer_order_id' => 'OI888', 'user_id' => 1000, 'site_id' => 1];return \Vvveb\invoiceFormat($format, $data);}@@ -78,6 +84,16 @@ class Site extends Base {die($format);}+ function orderIdFormat() {+ $format = $this->request->get['format'] ?? false;++ if ($format) {+ $format = $this->invoiceFormatPreview($format);+ }++ die($format);+ }+function regions() {$country_id = $this->request->get['country_id'] ?? false;$regions = [];@@ -104,7 +120,7 @@ class Site extends Base {$settingsValidator = new Validator(['site-settings']);$view = $this->view;- $site = $this->request->post['site'] ?? [];+ $site = $this->request->post['site'] ?? [];$settings = $this->request->post['settings'] ?? [];if (($errors = $siteValidator->validate($site)) === true &&@@ -234,7 +250,8 @@ class Site extends Base {$view->domain = ($domain['domain'] ?? '') . '.' . ($domain['tld'] ?? '');}- $setting['invoice_format_preview'] = $this->invoiceFormatPreview($setting['invoice_format'] ?? '');+ $setting['invoice_format_preview'] = $this->invoiceFormatPreview($setting['invoice_format'] ?? '');+ $setting['order_id_format_preview'] = $this->invoiceFormatPreview($setting['order_id_format'] ?? '');$view->set($data);$view->site = $site + $setting;diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.phpindex f5a5bee..6f3a8d9 100755--- a/app/controller/checkout/checkout.php+++ b/app/controller/checkout/checkout.php@@ -207,10 +207,11 @@ class Checkout extends Base {if (($errors = $validator->validate($this->request->post)) === true) {//allow only fields that are in the validator list and remove the rest- $checkoutInfo = $validator->filter($this->request->post);- $checkoutInfo['products'] = $cart->getAll();- $checkoutInfo['totals'] = $cart->getTotals();- $checkoutInfo['total'] = $cart->getGrandTotal();+ $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;//create user account if password is provided@@ -255,9 +256,10 @@ class Checkout extends Base {list($checkoutInfo) = Event::trigger(__CLASS__, 'add', $checkoutInfo);- $order_id = $order->add($checkoutInfo);+ $checkoutInfo = $order->add($checkoutInfo);- if ($order_id) {+ if ($checkoutInfo && $checkoutInfo['order_id']) {+ $order_id = $checkoutInfo['order_id'];$this->request->request['order_id'] = $order_id;$checkoutInfo['order_id'] = $order_id;diff --git a/app/template/checkout/confirm.tpl b/app/template/checkout/confirm.tplindex 822dc73..5de2eb5 100755--- a/app/template/checkout/confirm.tpl+++ b/app/template/checkout/confirm.tpl@@ -1,6 +1,6 @@//keep post valuesinput|value = <?php if (isset($_POST['@@__name__@@'])) echo $_POST['@@__name__@@'];?>-[data-v-order-*] = $this->order['@@__data-v-order-*__@@']+[data-v-order-*] = $this->order['@@__data-v-order-(*)__@@']import(common.tpl)diff --git a/install/sql/insert/site/site.sql b/install/sql/insert/site/site.sqlindex cf97578..6353883 100755--- a/install/sql/insert/site/site.sql+++ b/install/sql/insert/site/site.sql@@ -1,2 +1,2 @@INSERT INTO `site` (`site_id`, `key`, `name`, `host`, `theme`, `template`, `settings`) VALUES-(1, 'default','Default','*.*.*', 'landing', '', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"0","post_medium_width":"400","post_medium_height":"0","post_thumb_width":"150","post_thumb_height":"0","product_large_width":"800","product_large_height":"0","product_medium_width":"400","product_medium_height":"0","product_thumb_width":"150","product_thumb_height":"0","date_format":"F j, Y","time_format":"g:i A", "country_id":"222","region_id":"3553","language_id":"1","currency_id":"1","language":"en_US","currency":"USD","invoice_format":"I-{year}-{date_added}-{user_id}-{order_id}-{random-4}"}');\ No newline at end of file+(1, 'default','Default','*.*.*', 'landing', '', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"0","post_medium_width":"400","post_medium_height":"0","post_thumb_width":"150","post_thumb_height":"0","product_large_width":"800","product_large_height":"0","product_medium_width":"400","product_medium_height":"0","product_thumb_width":"150","product_thumb_height":"0","date_format":"F j, Y","time_format":"g:i A", "country_id":"222","region_id":"3553","language_id":"1","currency_id":"1","language":"en_US","currency":"USD","invoice_format":"I-{year2}-{month}-{order_id}-{user_id}-{customer_order_id}","order_id_format":"{year2}-{rand-str-12}"}');\ No newline at end of filediff --git a/install/sql/mysqli/schema/order/order.sql b/install/sql/mysqli/schema/order/order.sqlindex b9013fa..c505c54 100755--- a/install/sql/mysqli/schema/order/order.sql+++ b/install/sql/mysqli/schema/order/order.sql@@ -2,7 +2,8 @@ DROP TABLE IF EXISTS `order`;CREATE TABLE `order` (`order_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,- `invoice_no` varchar(191) NOT NULL DEFAULT '0',+ `invoice_no` varchar(64) NOT NULL DEFAULT '0',+ `customer_order_id` varchar(64) NOT NULL DEFAULT '0',`invoice_prefix` varchar(26) NOT NULL DEFAULT 'I-',`site_id` tinyint(6) NOT NULL DEFAULT '0',`site_name` varchar(64) NOT NULL,@@ -54,5 +55,6 @@ CREATE TABLE `order` (`created_at` datetime NOT NULL DEFAULT current_timestamp,`updated_at` datetime NOT NULL DEFAULT current_timestamp,PRIMARY KEY (`order_id`),- KEY `order_status_id` (`site_id`,`order_status_id`,`created_at`)+ KEY `order_status_id` (`site_id`,`order_status_id`,`created_at`),+ KEY `customer_order_id` (`customer_order_id`,`order_status_id`,`created_at`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;diff --git a/install/sql/pgsql/schema/order/order.sql b/install/sql/pgsql/schema/order/order.sqlindex 518b882..3e5836f 100755--- a/install/sql/pgsql/schema/order/order.sql+++ b/install/sql/pgsql/schema/order/order.sql@@ -7,7 +7,8 @@ CREATE SEQUENCE order_seq;CREATE TABLE "order" ("order_id" int check ("order_id" > 0) NOT NULL DEFAULT NEXTVAL ('order_seq'),- "invoice_no" varchar(191) NOT NULL DEFAULT '0',+ "invoice_no" varchar(64) NOT NULL DEFAULT '0',+ "customer_order_id" varchar(64) NOT NULL DEFAULT '0',"invoice_prefix" varchar(26) NOT NULL DEFAULT 'I-',"site_id" smallint NOT NULL DEFAULT 0,"site_name" varchar(64) NOT NULL,@@ -60,3 +61,6 @@ CREATE TABLE "order" ("updated_at" timestamp(0) NOT NULL DEFAULT now(),PRIMARY KEY ("order_id"));++CREATE INDEX "order_order_status_id" ON order ("site_id","order_status_id","created_at");+CREATE INDEX "order_customer_order_id" ON order ("customer_order_id","order_status_id","created_at");\ No newline at end of filediff --git a/install/sql/sqlite/schema/order/order.sql b/install/sql/sqlite/schema/order/order.sqlindex 3d9e9e8..051fa22 100755--- a/install/sql/sqlite/schema/order/order.sql+++ b/install/sql/sqlite/schema/order/order.sql@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS `order`;CREATE TABLE `order` (`order_id` INTEGER PRIMARY KEY AUTOINCREMENT,`invoice_no` TEXT NOT NULL DEFAULT '0',+`customer_order_id` TEXT NOT NULL DEFAULT '0',`invoice_prefix` TEXT NOT NULL DEFAULT 'I-',`site_id` TINYINT NOT NULL DEFAULT '0',`site_name` TEXT NOT NULL,@@ -57,3 +58,6 @@ CREATE TABLE `order` (`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP-- PRIMARY KEY (`order_id`));++CREATE INDEX `order_order_status_id` ON `order` (`site_id`,`order_status_id`,`created_at`);+CREATE INDEX `order_customer_order_id` ON `order` (`customer_order_id`,`order_status_id`,`created_at`);\ No newline at end of filediff --git a/system/cart/cart.php b/system/cart/cart.phpindex 6fe9e64..f45fb0c 100755--- a/system/cart/cart.php+++ b/system/cart/cart.php@@ -32,11 +32,11 @@ use Vvveb\System\Session;class Cart {protected $cart = [];- private $session;+ protected $session;- private $currency;+ protected $currency;- private $tax;+ protected $tax;protected $productModel = 'product';@@ -109,6 +109,9 @@ class Cart {foreach ($product['option'] as $value) {if (is_numeric($value)) {$productOptions[$value] = $value;+ } else {+ $product_option_value_id = $value['product_option_value_id'];+ $productOptions[$product_option_value_id] = $product_option_value_id;}}}@@ -155,23 +158,32 @@ class Cart {$prod['price'] = $product['price'];//add option value data and adjust price if necessary- if ($prod['option']) {- foreach ($prod['option'] as $option_id => $product_option_value_id) {- $value = $optionResults[$product_option_value_id];- $prod['option_value'][$product_option_value_id] = $value;+ if (isset($prod['option'])) {+ foreach ($prod['option'] as $option_id => $option) {+ if (is_numeric($option)) {+ $product_option_value_id = $option;+ } else {+ $product_option_value_id = $option['product_option_value_id'];+ }++ $value = $optionResults[$product_option_value_id];if ($value['price']) {if ($value['price_operator'] == '-') {- $prod['price'] -= $value['price'];- } else {- $prod['price'] += $value['price'];+ $value['price'] = -$value['price'];}++ $prod['price'] += $value['price'];+ $value['price_formatted'] = $this->currency->format($value['price']);}++ $prod['option_value'][$product_option_value_id] = $value;}}- $prod['url'] = htmlentities(url('product/product/index', $product));- $prod['remove-url'] = htmlentities(url('cart/cart/remove', $product));+ $url = ['slug' => $product['slug']];+ $prod['url'] = htmlentities(url('product/product/index', $url));+ $prod['remove-url'] = htmlentities(url('cart/cart/remove', $url));$prod['total'] = (int)$prod['price'] * $prod['quantity'];$prod['total_formatted'] = $this->currency->format($prod['total']);@@ -190,8 +202,8 @@ class Cart {//$prod['subscription_plan_id'] = $products[$productId]['subscription_plan_id'];}- $this->total += $prod['total'];- $this->total_tax += $prod['total_tax'];+ $this->total += $prod['total'];+ $this->total_tax += $prod['total_tax'];$this->total_items += $prod['quantity'];$prod = array_merge($prod, $product);@@ -345,6 +357,7 @@ class Cart {function getTotals() {//include taxes$this->addTaxTotal();+ $this->addCouponTotal();return $this->totals;}diff --git a/system/cart/coupon-trait.php b/system/cart/coupon-trait.phpindex b1b00e3..1a293d3 100644--- a/system/cart/coupon-trait.php+++ b/system/cart/coupon-trait.php@@ -44,6 +44,8 @@ trait CouponTrait {}public function removeCoupon($code) {+ $coupon = $this->coupons[$code];+ $this->removeTotal('coupon.' . $coupon['coupon_id']);unset($this->coupons[$code]);return true;@@ -57,7 +59,13 @@ trait CouponTrait {$coupons = $this->getCoupons();foreach ($coupons as $coupon) {- $this->addTotal('coupon.' . $coupon['coupon_rate_id'], $coupon['name'], $coupon['value']);+ if ($coupon['type'] == 'P') {+ $discount = (($coupon['discount'] * $this->getSubTotal()) / 100);+ } else {+ $discount = $coupon['discount'];+ }++ $this->addTotal('coupon.' . $coupon['coupon_id'], $coupon['name'], $discount);}}}diff --git a/system/cart/order.php b/system/cart/order.phpindex adac2fc..21b7413 100755--- a/system/cart/order.php+++ b/system/cart/order.php@@ -48,7 +48,7 @@ class Order {public function add($data) {//set defaults- $defaults = ['invoice_format', 'order_status_id', 'remote_ip', 'forwarded_for_ip'];+ $defaults = ['invoice_format', 'order_id_format', 'order_status_id', 'remote_ip', 'forwarded_for_ip'];$site = siteSettings();$site['remote_ip'] = $_SERVER['REMOTE_ADDR'] ?? false;@@ -63,19 +63,32 @@ class Order {}}- $data['invoice_no'] = \Vvveb\invoiceFormat($data['invoice_format'], $data);-+ $data['invoice_no'] = \Vvveb\invoiceFormat($data['invoice_format'], $data);+ $data['customer_order_id'] = \Vvveb\invoiceFormat($data['order_id_format'], $data);//todo: check if email is already registerd for new accounts++ //add products one by one to set product options for each+ $products = $data['products'];+ $data['products'] = [];+$result = $this->model->add(['order' => $data]);$order_id = $result['order'] ?? false;if ($order_id) {+ //add products+ foreach ($products as $key => $product) {+ $product_options = $product['option_value'] ?? [];+ $product_options['product_id'] = $product['product_id'];+ $this->model->addProduct(['product' => $product, 'product_options' => $product['option_value'], 'order_id' => $order_id]);+ }//update invoice to set {order_id} variable- $data['order_id'] = $order_id;- $data['invoice_no'] = \Vvveb\invoiceFormat($data['invoice_format'], $data);- $result = $this->model->edit(['order' => ['invoice_no' => $data['invoice_no']], 'order_id' => $order_id]);+ $data['order_id'] = $order_id;+ $data['user_id'] = $data['user_id'] ?? 0;+ $data['customer_order_id'] = \Vvveb\invoiceFormat($data['order_id_format'], $data);+ $data['invoice_no'] = \Vvveb\invoiceFormat($data['invoice_format'], $data);+ $result = $this->model->edit(['order' => ['invoice_no' => $data['invoice_no'], 'customer_order_id' => $data['customer_order_id']], 'order_id' => $order_id]);}- return $order_id;+ return $data;}}