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
Reviews star count progress bar. Coupon list on cart and checkout page. Revisions diff view. Product options display on cart and checkout page. Plugins status filter.
givanz4e9863eb5640
diff --git a/.gitattributes b/.gitattributesindex 886562a..1734998 100644--- a/.gitattributes+++ b/.gitattributes@@ -1,3 +1,4 @@-public/themes/** linguist-vendored-public/admin/** linguist-vendored+public/themes/* linguist-vendored+public/admin/* linguist-vendored+public/install/* linguist-vendored*.sql linguist-detectable=truediff --git a/admin/admin-bar.php b/admin/admin-bar.phpindex d904e55..8b158bc 100755--- a/admin/admin-bar.php+++ b/admin/admin-bar.php@@ -19,8 +19,8 @@* along with this program. If not, see <https://www.gnu.org/licenses/>.**/-if (! defined('DIR_ROOT')) {- exit();+if (! defined('V_VERSION')) {+ die('Invalid request!');}//if (function_exists('printAdminBarMenu')) return;@@ -31,8 +31,8 @@ list($menu) = Vvveb\System\Event::trigger('Vvveb\Controller\Base','init-menu', $list($menu) = Vvveb\System\Event::trigger('admin-bar', 'menu', $menu);list($top) = Vvveb\System\Event::trigger('admin-bar', 'top', []);-$template = Vvveb\getCurrentTemplate();-$url = Vvveb\getCurrentUrl();+$template = Vvveb\getCurrentTemplate();+$url = Vvveb\getCurrentUrl();$admin_path = Vvveb\adminPath();$design_url = $admin_path . Vvveb\url(['module' => 'editor/editor', 'template' => $template, 'url' => $url], false, false);$urlData = Vvveb\System\Routes::getUrlData($url);@@ -143,9 +143,9 @@ if (! function_exists('printAdminBarMenu')) {<?php echo __('Full page cache'); ?></a></li>- <div class="dropdown-divider">+ <li class="dropdown-divider"><hr />- </div>+ </li><li><a href="<?php echo $admin_path; ?>?module=tools/cache&action=delete" target="_blank"><i class="la la-circle-notch"></i>diff --git a/admin/component/languages.php b/admin/component/languages.phpindex a1fe2e6..bbd4efe 100755--- a/admin/component/languages.php+++ b/admin/component/languages.php@@ -23,8 +23,6 @@namespace Vvveb\Component;use function Vvveb\availableLanguages;-use Vvveb\Sql\LanguageSQL;-use Vvveb\System\Cache;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Session;@@ -46,7 +44,7 @@ class Languages extends ComponentBase {}function results() {- $results = [];+ $results = [];$results['language'] = availableLanguages();if ($results['language']) {diff --git a/admin/component/notifications.php b/admin/component/notifications.phpindex 5a9a77d..d4d9a32 100644--- a/admin/component/notifications.php+++ b/admin/component/notifications.php@@ -27,8 +27,8 @@ use function Vvveb\orderStatusBadgeClass;use Vvveb\Sql\StatSQL;use Vvveb\System\Cache;use Vvveb\System\Component\ComponentBase;-use Vvveb\System\Event;use Vvveb\System\Core\View;+use Vvveb\System\Event;use Vvveb\System\Update;class Notifications extends ComponentBase {@@ -36,24 +36,28 @@ class Notifications extends ComponentBase {];public $options = [];+private $stats;- private $count = 0;++ private $count = 0;+private $notifications = [];+private $menu = [];protected function orders() {$orderCount = $this->stats->getOrdersCount($this->options)['orders'] ?? [];-+$orderStatsusNew = 1; //get from site config$newOrders = ($orderCount[$orderStatsusNew]['count'] ?? 0);if ($newOrders > 0) {$this->count += $newOrders;- $this->menu['sales'] = [];+ $this->menu['sales'] = [];$this->menu['sales']['badge'] = $newOrders;$this->menu['sales']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';}-+//set order name as array keysforeach ($orderCount as $type => $orders) {if (isset($orders['name'])) {@@ -69,7 +73,7 @@ class Notifications extends ComponentBase {protected function users() {}-+protected function products() {$productCount = $this->stats->getProductStockCount($this->options)['products'] ?? [];@@ -80,9 +84,8 @@ class Notifications extends ComponentBase {$this->notifications['products'] = $productCount + $this->notifications['products'];}-- protected function comments() {+ protected function comments() {$commentCount = $this->stats->getCommentsCount($this->options)['comments'] ?? [];$comment_status = [0 => 'pending',@@ -96,11 +99,11 @@ class Notifications extends ComponentBase {if ($newComments > 0) {$this->count += $newComments;- $this->menu['post'] = [];+ $this->menu['post'] = [];$this->menu['post']['badge'] = $newComments;- $this->menu['post']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';-- $this->menu['post']['items']['comments'] = [];+ $this->menu['post']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';++ $this->menu['post']['items']['comments'] = [];$this->menu['post']['items']['comments']['badge'] = $newComments;$this->menu['post']['items']['comments']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';}@@ -114,9 +117,9 @@ class Notifications extends ComponentBase {$this->notifications['comments'] = $commentCount + $this->notifications['comments'];}-+protected function reviews() {- $reviewCount = $this->stats->getReviewsCount($this->options)['reviews'] ?? [];+ $reviewCount = $this->stats->getReviewsCount($this->options)['reviews'] ?? [];$comment_status = [0 => 'pending',1 => 'approved',@@ -131,13 +134,13 @@ class Notifications extends ComponentBase {$this->count += $newReviews;//$this->menu['product'] = [];$this->menu['product']['badge'] = $newReviews;- $this->menu['product']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';-+ $this->menu['product']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';+//$this->menu['product']['items']['reviews'] = [];$this->menu['product']['items']['reviews']['badge'] = $newReviews;$this->menu['product']['items']['reviews']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';}-+foreach ($reviewCount as $type => $reviews) {$reviews['icon'] = ' la la-comments';$reviews['badge'] = commentStatusBadgeClass($reviews['status']);@@ -146,12 +149,11 @@ class Notifications extends ComponentBase {}$this->notifications['reviews'] = $reviewCount + $this->notifications['reviews'];-}protected function questions() {$questionCount = $this->stats->getQuestionsCount($this->options)['questions'] ?? [];- $comment_status = [+ $comment_status = [0 => 'pending',1 => 'approved',2 => 'spam',@@ -165,13 +167,13 @@ class Notifications extends ComponentBase {$this->count += $newQuestions;//$this->menu['product'] = [];$this->menu['product']['badge'] = ($this->menu['product']['badge'] ?? 0) + $newQuestions;- $this->menu['product']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';-+ $this->menu['product']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';+//$this->menu['product']['items']['questions'] = [];$this->menu['product']['items']['questions']['badge'] = $newQuestions;$this->menu['product']['items']['questions']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';}-+foreach ($questionCount as $type => $questions) {$questions['icon'] = 'la la-question-circle';$questions['badge'] = commentStatusBadgeClass($questions['status']);@@ -181,16 +183,16 @@ class Notifications extends ComponentBase {$this->notifications['questions'] = $questionCount + $this->notifications['questions'];}-+function request(&$results, $index) {//add menu notification countif ($results['menu'] && $index == 0) {- $view = View::getInstance();+ $view = View::getInstance();$view->menu = array_merge_recursive($view->menu, $results['menu']);}}-+function results() {// return [];$cache = Cache::getInstance();@@ -237,13 +239,12 @@ class Notifications extends ComponentBase {$this->comments();$this->reviews();$this->questions();-$update = new Update();$updates = $update->checkUpdates('core');$this->notifications['updates']['core'] = $updates;- $this->count += max($updates['hasUpdate'], 0);+ $this->count += max($updates['hasUpdate'], 0);$results = ['notifications' => $this->notifications,@@ -252,7 +253,7 @@ class Notifications extends ComponentBase {];list($results) = Event::trigger(__CLASS__, __FUNCTION__, $results);-+return $results;}}diff --git a/admin/component/products.php b/admin/component/products.phpindex 2d8af14..b47aa97 100755--- a/admin/component/products.php+++ b/admin/component/products.php@@ -28,16 +28,16 @@ use Vvveb\System\Images;class Products extends ComponentBase {public static $defaultOptions = [- 'start' => 0,- 'limit' => 4,- 'language_id' => 1,- 'site_id' => 1,- 'manufacturer_id' => NULL,- 'vendor_id' => NULL,- 'related' => NULL,- 'order' => ['url', 'price asc'],- //'taxonomy_item_id' => null,- 'include_image_gallery' => true,+ 'start' => 0,+ 'limit' => 4,+ 'language_id' => 1,+ 'site_id' => 1,+ 'manufacturer_id'=> NULL,+ 'vendor_id' => NULL,+ 'related' => NULL,+ 'order' => ['url', 'price asc'],+ //'taxonomy_item_id'=> null,+ 'product_image' => true,];public $options = [];diff --git a/admin/controller/admin/roles.php b/admin/controller/admin/roles.phpindex 98abb66..bd7f9d0 100755--- a/admin/controller/admin/roles.php+++ b/admin/controller/admin/roles.php@@ -23,8 +23,6 @@namespace Vvveb\Controller\Admin;use Vvveb\Controller\Base;-use Vvveb\System\Images;-use Vvveb\System\User\Role;class Roles extends Base {private function save() {diff --git a/admin/controller/base.php b/admin/controller/base.phpindex 091d3fb..b816e7d 100755--- a/admin/controller/base.php+++ b/admin/controller/base.php@@ -29,7 +29,6 @@ use function Vvveb\availableLanguages;use function Vvveb\clearLanguageCache;use function Vvveb\filter;use function Vvveb\setLanguage;-use Vvveb\Sql\StatSQL;use Vvveb\Sql\taxonomySQL;use Vvveb\System\Core\FrontController;use Vvveb\System\Core\Request;diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.phpindex 8514187..11880fb 100644--- a/admin/controller/content/edit.php+++ b/admin/controller/content/edit.php@@ -114,9 +114,11 @@ class Edit extends Base {$this->type = $post['type'] ?? $this->type;if ($this->object == 'product') {- $route = "product/{$this->type}/index";+ $route = "product/{$this->type}/index";+ $controller = 'product';} else {- $route = "content/{$this->type}/index";+ $route = "content/{$this->type}/index";+ $controller = 'content';}if ($this->revisions) {@@ -185,6 +187,7 @@ class Edit extends Base {$view->type = __($this->type);$view->type_name = $type_name;$view->posts_list_url = \Vvveb\url(['module' => 'content/posts', 'type' => $this->type]);+ $view->revisions_url = \Vvveb\url(['module' => "$controller/revisions", 'type' => $this->type, $this->object . '_id' => $post_id]);}private function addCategory($taxonomy_id, $name) {@@ -304,7 +307,7 @@ class Edit extends Base {$post_id = $id;$new = true;- $message = ucfirst($this->type) . ' ' . __('saved') . '!';+ $message = ucfirst($this->type) . ' ' . __('saved') . '!';$view->success['get'] = $message;}}diff --git a/admin/controller/content/revisions.php b/admin/controller/content/revisions.phpindex 3c27813..aaeb93c 100644--- a/admin/controller/content/revisions.php+++ b/admin/controller/content/revisions.php@@ -24,6 +24,7 @@ namespace Vvveb\Controller\Content;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\System\Images;use function Vvveb\humanReadable;use function Vvveb\model;@@ -31,7 +32,7 @@ class Revisions extends Base {protected $type = 'post';//check for other modules permission like revision and editor to enable links like save/delete etc- //protected $additionalPermissionCheck = ['content/revision/save'];+ protected $additionalPermissionCheck = ['content/revisions/save'];function merge() {}@@ -40,76 +41,83 @@ class Revisions extends Base {if (isset($this->request->get['type'])) {$this->type = $this->request->get['type'];}- $this->post_id = $this->request->get[$this->type . '_id'] ?? false;- $this->language_id = $this->request->get['language_id'] ?? false;- $this->created_at = $this->request->get['created_at'] ?? false;+$this->revisions = model($this->type . '_content_revision');+ $this->post = model($this->type);++ $this->options = ['type' => $this->type];++ foreach ([$this->type . '_id', 'language_id', 'created_at'] as $param) {+ if (isset($this->request->get[$param])) {+ $this->options[$param] = $this->request->get[$param];+ }+ }return parent::init();}function delete() {- $view = $this->view;- $this->revisions = model($this->type . '_content_revision');-- $options = [- $this->type . '_id' => $this->post_id,- 'language_id' => $this->language_id,- 'created_at' => $this->created_at,- ] + $this->global;--- $results = $this->revisions->delete($options);+ $results = $this->revisions->delete($this->options + $this->global);header('Content-type: application/json; charset=utf-8');- echo json_encode($options);die();}+ function save() {+ $content = $this->request->post['content'] ?? false;+ if ($content) {+ $result = $this->post->editContent(+ [$this->type . '_content' => ['content' => $content]] ++ $this->options ++ $this->global+ );++ if ($result) {+ $this->view->success[] = ucfirst($this->type) . ' ' . __('saved') . '!';;+ } else {+ $view->errors = [$post->error];+ }+ }++ return $this->index();+ }+function revision() {$view = $this->view;-- $options = [- $this->type . '_id' => $this->post_id,- 'language_id' => $this->language_id,- 'created_at' => $this->created_at,- ] + $this->global;-- $results = $this->revisions->get($options);-- header('Content-type: application/json; charset=utf-8');- echo json_encode($results);+ $results = $this->revisions->get($this->options);+ if ($results && isset($results['content'])) {+ echo $results['content'];+ }die();}function index() {- return;- $this->post_id = $this->request->get[$this->type . '_id'] ?? false;- $this->language_id = $this->request->get['language_id'] ?? false;- $this->created_at = $this->request->get['created_at'] ?? false;-- $view = $this->view;- $revisions = model($this->type . '_content_revision');-- $options = [- 'type' => $this->type,- 'comment_count' => true,- ] + $this->global + $this->filter;+ $view = $this->view;+ $revisions = model($this->type . '_content_revision');+ $this->options += $this->global;- $results = $this->revisions->getAll($options);-- foreach ($results['revisions'] as $id => &$revision) {++ $revisions = $this->revisions->getAll($this->options);// all post/product revisions+ $revision = $this->revisions->get($this->options);// latest or selected revision+ $post = $this->post->get($this->options);// post/product content++ if (isset($post['image'])) {+ $post['image'] = $post['image'] = Images::image($post['image'], $this->type, 'thumb');}+ $results = [+ 'revisions' => $revisions['revision'] ?? [],+ 'revision' => $revision ?? [],+ 'post' => $post ?? [],+ ];+$view->set($results);- $view->status = ['publish' => 'publish', 'pending' => 'pending'];- $view->archives = $archives;- $view->filter = $this->filter;- $view->limit = $options['limit'];++ $view->limit = $this->options['limit'];$view->type = $this->type;- $view->addUrl = \Vvveb\url(['module' => 'content/revision', 'type' => $this->type]);+ $view->revisionUrl = \Vvveb\url(['module' => 'content/revisions', 'action' => 'revision', 'type' => $this->type]);$view->type_name = humanReadable(__($this->type));$view->type_name_plural = humanReadable(__($view->type . 's'));}diff --git a/admin/controller/editor/autocomplete.php b/admin/controller/editor/autocomplete.phpindex 6cface0..364c9b6 100755--- a/admin/controller/editor/autocomplete.php+++ b/admin/controller/editor/autocomplete.php@@ -24,7 +24,6 @@ namespace Vvveb\Controller\Editor;use Vvveb\Controller\Base;use Vvveb\Sql\categorySQL;-use Vvveb\System\Core\View;class Autocomplete extends Base {private $themeConfig = [];diff --git a/admin/controller/order/return-order.php b/admin/controller/order/return-order.phpindex d05e5dd..6207be2 100644--- a/admin/controller/order/return-order.php+++ b/admin/controller/order/return-order.php@@ -22,10 +22,9 @@namespace Vvveb\Controller\Order;-use function Vvveb\__;use Vvveb\Controller\Crud;-use Vvveb\Sql\Return_ResolutionSQL;use Vvveb\Sql\Return_ReasonSQL;+use Vvveb\Sql\Return_ResolutionSQL;use Vvveb\Sql\Return_StatusSQL;//Return is a reserved keyword using ReturnOrder and return-order instead@@ -40,15 +39,15 @@ class ReturnOrder extends Crud {parent :: index();$resolution = new Return_ResolutionSQL();- $reason = new Return_ReasonSQL();- $status = new Return_StatusSQL();-+ $reason = new Return_ReasonSQL();+ $status = new Return_StatusSQL();+$resolutions = $resolution->getAll($this->global)['return_resolution'] ?? [];- $reasons = $reason->getAll($this->global)['return_reason'] ?? [];- $statuses = $status->getAll($this->global)['return_status'] ?? [];+ $reasons = $reason->getAll($this->global)['return_reason'] ?? [];+ $statuses = $status->getAll($this->global)['return_status'] ?? [];$this->view->return_resolution_id = $resolutions;- $this->view->return_reason_id = $reasons;- $this->view->return_status_id = $statuses;+ $this->view->return_reason_id = $reasons;+ $this->view->return_status_id = $statuses;}}diff --git a/admin/controller/order/subscription.php b/admin/controller/order/subscription.phpindex 75e6706..1b2c919 100644--- a/admin/controller/order/subscription.php+++ b/admin/controller/order/subscription.php@@ -35,8 +35,8 @@ class Subscription extends Crud {function index() {parent :: index();- $this->view->period = ['day' => __('Day'), 'week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')];- $this->view->trial_period = $this->view->period;+ $this->view->period = ['day' => __('Day'), 'week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')];+ $this->view->trial_period = $this->view->period;$this->view->trial_status = $this->view->status;}}diff --git a/admin/controller/plugin/market.php b/admin/controller/plugin/market.phpindex c4f5843..d72880c 100755--- a/admin/controller/plugin/market.php+++ b/admin/controller/plugin/market.php@@ -98,6 +98,7 @@ class Market extends Base {$request = $validator->filter($this->request->get);$plugins = [];+ $request['limit'] = $this->view->limit = 8;try {$plugins = Plugins :: getMarketList($request);$installed = Plugins :: getList($this->global['site_id']);diff --git a/admin/controller/product/attribute-group.php b/admin/controller/product/attribute-group.phpindex 34f8273..bd247c0 100644--- a/admin/controller/product/attribute-group.php+++ b/admin/controller/product/attribute-group.php@@ -52,7 +52,6 @@ class AttributeGroup extends Crud {}}-if ($attribute_group_id) {$attributeGroup = new Attribute_GroupSQL();$attributeSql = new AttributeSQL();diff --git a/admin/controller/product/revisions.php b/admin/controller/product/revisions.phpnew file mode 100644index 0000000..b793ae4--- /dev/null+++ b/admin/controller/product/revisions.php@@ -0,0 +1,33 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Product;++use function Vvveb\__;+use Vvveb\Controller\Base;+use Vvveb\Controller\Content\Revisions as RevisionsBase;++class Revisions extends RevisionsBase {+ protected $type = 'product';++ protected $additionalPermissionCheck = ['product/revisions/save'];+}diff --git a/admin/controller/settings/site.php b/admin/controller/settings/site.phpindex 94f1b61..e6ff258 100755--- a/admin/controller/settings/site.php+++ b/admin/controller/settings/site.php@@ -164,7 +164,7 @@ class Site extends Base {}}- $data = $siteSql->getData(($view->setting ?? []) + $this->global);+ $data = $siteSql->getData(($view->setting ?? []) + $this->global);$data['complete_status_id'] = $data['processing_status_id'] = $data['order_status_id'];$data['timezone'] = [];diff --git a/admin/controller/settings/subscription-plan.php b/admin/controller/settings/subscription-plan.phpindex 7684489..95748b1 100644--- a/admin/controller/settings/subscription-plan.php+++ b/admin/controller/settings/subscription-plan.php@@ -35,8 +35,8 @@ class SubscriptionPlan extends Crud {function index() {parent :: index();- $this->view->period = ['day' => __('Day'), 'week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')];- $this->view->trial_period = $this->view->period;+ $this->view->period = ['day' => __('Day'), 'week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')];+ $this->view->trial_period = $this->view->period;$this->view->trial_status = $this->view->status;}}diff --git a/admin/controller/theme/market.php b/admin/controller/theme/market.phpindex f8b8248..20e0283 100755--- a/admin/controller/theme/market.php+++ b/admin/controller/theme/market.php@@ -91,8 +91,9 @@ class Market extends Base {$request = $validator->filter($this->request->get);$themes = [];+ $request['limit'] = $this->view->limit = 8;try {- $themes = Themes :: getMarketList($request);+ $themes = Themes :: getMarketList($request);$installed = Themes :: getList($this->global['site_id']);foreach ($themes['themes'] as &$theme) {diff --git a/admin/controller/user/reset.php b/admin/controller/user/reset.phpindex 0ede876..8bf6dd3 100755--- a/admin/controller/user/reset.php+++ b/admin/controller/user/reset.php@@ -43,14 +43,14 @@ class Reset {if ($password && $admin) {if (Admin::update(['token' => '', 'password' => $password], ['username' => $user, 'token' => $token])) {- $success = __('Password was reset!');- $this->view->success[] = $success;- $this->session->set('success', $success);+ $success = __('Password was reset!');+ $this->view->success['login'] = $success;+ $this->session->set('success', ['login' => $success]);header('Location: ' . url(['module' => 'user/login', 'success' => $success]));} else {- $errors = __('Update failed!');- $this->view->errors[] = $errors;- $this->session->set('errors', $errors);+ $errors = __('Update failed!');+ $this->view->errors['login'] = $errors;+ $this->session->set('errors', ['login' => $errors]);}}}@@ -99,10 +99,10 @@ class Reset {$this->session->set('success', $success);header('Location: ' . url(['module' => 'user/login', 'success' => $success]));} else {- $this->view->errors[] = __('Error sending reset email!');+ $this->view->errors['login'] = __('Error sending reset email!');}} else {- $this->view->errors[] = __('Email not found!');+ $this->view->errors['login'] = __('Email not found!');}}}diff --git a/admin/sql/mysqli/comment.sql b/admin/sql/mysqli/comment.sqlindex 7507988..8fa5ad0 100755--- a/admin/sql/mysqli/comment.sql+++ b/admin/sql/mysqli/comment.sql@@ -23,7 +23,7 @@)BEGIN- SELECT comment.*, user.*, comment_id as array_key+ SELECT user.*, comment.*, comment_id as array_keyFROM comment AS commentLEFT JOIN user ON (comment.user_id = comment.user_id)diff --git a/admin/sql/mysqli/coupon.sql b/admin/sql/mysqli/coupon.sqlindex 5f5bcce..a68831d 100755--- a/admin/sql/mysqli/coupon.sql+++ b/admin/sql/mysqli/coupon.sql@@ -29,12 +29,38 @@PROCEDURE get(IN coupon_id INT,+ IN code CHAR,+ IN free_shipping INT,+ IN status INT,OUT fetch_row,)BEGIN-- couponSELECT *- FROM coupon as _ WHERE coupon_id = :coupon_id;+ FROM coupon as _+ WHERE 1 = 1++ @IF !empty(:code)+ THEN+ AND code = :code+ END @IF++ @IF !empty(:free_shipping)+ THEN+ AND free_shipping = :free_shipping+ END @IF++ @IF !empty(:coupon_id)+ THEN+ AND coupon_id = :coupon_id+ END @IF++ @IF !empty(:status)+ THEN+ AND status = :status+ END @IF+ ;+END-- add coupondiff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sqlindex d3d2c6e..3345b35 100755--- a/admin/sql/mysqli/post.sql+++ b/admin/sql/mysqli/post.sql@@ -205,13 +205,13 @@-- month@IF isset(:month) && !empty(:month)THEN- AND MONTH(created_at) = :month+ AND MONTH(posts.created_at) = :monthEND @IF-- year@IF isset(:year) && !empty(:year)THEN- AND YEAR(created_at) = :year+ AND YEAR(posts.created_at) = :yearEND @IF-- order by@@ -420,6 +420,25 @@END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN post_content ARRAY,+ IN post_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN++ :post_content = @FILTER(:post_content, post_content);++ UPDATE post_content++ SET @LIST(:post_content)++ WHERE post_id = :post_id AND language_id = :language_id+ END+-- Delete post@@ -491,16 +510,16 @@BEGINSELECT- YEAR(created_at) AS year+ YEAR(archives.created_at) AS year@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,MONTH(created_at) AS month+ ,MONTH(archives.created_at) AS monthEND @IF@IF isset(:interval) AND :interval == "day"THEN- ,DAYOFMONTH(created_at) AS day+ ,DAYOFMONTH(archives.created_at) AS dayEND @IF,count(archives.post_id) as count@@ -522,29 +541,29 @@GROUP BY- YEAR(created_at)+ YEAR(archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,MONTH(created_at)+ ,MONTH(archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,DAYOFMONTH(created_at)+ ,DAYOFMONTH(archives.created_at)END @IFORDER BY- YEAR(created_at)+ YEAR(archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,MONTH(created_at)+ ,MONTH(archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,DAYOFMONTH(created_at)+ ,DAYOFMONTH(archives.created_at)END @IFdiff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sqlindex 87e6a3b..1ab9d8b 100755--- a/admin/sql/mysqli/product.sql+++ b/admin/sql/mysqli/product.sql@@ -440,6 +440,26 @@END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN product_content ARRAY,+ IN product_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN++ :product_content = @FILTER(:product_content, product_content);++ UPDATE product_content++ SET @LIST(:product_content)++ WHERE product_id = :product_id AND language_id = :language_id+ END++-- Add new productCREATE PROCEDURE add(@@ -728,7 +748,7 @@)BEGIN- SELECT pd.*,products.*+ SELECT pd.*,products.*, products.product_id as array_key@IF !empty(:manufacturer)THENdiff --git a/admin/sql/mysqli/product_option_value.sql b/admin/sql/mysqli/product_option_value.sqlindex 9b1a3f2..cbd46bb 100644--- a/admin/sql/mysqli/product_option_value.sql+++ b/admin/sql/mysqli/product_option_value.sql@@ -6,6 +6,7 @@IN language_id INT,IN option_id INT,IN product_id INT,+ IN product_option_value_id ARRAY,IN start INT,IN limit INT,OUT fetch_all,@@ -13,10 +14,13 @@)BEGIN-- product_option_value- SELECT product_option_value.*, option_value.image, ovc.name, product_option_value.product_option_value_id as array_key+ SELECT product_option_value.*,+ option_value.image, ovc.name, oc.name as `option`,+ product_option_value.product_option_value_id as array_keyFROM product_option_value AS product_option_valueINNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_idINNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id+ INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_idWHERE 1 = 1@@ -24,6 +28,12 @@@IF isset(:option_id)THENAND product_option_value.option_id = :option_id+ END @IF++ -- option_id+ @IF isset(:product_option_value_id)+ THEN+ AND product_option_value.product_option_value_id IN (:product_option_value_id)END @IF-- product_iddiff --git a/admin/sql/mysqli/product_question.sql b/admin/sql/mysqli/product_question.sqlindex fe9843e..46d48c2 100755--- a/admin/sql/mysqli/product_question.sql+++ b/admin/sql/mysqli/product_question.sql@@ -18,9 +18,9 @@)BEGIN- SELECT *+ SELECT user.*,product_question.*,user.user_id as user_idFROM product_question AS product_question- INNER JOIN user on user.user_id = product_question.user_id+ LEFT JOIN user on user.user_id = product_question.user_idWHERE 1 = 1@@ -30,12 +30,12 @@AND product_question.product_id = :product_idEND @IF- -- product slug+ -- product slug@IF isset(:slug)- THEN- AND product_question.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)- END @IF-+ THEN+ AND product_question.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF+-- user@IF isset(:user_id)THENdiff --git a/admin/sql/mysqli/product_review.sql b/admin/sql/mysqli/product_review.sqlindex 43a7ff4..4abda45 100755--- a/admin/sql/mysqli/product_review.sql+++ b/admin/sql/mysqli/product_review.sql@@ -6,6 +6,7 @@IN language_id INT,IN site_id INT,IN product_id INT,+ IN slug CHAR,IN user_id INT,IN status INT,@@ -19,7 +20,7 @@)BEGIN- SELECT product_review.*,user.*,user.user_id as user_id,+ SELECT user.*,product_review.*,user.user_id as user_id,(SELECT CONCAT('[', GROUP_CONCAT('{"id":"', prm.product_review_media_id, '","image":"' , prm.image, '"}'), ']')FROM product_review_media as prmWHERE prm.product_review_id = product_review.product_review_id) as images@@ -29,13 +30,13 @@WHERE 1 = 1- -- post+ -- product@IF isset(:product_id)THENAND product_review.product_id = :product_idEND @IF- -- post slug+ -- product slug@IF isset(:slug)THENAND product_review.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)@@ -77,6 +78,84 @@INNER JOIN user on user.user_id = product_review.user_idWHERE product_review_id = :product_review_id LIMIT 1;+ END++ -- Get product reviews stats++ CREATE PROCEDURE getProductStats(+ -- variables+ IN language_id INT,+ IN site_id INT,+ IN product_id INT,+ IN slug CHAR,+ IN user_id INT,+ IN status INT,+ -- return+ OUT fetch_all, -- orders+ OUT fetch_one -- count+ )+ BEGIN++ -- rating count+ SELECT COUNT(*) AS count, summary.rating, summary.rating as array_key+ FROM product_review AS summary+ WHERE 1 = 1++ -- product+ @IF isset(:product_id)+ THEN+ AND summary.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND summary.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND summary.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND summary.status = :status+ END @IF++ GROUP BY summary.rating;++ SELECT AVG(rating.rating) as average+ FROM product_review AS rating+ WHERE 1 = 1+ -- product+ @IF isset(:product_id)+ THEN+ AND rating.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND rating.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND rating.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND rating.status = :status+ END @IF++ LIMIT 1;+END-- Add new product reviewdiff --git a/admin/sql/mysqli/product_subscription.sql b/admin/sql/mysqli/product_subscription.sqlindex 89d152b..047b60b 100644--- a/admin/sql/mysqli/product_subscription.sql+++ b/admin/sql/mysqli/product_subscription.sql@@ -5,6 +5,7 @@PROCEDURE getAll(IN language_id INT,IN product_id INT,+ IN subscription_plan_id INT,IN start INT,IN limit INT,OUT fetch_all,@@ -35,6 +36,12 @@@IF isset(:product_id)THENAND product_subscription.product_id = :product_id+ END @IF++ -- subscription_plan_id+ @IF isset(:subscription_plan_id)+ THEN+ AND product_subscription.subscription_plan_id = :subscription_plan_idEND @IF-- limit@@ -60,7 +67,9 @@BEGIN-- product_subscriptionSELECT *- FROM product_subscription as _ WHERE product_subscription_id = :product_subscription_id;+ FROM product_subscription as _ WHERE 1 = 1++ product_subscription_id = :product_subscription_id;END-- add product_subscriptiondiff --git a/admin/sql/mysqli/stat.sql b/admin/sql/mysqli/stat.sqlindex 2c88ba0..e75067d 100755--- a/admin/sql/mysqli/stat.sql+++ b/admin/sql/mysqli/stat.sql@@ -90,7 +90,7 @@-- orders- SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key+ SELECT COUNT(*) AS count, os.name, orders.order_status_id as array_keyFROM `order` AS ordersLEFT JOIN order_status AS os ON (orders.order_status_id = os.order_status_id AND os.language_id = :language_id)@@ -115,7 +115,7 @@END @IF- GROUP BY orders.order_status_id, os.name, date, orders.order_status_id;+ GROUP BY orders.order_status_id, os.name, orders.order_status_id;ENDCREATE PROCEDURE getCommentsCount(@@ -136,7 +136,7 @@-- comments- SELECT COUNT(*) AS count, DATE(created_at) as date, comments.status,comments.created_at, comments.status as array_key FROM comment AS comments+ SELECT COUNT(*) AS count, comments.status, comments.status as array_key FROM comment AS commentsWHERE 1 = 1@@ -162,7 +162,7 @@END @IF- GROUP BY comments.status, comments.created_at, date;+ GROUP BY comments.status;END@@ -184,7 +184,7 @@-- reviews- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews+ SELECT COUNT(*) AS count, reviews.status, reviews.status as array_key FROM product_review AS reviewsWHERE 1 = 1@@ -210,7 +210,7 @@END @IF- GROUP BY reviews.status, date;+ GROUP BY reviews.status;ENDCREATE PROCEDURE getQuestionsCount(@@ -231,7 +231,7 @@-- questions- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions+ SELECT COUNT(*) AS count, questions.status, questions.status as array_key FROM product_question AS questionsWHERE 1 = 1@@ -257,7 +257,7 @@END @IF- GROUP BY questions.status, date;+ GROUP BY questions.status;ENDCREATE PROCEDURE getProductStockCount(@@ -299,6 +299,6 @@END @IF- GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;+ GROUP BY products.stock_status_id, st.name ORDER BY products.stock_status_id;ENDdiff --git a/admin/sql/mysqli/user.sql b/admin/sql/mysqli/user.sqlindex 404a007..3cb99f4 100755--- a/admin/sql/mysqli/user.sql+++ b/admin/sql/mysqli/user.sql@@ -74,7 +74,7 @@@IF isset(:username)THEN- AND _.user = :user+ AND _.username = :usernameEND @IF@IF isset(:email)diff --git a/admin/sql/pgsql/comment.sql b/admin/sql/pgsql/comment.sqlindex aa86522..72444fa 100755--- a/admin/sql/pgsql/comment.sql+++ b/admin/sql/pgsql/comment.sql@@ -23,7 +23,7 @@)BEGIN- SELECT comment.*, user.*, comment_id as array_key+ SELECT user.*, comment.*, comment_id as array_keyFROM comment AS commentLEFT JOIN user ON (comment.user_id = comment.user_id)diff --git a/admin/sql/pgsql/coupon.sql b/admin/sql/pgsql/coupon.sqlindex e0c7ce3..bfbeaff 100755--- a/admin/sql/pgsql/coupon.sql+++ b/admin/sql/pgsql/coupon.sql@@ -29,12 +29,38 @@PROCEDURE get(IN coupon_id INT,+ IN code CHAR,+ IN free_shipping INT,+ IN status INT,OUT fetch_row,)BEGIN-- couponSELECT *- FROM coupon as _ WHERE coupon_id = :coupon_id;+ FROM coupon as _+ WHERE 1 = 1++ @IF !empty(:code)+ THEN+ AND code = :code+ END @IF++ @IF !empty(:free_shipping)+ THEN+ AND free_shipping = :free_shipping+ END @IF++ @IF !empty(:coupon_id)+ THEN+ AND coupon_id = :coupon_id+ END @IF++ @IF !empty(:status)+ THEN+ AND status = :status+ END @IF+ ;+END-- add coupondiff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sqlindex 1bdcee3..dffa4c6 100755--- a/admin/sql/pgsql/post.sql+++ b/admin/sql/pgsql/post.sql@@ -147,13 +147,13 @@-- month@IF isset(:month) && !empty(:month)THEN- AND date_part('month',created_at) = :month+ AND date_part('month',posts.created_at) = :monthEND @IF-- year@IF isset(:year) && !empty(:year)THEN- AND date_part('year',created_at) = :year+ AND date_part('year',posts.created_at) = :yearEND @IF-- order by@@ -364,6 +364,25 @@END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN post_content ARRAY,+ IN post_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN++ :post_content = @FILTER(:post_content, post_content);++ UPDATE post_content++ SET @LIST(:post_content)++ WHERE post_id = :post_id AND language_id = :language_id+ END+-- Delete post@@ -435,16 +454,16 @@BEGINSELECT- date_part('year',created_at) AS "year"+ date_part('year',archives.created_at) AS "year"@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,date_part('month',created_at) AS "month"+ ,date_part('month',archives.created_at) AS "month"END @IF@IF isset(:interval) AND :interval == "day"THEN- ,date_part('day',created_at) AS "day"+ ,date_part('day',archives.created_at) AS "day"END @IF,count(archives.post_id) as count@@ -466,29 +485,29 @@GROUP BY- date_part('year',created_at)+ date_part('year',archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,date_part('month',created_at)+ ,date_part('month',archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,date_part('day',created_at)+ ,date_part('day',archives.created_at)END @IFORDER BY- date_part('year',created_at)+ date_part('year',archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,date_part('month',created_at)+ ,date_part('month',archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,date_part('day',created_at)+ ,date_part('day',archives.created_at)END @IFdiff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sqlindex 845fb3d..6befc71 100755--- a/admin/sql/pgsql/product.sql+++ b/admin/sql/pgsql/product.sql@@ -441,6 +441,26 @@END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN product_content ARRAY,+ IN product_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN++ :product_content = @FILTER(:product_content, product_content);++ UPDATE product_content++ SET @LIST(:product_content)++ WHERE product_id = :product_id AND language_id = :language_id+ END++-- Add new productCREATE PROCEDURE add(@@ -718,7 +738,7 @@LOCAL special INT,LOCAL points INT,LOCAL stock_status INT,- LOCAL image_gallery INT,+ LOCAL product_image INT,-- return array of products for products queryOUT fetch_all,@@ -727,7 +747,7 @@)BEGIN- SELECT pd.*,products.*+ SELECT pd.*,products.*, products.product_id as array_key@IF !empty(:manufacturer)THEN@@ -737,7 +757,7 @@-- include image gallery- @IF !empty(:image_gallery)+ @IF !empty(:product_image)THEN--,(SELECT '[' || STRING_AGG('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images,(SELECT json_agg(json_build_object('id',pi.product_image_id,'image',pi.image)) FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as imagesdiff --git a/admin/sql/pgsql/product_option_value.sql b/admin/sql/pgsql/product_option_value.sqlindex 9b1a3f2..6d3647f 100644--- a/admin/sql/pgsql/product_option_value.sql+++ b/admin/sql/pgsql/product_option_value.sql@@ -6,6 +6,7 @@IN language_id INT,IN option_id INT,IN product_id INT,+ IN product_option_value_id ARRAY,IN start INT,IN limit INT,OUT fetch_all,@@ -13,10 +14,13 @@)BEGIN-- product_option_value- SELECT product_option_value.*, option_value.image, ovc.name, product_option_value.product_option_value_id as array_key+ SELECT product_option_value.*,+ option_value.image, ovc.name, oc.name as "option",+ product_option_value.product_option_value_id as array_keyFROM product_option_value AS product_option_valueINNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_idINNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id+ INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_idWHERE 1 = 1@@ -24,6 +28,12 @@@IF isset(:option_id)THENAND product_option_value.option_id = :option_id+ END @IF++ -- option_id+ @IF isset(:product_option_value_id)+ THEN+ AND product_option_value.product_option_value_id IN (:product_option_value_id)END @IF-- product_iddiff --git a/admin/sql/pgsql/product_question.sql b/admin/sql/pgsql/product_question.sqlindex 95ee84d..7a8cca9 100755--- a/admin/sql/pgsql/product_question.sql+++ b/admin/sql/pgsql/product_question.sql@@ -18,9 +18,9 @@)BEGIN- SELECT *+ SELECT user.*,product_question.*,user.user_id as user_idFROM product_question AS product_question- INNER JOIN user on user.user_id = product_question.user_id+ LEFT JOIN user on user.user_id = product_question.user_idWHERE 1 = 1diff --git a/admin/sql/pgsql/product_review.sql b/admin/sql/pgsql/product_review.sqlindex 00734c3..c1d69ad 100755--- a/admin/sql/pgsql/product_review.sql+++ b/admin/sql/pgsql/product_review.sql@@ -6,6 +6,7 @@IN language_id INT,IN site_id INT,IN product_id INT,+ IN slug CHAR,IN user_id INT,IN status INT,@@ -19,7 +20,7 @@)BEGIN- SELECT product_review.*,user.*,user.user_id as user_id,+ SELECT user.*,product_review.*,user.user_id as user_id,(SELECT json_agg(json_build_object('id',prm.product_review_media_id,'image',prm.image))FROM product_review_media as prmWHERE prm.product_review_id = product_review.product_review_id) as images@@ -29,13 +30,13 @@WHERE 1 = 1- -- post+ -- product@IF isset(:product_id)THENAND product_review.product_id = :product_idEND @IF- -- post slug+ -- product slug@IF isset(:slug)THENAND product_review.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)@@ -77,6 +78,84 @@INNER JOIN user on user.user_id = product_review.user_idWHERE product_review_id = :product_review_id LIMIT 1;+ END++ -- Get product reviews stats++ CREATE PROCEDURE getProductStats(+ -- variables+ IN language_id INT,+ IN site_id INT,+ IN product_id INT,+ IN slug CHAR,+ IN user_id INT,+ IN status INT,+ -- return+ OUT fetch_all, -- orders+ OUT fetch_one -- count+ )+ BEGIN++ -- rating count+ SELECT COUNT(*) AS count, summary.rating, summary.rating as array_key+ FROM product_review AS summary+ WHERE 1 = 1++ -- product+ @IF isset(:product_id)+ THEN+ AND summary.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND summary.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND summary.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND summary.status = :status+ END @IF++ GROUP BY summary.rating;++ SELECT AVG(rating.rating) as average+ FROM product_review AS rating+ WHERE 1 = 1+ -- product+ @IF isset(:product_id)+ THEN+ AND rating.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND rating.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND rating.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND rating.status = :status+ END @IF++ LIMIT 1;+END-- Add new product reviewdiff --git a/admin/sql/pgsql/stat.sql b/admin/sql/pgsql/stat.sqlindex bca72ce..c34d35c 100755--- a/admin/sql/pgsql/stat.sql+++ b/admin/sql/pgsql/stat.sql@@ -90,7 +90,7 @@-- orders- SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key+ SELECT COUNT(*) AS count, os.name, orders.order_status_id as array_keyFROM "order" AS ordersLEFT JOIN order_status AS os ON (orders.order_status_id = os.order_status_id AND os.language_id = :language_id)@@ -115,7 +115,7 @@END @IF- GROUP BY orders.order_status_id, os.name, date, orders.order_status_id;+ GROUP BY orders.order_status_id, os.name, orders.order_status_id;ENDCREATE PROCEDURE getCommentsCount(@@ -136,7 +136,7 @@-- comments- SELECT COUNT(*) AS count, DATE(created_at) as date, comments.status,comments.created_at, comments.status as array_key FROM comment AS comments+ SELECT COUNT(*) AS count, comments.status, comments.status as array_key FROM comment AS commentsWHERE 1 = 1@@ -162,7 +162,7 @@END @IF- GROUP BY comments.status, comments.created_at, date;+ GROUP BY comments.status;END@@ -184,7 +184,7 @@-- reviews- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews+ SELECT COUNT(*) AS count, reviews.status, reviews.status as array_key FROM product_review AS reviewsWHERE 1 = 1@@ -210,7 +210,7 @@END @IF- GROUP BY reviews.status, date;+ GROUP BY reviews.status;ENDCREATE PROCEDURE getQuestionsCount(@@ -231,7 +231,7 @@-- questions- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions+ SELECT COUNT(*) AS count, questions.status, questions.status as array_key FROM product_question AS questionsWHERE 1 = 1@@ -257,7 +257,7 @@END @IF- GROUP BY questions.status, date;+ GROUP BY questions.status;ENDCREATE PROCEDURE getProductStockCount(@@ -299,6 +299,6 @@END @IF- GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;+ GROUP BY products.stock_status_id, st.name ORDER BY products.stock_status_id;ENDdiff --git a/admin/sql/pgsql/user.sql b/admin/sql/pgsql/user.sqlindex 9382b76..9be9ae6 100755--- a/admin/sql/pgsql/user.sql+++ b/admin/sql/pgsql/user.sql@@ -74,7 +74,7 @@@IF isset(:username)THEN- AND _.user = :user+ AND _.username = :usernameEND @IF@IF isset(:email)diff --git a/admin/sql/sqlite/comment.sql b/admin/sql/sqlite/comment.sqlindex 487fc3e..9638cf3 100755--- a/admin/sql/sqlite/comment.sql+++ b/admin/sql/sqlite/comment.sql@@ -23,7 +23,7 @@)BEGIN- SELECT comment.*, user.*, comment_id as array_key+ SELECT user.*, comment.*, comment_id as array_keyFROM comment AS commentLEFT JOIN user ON (comment.user_id = comment.user_id)diff --git a/admin/sql/sqlite/coupon.sql b/admin/sql/sqlite/coupon.sqlindex e0c7ce3..bfbeaff 100755--- a/admin/sql/sqlite/coupon.sql+++ b/admin/sql/sqlite/coupon.sql@@ -29,12 +29,38 @@PROCEDURE get(IN coupon_id INT,+ IN code CHAR,+ IN free_shipping INT,+ IN status INT,OUT fetch_row,)BEGIN-- couponSELECT *- FROM coupon as _ WHERE coupon_id = :coupon_id;+ FROM coupon as _+ WHERE 1 = 1++ @IF !empty(:code)+ THEN+ AND code = :code+ END @IF++ @IF !empty(:free_shipping)+ THEN+ AND free_shipping = :free_shipping+ END @IF++ @IF !empty(:coupon_id)+ THEN+ AND coupon_id = :coupon_id+ END @IF++ @IF !empty(:status)+ THEN+ AND status = :status+ END @IF+ ;+END-- add coupondiff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sqlindex f013a07..75a6767 100755--- a/admin/sql/sqlite/post.sql+++ b/admin/sql/sqlite/post.sql@@ -143,13 +143,13 @@-- month@IF isset(:month) && !empty(:month)THEN- AND strftime('%M', created_at) = :month+ AND strftime('%M', posts.created_at) = :monthEND @IF-- year@IF isset(:year) && !empty(:year)THEN- AND strftime('%Y', created_at) = :year+ AND strftime('%Y', posts.created_at) = :yearEND @IF-- order by@@ -359,7 +359,26 @@COMMIT;END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN post_content ARRAY,+ IN post_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN+ :post_content = @FILTER(:post_content, post_content);++ UPDATE post_content++ SET @LIST(:post_content)++ WHERE post_id = :post_id AND language_id = :language_id+ END++-- Delete postCREATE PROCEDURE delete(@@ -430,16 +449,16 @@BEGINSELECT- strftime('%Y',created_at) AS `year`+ strftime('%Y',archives.created_at) AS `year`@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,strftime('%M',created_at) AS `month`+ ,strftime('%M',archives.created_at) AS `month`END @IF@IF isset(:interval) AND :interval == "day"THEN- ,strftime('%D',created_at) AS `day`+ ,strftime('%D',archives.created_at) AS `day`END @IF,count(archives.post_id) as count@@ -461,29 +480,29 @@GROUP BY- strftime('%Y',created_at)+ strftime('%Y',archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,strftime('%M',created_at)+ ,strftime('%M',archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,strftime('%D',created_at)+ ,strftime('%D',archives.created_at)END @IFORDER BY- strftime('%Y',created_at)+ strftime('%Y',archives.created_at)@IF isset(:interval) AND (:interval == "month" || :interval == "day")THEN- ,strftime('%M',created_at)+ ,strftime('%M',archives.created_at)END @IF@IF isset(:interval) AND :interval == "day"THEN- ,strftime('%D',created_at)+ ,strftime('%D',archives.created_at)END @IFdiff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sqlindex e492ea0..3b5e7f8 100755--- a/admin/sql/sqlite/product.sql+++ b/admin/sql/sqlite/product.sql@@ -440,6 +440,26 @@END+ -- Edit post content++ CREATE PROCEDURE editContent(+ IN product_content ARRAY,+ IN product_id INT,+ IN language_id INT,+ OUT affected_rows+ )+ BEGIN++ :product_content = @FILTER(:product_content, product_content);++ UPDATE product_content++ SET @LIST(:product_content)++ WHERE product_id = :product_id AND language_id = :language_id+ END++-- Add new productCREATE PROCEDURE add(@@ -719,7 +739,7 @@LOCAL special INT,LOCAL points INT,LOCAL stock_status INT,- LOCAL image_gallery INT,+ LOCAL product_image INT,-- return array of products for products queryOUT fetch_all,@@ -728,7 +748,7 @@)BEGIN- SELECT pd.*,products.*+ SELECT pd.*,products.*, products.product_id as array_key@IF !empty(:manufacturer)THEN@@ -738,7 +758,7 @@-- include image gallery- @IF !empty(:image_gallery)+ @IF !empty(:product_image)THEN-- uncomment the group concat version if you are using an older sqlite version-- ,(SELECT '[' || GROUP_CONCAT('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as imagesdiff --git a/admin/sql/sqlite/product_option_value.sql b/admin/sql/sqlite/product_option_value.sqlindex 9b1a3f2..cbd46bb 100644--- a/admin/sql/sqlite/product_option_value.sql+++ b/admin/sql/sqlite/product_option_value.sql@@ -6,6 +6,7 @@IN language_id INT,IN option_id INT,IN product_id INT,+ IN product_option_value_id ARRAY,IN start INT,IN limit INT,OUT fetch_all,@@ -13,10 +14,13 @@)BEGIN-- product_option_value- SELECT product_option_value.*, option_value.image, ovc.name, product_option_value.product_option_value_id as array_key+ SELECT product_option_value.*,+ option_value.image, ovc.name, oc.name as `option`,+ product_option_value.product_option_value_id as array_keyFROM product_option_value AS product_option_valueINNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_idINNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id+ INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_idWHERE 1 = 1@@ -24,6 +28,12 @@@IF isset(:option_id)THENAND product_option_value.option_id = :option_id+ END @IF++ -- option_id+ @IF isset(:product_option_value_id)+ THEN+ AND product_option_value.product_option_value_id IN (:product_option_value_id)END @IF-- product_iddiff --git a/admin/sql/sqlite/product_question.sql b/admin/sql/sqlite/product_question.sqlindex 5e6d47d..a2adec2 100755--- a/admin/sql/sqlite/product_question.sql+++ b/admin/sql/sqlite/product_question.sql@@ -18,9 +18,9 @@)BEGIN- SELECT *+ SELECT user.*,product_question.*,user.user_id as user_idFROM product_question AS product_question- INNER JOIN user on user.user_id = product_question.user_id+ LEFT JOIN user on user.user_id = product_question.user_idWHERE 1 = 1diff --git a/admin/sql/sqlite/product_review.sql b/admin/sql/sqlite/product_review.sqlindex e9080e3..3a9b96b 100755--- a/admin/sql/sqlite/product_review.sql+++ b/admin/sql/sqlite/product_review.sql@@ -6,6 +6,7 @@IN language_id INT,IN site_id INT,IN product_id INT,+ IN slug CHAR,IN user_id INT,IN status INT,@@ -19,7 +20,7 @@)BEGIN- SELECT product_review.*,user.*,user.user_id as user_id,+ SELECT user.*,product_review.*,user.user_id as user_id,(SELECT json_group_array(json_object('id',prm.product_review_media_id,'image',prm.image))FROM product_review_media as prmWHERE prm.product_review_id = product_review.product_review_id) as images@@ -29,13 +30,13 @@WHERE 1 = 1- -- post+ -- product@IF isset(:product_id)THENAND product_review.product_id = :product_idEND @IF- -- post slug+ -- product slug@IF isset(:slug)THENAND product_review.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)@@ -77,6 +78,84 @@INNER JOIN user on user.user_id = product_review.user_idWHERE product_review_id = :product_review_id LIMIT 1;+ END++ -- Get product reviews stats++ CREATE PROCEDURE getProductStats(+ -- variables+ IN language_id INT,+ IN site_id INT,+ IN product_id INT,+ IN slug CHAR,+ IN user_id INT,+ IN status INT,+ -- return+ OUT fetch_all, -- orders+ OUT fetch_one -- count+ )+ BEGIN++ -- rating count+ SELECT COUNT(*) AS count, summary.rating, summary.rating as array_key+ FROM product_review AS summary+ WHERE 1 = 1++ -- product+ @IF isset(:product_id)+ THEN+ AND summary.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND summary.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND summary.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND summary.status = :status+ END @IF++ GROUP BY summary.rating;++ SELECT AVG(rating.rating) as average+ FROM product_review AS rating+ WHERE 1 = 1+ -- product+ @IF isset(:product_id)+ THEN+ AND rating.product_id = :product_id+ END @IF++ -- product slug+ @IF isset(:slug)+ THEN+ AND rating.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)+ END @IF++ -- user+ @IF isset(:user_id)+ THEN+ AND rating.user_id = :user_id+ END @IF++ -- status+ @IF isset(:status)+ THEN+ AND rating.status = :status+ END @IF++ LIMIT 1;+END-- Add new product reviewdiff --git a/admin/sql/sqlite/stat.sql b/admin/sql/sqlite/stat.sqlindex 4f04a35..e75067d 100755--- a/admin/sql/sqlite/stat.sql+++ b/admin/sql/sqlite/stat.sql@@ -90,7 +90,7 @@-- orders- SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key+ SELECT COUNT(*) AS count, os.name, orders.order_status_id as array_keyFROM `order` AS ordersLEFT JOIN order_status AS os ON (orders.order_status_id = os.order_status_id AND os.language_id = :language_id)@@ -115,7 +115,7 @@END @IF- GROUP BY orders.order_status_id, os.name, date;+ GROUP BY orders.order_status_id, os.name, orders.order_status_id;ENDCREATE PROCEDURE getCommentsCount(@@ -136,7 +136,7 @@-- comments- SELECT COUNT(*) AS count, DATE(created_at) as date, comments.status,comments.created_at, comments.status as array_key FROM comment AS comments+ SELECT COUNT(*) AS count, comments.status, comments.status as array_key FROM comment AS commentsWHERE 1 = 1@@ -162,7 +162,7 @@END @IF- GROUP BY comments.status, comments.created_at, date;+ GROUP BY comments.status;END@@ -184,7 +184,7 @@-- reviews- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews+ SELECT COUNT(*) AS count, reviews.status, reviews.status as array_key FROM product_review AS reviewsWHERE 1 = 1@@ -210,7 +210,7 @@END @IF- GROUP BY reviews.status, date;+ GROUP BY reviews.status;ENDCREATE PROCEDURE getQuestionsCount(@@ -231,7 +231,7 @@-- questions- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions+ SELECT COUNT(*) AS count, questions.status, questions.status as array_key FROM product_question AS questionsWHERE 1 = 1@@ -257,7 +257,7 @@END @IF- GROUP BY questions.status, date;+ GROUP BY questions.status;ENDCREATE PROCEDURE getProductStockCount(@@ -299,6 +299,6 @@END @IF- GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;+ GROUP BY products.stock_status_id, st.name ORDER BY products.stock_status_id;ENDdiff --git a/admin/sql/sqlite/user.sql b/admin/sql/sqlite/user.sqlindex 2962637..9aca8a3 100755--- a/admin/sql/sqlite/user.sql+++ b/admin/sql/sqlite/user.sql@@ -74,7 +74,7 @@@IF isset(:username)THEN- AND _.user = :user+ AND _.username = :usernameEND @IF@IF isset(:email)diff --git a/admin/template/content/edit.tpl b/admin/template/content/edit.tplindex a0d5798..41d3142 100644--- a/admin/template/content/edit.tpl+++ b/admin/template/content/edit.tpl@@ -66,6 +66,7 @@ if ($optgroup != $option['folder']) {[data-v-languages] [data-v-language]|before = <?phpforeach ($this->languagesList as $language) {+ $content = $this->{{type}}['{{type}}_content'][$language['language_id']] ?? [];?>[data-v-languages] [data-v-language-id]|id = <?php echo 'lang-' . $language['code'] . '-' . $_lang_instance;?>[data-v-languages] [data-v-language-id]|addClass = <?php if ($_i == 0) echo 'show active';?>@@ -87,26 +88,26 @@ $_i++;[data-v-{{type}}] input[data-v-{{type}}-content-*]|value = <?php$desc = '@@__data-v-{{type}}-content-(*)__@@';- if (isset($this->{{type}}['{{type}}_content'][$language['language_id']][$desc]))- echo $this->{{type}}['{{type}}_content'][$language['language_id']][$desc];+ if (isset($content[$desc]))+ echo $content[$desc];?>[data-v-{{type}}] [data-v-{{type}}-content-*]|innerText = <?php$desc = '@@__data-v-{{type}}-content-(*)__@@';- if (isset($this->{{type}}['{{type}}_content'][$language['language_id']][$desc]))- echo $this->{{type}}['{{type}}_content'][$language['language_id']][$desc];+ if (isset($content[$desc]))+ echo $content[$desc];?>[data-v-{{type}}] a[data-v-{{type}}-content-*]|href = <?php$desc = '@@__data-v-{{type}}-content-(*)__@@';- if (isset($this->{{type}}['{{type}}_content'][$language['language_id']][$desc]))- echo $this->{{type}}['{{type}}_content'][$language['language_id']][$desc];+ if (isset($content[$desc]))+ echo $content[$desc];?>[data-v-{{type}}] textarea[data-v-{{type}}-content-*] = <?php$desc = '@@__data-v-{{type}}-content-(*)__@@';- if (isset($this->{{type}}['{{type}}_content'][$language['language_id']][$desc]))- echo $this->{{type}}['{{type}}_content'][$language['language_id']][$desc];+ if (isset($content[$desc]))+ echo $content[$desc];?>[data-v-{{type}}] input[data-v-{{type}}-content-language_id]|value = <?php echo $language['language_id']; ?>@@ -118,7 +119,7 @@ $_i++;[data-v-languages] [data-v-language] [data-v-revision]|deleteAllButFirstChild[data-v-languages] [data-v-language] [data-v-revision]|before = <?php-$revisions = $this->{{type}}['{{type}}_content'][$language['language_id']]['revision'];+$revisions = $content['revision'];foreach ($revisions as $revision) {?>@@ -133,5 +134,6 @@ foreach ($revisions as $revision) {}?>+[data-v-{{type}}] [data-v-revisions_url]|href = $this->revisions_urlimport(content/post_taxonomy.tpl)\ No newline at end of filediff --git a/admin/template/content/post.tpl b/admin/template/content/post.tplindex 5c4dd35..5facabf 100755--- a/admin/template/content/post.tpl+++ b/admin/template/content/post.tpl@@ -2,12 +2,12 @@ import(crud.tpl, {"type":"post"})import(content/edit.tpl, {"type":"post"})/* Links */-[data-v-post] [data-v-url]|href = $this->post['url']-[data-v-post] [data-v-url] = $this->post['url']+[data-v-post] [data-v-url]|href = $this->post['url']+[data-v-post] [data-v-url] = $this->post['url'][data-v-post] [data-v-design_url]|href = $this->post['design_url']-[data-v-template_missing] = <?php echo $this->template_missing;?>-[data-v-type_name_plural] = $this->type_name_plural-[data-v-type-name] = $this->type_name-[data-v-type] = $this->type+[data-v-template_missing] = <?php echo $this->template_missing;?>+[data-v-type_name_plural] = $this->type_name_plural+[data-v-type-name] = $this->type_name+[data-v-type] = $this->type[data-v-posts-list-url]|href = $this->posts_list_urldiff --git a/admin/template/content/revisions.tpl b/admin/template/content/revisions.tplnew file mode 100644index 0000000..aab2fb3--- /dev/null+++ b/admin/template/content/revisions.tpl@@ -0,0 +1,18 @@+import(common.tpl)++[data-v-post-*] = $this->post['@@__data-v-post-(*)__@@']+img[data-v-post-*]|src = $this->post['@@__data-v-post-(*)__@@']+[data-v-revision-*] = $this->revision['@@__data-v-revision-(*)__@@']++@revision = [data-v-revisions-list] [data-v-option]++@revision|deleteAllButFirstChild++@revision|before = <?php+foreach ($this->revisions as $revision) {?>+ @revision|value = $revision['created_at']+ @revision = <?php echo Vvveb\friendlyDate($revision['created_at']) . ' | ' . $revision['created_at'] . ' | ' .$revision['display_name'];?>++@revision|after = <?php+ }+?>diff --git a/admin/template/product/revisions.tpl b/admin/template/product/revisions.tplnew file mode 100644index 0000000..aab2fb3--- /dev/null+++ b/admin/template/product/revisions.tpl@@ -0,0 +1,18 @@+import(common.tpl)++[data-v-post-*] = $this->post['@@__data-v-post-(*)__@@']+img[data-v-post-*]|src = $this->post['@@__data-v-post-(*)__@@']+[data-v-revision-*] = $this->revision['@@__data-v-revision-(*)__@@']++@revision = [data-v-revisions-list] [data-v-option]++@revision|deleteAllButFirstChild++@revision|before = <?php+foreach ($this->revisions as $revision) {?>+ @revision|value = $revision['created_at']+ @revision = <?php echo Vvveb\friendlyDate($revision['created_at']) . ' | ' . $revision['created_at'] . ' | ' .$revision['display_name'];?>++@revision|after = <?php+ }+?>diff --git a/app/component/cart.php b/app/component/cart.phpindex c691072..cea43b0 100755--- a/app/component/cart.php+++ b/app/component/cart.php@@ -42,11 +42,12 @@ class Cart extends ComponentBase {protected $options = [];function results() {- $cart = ShoppingCart::getInstance($this->options);- $results['products'] = $cart->getAll();- $results['total_items'] = $cart->getNoProducts();- $results['totals'] = $cart->getTotals();- $results['total'] = $cart->getGrandTotal();+ $cart = ShoppingCart::getInstance($this->options);+ $results['products'] = $cart->getAll();+ $results['coupons'] = $cart->getCoupons();+ $results['total_items'] = $cart->getNoProducts();+ $results['totals'] = $cart->getTotals();+ $results['total'] = $cart->getGrandTotal();$results['total_formatted'] = $cart->getGrandTotalFormatted();list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);diff --git a/app/component/comments.php b/app/component/comments.phpindex 34f2124..e6615bc 100755--- a/app/component/comments.php+++ b/app/component/comments.php@@ -49,8 +49,8 @@ class Comments extends ComponentBase {//called when fetching data, when cache expiresfunction results() {- $comments = model($this->model); //new CommentSQL();- $results = $comments->getAll($this->options);+ $this->modelInstance = model($this->model); //new CommentSQL();+ $results = $this->modelInstance->getAll($this->options);$results[$this->type] = $results[$this->type] ?? [];$order = $this->options['order'];diff --git a/app/component/products.php b/app/component/products.phpindex 9ac7f7f..6129064 100755--- a/app/component/products.php+++ b/app/component/products.php@@ -31,27 +31,27 @@ use function Vvveb\url;class Products extends ComponentBase {public static $defaultOptions = [- 'start' => 0,- 'page' => 1,- 'limit' => 4,- 'status' => 1,- 'source' => 'autocomplete',- 'language_id' => null,- 'site_id' => null,- 'type' => 'product',- 'parent' => null,- 'manufacturer_id' => NULL,- 'vendor_id' => NULL,- 'order_by' => NULL,- 'direction' => ['url', 'asc', 'desc'],- 'taxonomy_item_id' => NULL,- 'image_gallery' => true,- 'product_id' => [],- 'search' => null,- 'slug' => null,- 'related' => null,- 'variant' => null,- 'image_size' => 'medium',+ 'start' => 0,+ 'page' => 1,+ 'limit' => 4,+ 'status' => 1,+ 'source' => 'autocomplete',+ 'language_id' => null,+ 'site_id' => null,+ 'type' => 'product',+ 'parent' => null,+ 'manufacturer_id' => NULL,+ 'vendor_id' => NULL,+ 'order_by' => NULL,+ 'direction' => ['url', 'asc', 'desc'],+ 'taxonomy_item_id'=> NULL,+ 'product_image' => true,+ 'product_id' => [],+ 'search' => null,+ 'slug' => null,+ 'related' => null,+ 'variant' => null,+ 'image_size' => 'medium',];public $options = [];diff --git a/app/component/questions.php b/app/component/questions.phpindex fdc6035..fd6037e 100644--- a/app/component/questions.php+++ b/app/component/questions.php@@ -23,17 +23,17 @@namespace Vvveb\Component;class Questions extends Comments {- protected $type = 'question';+ protected $type = 'product_question';protected $route = 'product/product/index';-+protected $model = 'product_question';public static $defaultOptions = ['product_id' => 'url','slug' => 'url',- 'post_title' => null, //include post title (for recent reviews etc)- 'status' => 1, //approved reviews+ 'product_title' => null, //include post title (for recent questions etc)+ 'status' => 1, //approved questions'start' => 0,'limit' => 10,'order' => 'asc', //descdiff --git a/app/component/reviews.php b/app/component/reviews.phpindex 63cb908..ed350c9 100755--- a/app/component/reviews.php+++ b/app/component/reviews.php@@ -25,20 +25,22 @@ use Vvveb\Sql\Product_Review_MediaSQL;use Vvveb\System\Images;class Reviews extends Comments {- protected $type = 'review';+ protected $type = 'product_review';protected $route = 'product/product/index';protected $model = 'product_review';public static $defaultOptions = [- 'product_id' => 'url',- 'user_id' => NULL,- 'status' => 1, //approved reviews- 'start' => 0,- 'limit' => 10,- 'image_size' => 'thumb',- 'order' => 'asc', //desc+ 'product_id' => 'url',+ 'slug' => 'url',+ 'product_title' => NULL, //include product title (for recent reviews etc)+ 'user_id' => NULL,+ 'status' => 1, //approved reviews+ 'start' => 0,+ 'limit' => 10,+ 'image_size' => 'thumb',+ 'order' => 'asc', //desc];function results() {@@ -70,6 +72,25 @@ class Reviews extends Comments {$results['images'] = $gallery;+ $stats = $this->modelInstance->getProductStats($this->options);+ if ($stats) {+ $results += $stats;+ }++ $results['rating'] = number_format($results['rating'] ?? 0, 1);++ //compute width and fill missing ratings+ foreach ([1,2,3,4,5] as $rating) {+ if (isset($results['summary'][$rating])) {+ $summary = &$results['summary'][$rating];+ $summary['percent'] = ceil($summary['count'] * 100 / $results['count']);+ } else {+ $results['summary'][$rating]['percent'] = 0;+ $results['summary'][$rating]['rating'] = 1;+ $results['summary'][$rating]['count'] = 0;+ }+ }+return $results;}}diff --git a/app/controller/cart/cart.php b/app/controller/cart/cart.phpindex 88612de..86d84e6 100755--- a/app/controller/cart/cart.php+++ b/app/controller/cart/cart.php@@ -29,6 +29,8 @@ use Vvveb\System\Payment;use Vvveb\System\Shipping;class Cart extends Base {+ use CouponTrait;+function index() {$cart = ShoppingCart::getInstance($this->global);$payment = Payment::getInstance();@@ -48,32 +50,23 @@ class Cart extends Base {'total_items' => $cart->getNoProducts(),'total_price' => $cart->getNoProducts(),'total' => $cart->getGrandTotal(),+ 'coupons' => $cart->getCoupons(),'total_formatted' => $cart->getGrandTotalFormatted(),];$this->view->cart = $cart;}-- function coupon() {- $coupon = $this->request->request['coupon'] ?? '';--- $cart = ShoppingCart::getInstance($this->global);--- return $this->index();- }-private function action($action, $productId = null, $quantity = 1) {$cart = ShoppingCart::getInstance($this->global);- $productId = $this->request->request['product_id'];- $quantity = $this->request->request['quantity'] ?? $quantity;- $option = $this->request->request['option'] ?? [];- $subscriptionPlanId = $this->request->request['subscription_plan_id'] ?? false;+ $productId = $this->request->request['product_id'] ?? false;+ $key = $this->request->request['key'] ?? false;+ $quantity = $this->request->request['quantity'] ?? $quantity;+ $option = $this->request->request['option'] ?? [];+ $subscriptionPlanId = $this->request->request['subscription_plan_id'] ?? false;- if (isset($productId)) {+ if ($key || $productId) {//$this->view->success = false;switch ($action) {case 'add':@@ -82,12 +75,12 @@ class Cart extends Base {break;case 'update':- $cart->update($productId, $quantity);+ $cart->update($key, $quantity);break;case 'remove':- $cart->remove($productId);+ $cart->remove($key);break;}diff --git a/app/controller/cart/coupon-trait.php b/app/controller/cart/coupon-trait.phpnew file mode 100644index 0000000..d9d4520--- /dev/null+++ b/app/controller/cart/coupon-trait.php@@ -0,0 +1,60 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Cart;++use function Vvveb\__;+use Vvveb\System\Cart\Cart as ShoppingCart;++trait CouponTrait {+ function coupon() {+ $coupon = $this->request->request['coupon'] ?? '';++ if ($coupon) {+ $cart = ShoppingCart::getInstance($this->global);++ if ($cart->addCoupon($coupon)) {+ $this->view->success['coupon'] = __('Coupon successfully applied!');+ } else {+ $this->view->errors['coupon'] = __('Invalid or expired coupon!');+ }+ }++ return $this->index();+ }++ function removeCoupon() {+ $coupon = $this->request->request['coupon'] ?? '';++ if ($coupon) {+ $cart = ShoppingCart::getInstance($this->global);++ if ($cart->removeCoupon($coupon)) {+ $this->view->success['coupon'] = __('Coupon removed!');+ } else {+ $this->view->errors['coupon'] = __('Could not remove coupon!');+ }+ }++ return $this->index();+ }+}diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.phpindex 30d4eed..58c08af 100755--- a/app/controller/checkout/checkout.php+++ b/app/controller/checkout/checkout.php@@ -24,6 +24,7 @@ namespace Vvveb\Controller\Checkout;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\Controller\Cart\CouponTrait;use Vvveb\Controller\User\LoginTrait;use function Vvveb\email;use function Vvveb\prefixArrayKeys;@@ -42,7 +43,7 @@ use Vvveb\System\Validator;use function Vvveb\url;class Checkout extends Base {- use LoginTrait;+ use LoginTrait, CouponTrait;/*use LoginTrait {@@ -56,10 +57,6 @@ class Checkout extends Base {return $this->index();}*/- function coupon() {- $this->response->setType('json');- $this->response->output($result);- }function regions() {$country_id = $this->request->get['country_id'] ?? false;diff --git a/app/controller/content/comment-trait.php b/app/controller/content/comment-trait.phpnew file mode 100644index 0000000..d167888--- /dev/null+++ b/app/controller/content/comment-trait.php@@ -0,0 +1,71 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Content;++use function Vvveb\__;+use function Vvveb\model;+use function Vvveb\sanitizeHTML;++trait CommentTrait {+ private function insertComment($commentType = 'comment', $text = 'comment') {+ $result = false;+ $post = &$this->request->post;++ if (isset($post['content'])) {+ //robots will also fill hidden inputs+ $notRobot =+ (isset($post['firstname-empty']) && empty($post['firstname-empty']) &&+ isset($post['lastname-empty']) && empty($post['lastname-empty']) &&+ isset($post['subject-empty']) && empty($post['subject-empty']));++ if ($notRobot) {+ $user = $this->global['user'];++ if ($user) {+ $user['author'] = $user['display_name'];+ }++ $post['content'] = sanitizeHTML($post['content']);++ //$sql = new \Vvveb\Sql\CommentSQL();+ $sql = model($commentType);+ $comment = array_merge($post, $user, ['created_at' => date('Y-m-d H:i:s'), 'status' => 0]);+ $result = $sql->add([$commentType => $comment]);++ if ($result[$commentType]) {+ $comment["{$commentType}_id"] = $result[$commentType];++ $comments = $this->session->get('comments', []);+ $comments[$comment['slug']][$comment["{$commentType}_id"]] = $comment;+ $this->session->set($commentType, $comments);++ $this->view->success[] = ucfirst($text) . __(' was posted!');+ } else {+ $this->view->errors[] = sprintf(__('Error adding %s!'), $text);+ }+ }+ }++ return $result;+ }+}diff --git a/app/controller/content/post.php b/app/controller/content/post.phpindex 6e1d95b..00f4d52 100755--- a/app/controller/content/post.php+++ b/app/controller/content/post.php@@ -31,54 +31,10 @@ use function Vvveb\sanitizeHTML;class Post extends Base {public $type = 'post';- private function insertComment() {- $result = false;- $post = &$this->request->post;-- if (isset($post['content'])) {- //robots will also fill hidden inputs- $notRobot =- (isset($post['firstname-empty']) && empty($post['firstname-empty']) &&- isset($post['lastname-empty']) && empty($post['lastname-empty']) &&- isset($post['subject-empty']) && empty($post['subject-empty']));-- if ($notRobot) {- $user = $this->global['user'];-- if ($user) {- $user['author'] = $user['display_name'];- }-- $post['content'] = sanitizeHTML($post['content']);-- $sql = new \Vvveb\Sql\CommentSQL();- $comment = array_merge($post, $user, ['created_at' => date('Y-m-d H:i:s'), 'status' => 0]);- $result = $sql->add(['comment' => $comment]);-- if ($result['comment']) {- $comment['comment_id'] = $result['comment'];-- $comments = $this->session->get('comments', []);- $comments[$comment['slug']][$comment['comment_id']] = $comment;- $this->session->set('comment', $comments);-- $this->view->success[] = __('Comment was posted!');- } else {- $this->view->errors[] = __('Error adding comment!');- }- }- }-- return $result;- }+ use CommentTrait;function addComment() {return $this->index();- //$result = $this->insertComment();- //$this->response->setType('json');- //$this->response->output($result);-- //return false;}function index() {diff --git a/app/controller/product/product.php b/app/controller/product/product.phpindex 98f92e4..ad07d3e 100755--- a/app/controller/product/product.php+++ b/app/controller/product/product.php@@ -25,54 +25,29 @@ namespace Vvveb\Controller\Product;use \Vvveb\Sql\ProductSQL;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\Controller\Content\CommentTrait;class Product extends Base {public $type = 'product';++ use CommentTrait;- private function insertComment() {- $result = false;- $product = &$this->request->product;-- if (isset($product['content'])) {- //robots will also fill hidden inputs- $notRobot =- (isset($product['firstname-empty']) && empty($product['firstname-empty']) &&- isset($product['lastname-empty']) && empty($product['lastname-empty']) &&- isset($product['subject-empty']) && empty($product['subject-empty']));-- if ($notRobot) {- $user = $this->global['user'];-- if ($user) {- $user['author'] = $user['display_name'];- }-- $product['content'] = sanitizeHTML($product['content']);-- $sql = new \Vvveb\Sql\CommentSQL();- $comment = array_merge($product, $user, ['created_at' => date('Y-m-d H:i:s'), 'status' => 0]);- $result = $sql->add(['comment' => $comment]);-- if ($result['comment']) {- $comment['comment_id'] = $result['comment'];-- $comments = $this->session->get('comments', []);- $comments[$comment['slug']][$comment['comment_id']] = $comment;- $this->session->set('comments', $comments);-- $this->view->success[] = __('Comment was producted!');- } else {- $this->view->errors[] = __('Error adding comment!');- }- }- }+ function addReview() {+ return $this->index();+ }- return $result;+ function addQuestion() {+ return $this->index();}+function index() {- if (isset($this->request->product['content'])) {- $result = $this->insertComment();+ if (isset($this->request->post['content'])) {+ if (isset($this->request->post['rating'])) {+ $result = $this->insertComment('product_review', __('review'));+ } else {+ $result = $this->insertComment('product_question', __('question'));+ }}$language = $this->request->get['language'] ?? '';diff --git a/app/controller/user/reset.php b/app/controller/user/reset.phpindex e5f08e9..3e9115c 100644--- a/app/controller/user/reset.php+++ b/app/controller/user/reset.php@@ -43,15 +43,15 @@ class Reset extends Base {if ($password && $admin) {if (User::update(['token' => '', 'password' => $password], ['username' => $user, 'token' => $token])) {- $success = __('Password was reset!');- $this->view->success['get'] = $success;- $this->session->set('success', $success);+ $success = __('Password was reset!');+ $this->view->success['login'] = $success;+ $this->session->set('success', ['login' => $success]);$this->redirect('/user/login');//header('Location: ' . url(['module' => 'user/login', 'success' => $success]));} else {- $errors = __('Update failed!');- $this->view->errors[] = $errors;- $this->session->set('errors', $errors);+ $errors = __('Update failed!');+ $this->view->errors['login'] = $errors;+ $this->session->set('errors', ['login' => $errors]);}}}@@ -110,7 +110,7 @@ class Reset extends Base {$this->view->errors[] = __('Error sending reset email!');}} else {- $this->view->errors[] = __('Email not found!');+ $this->view->errors['login'] = __('Email not found!');}}}diff --git a/app/controller/user/return-form.php b/app/controller/user/return-form.phpnew file mode 100755index 0000000..9e34f4e--- /dev/null+++ b/app/controller/user/return-form.php@@ -0,0 +1,35 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\User;++use Vvveb\Controller\Base;+use Vvveb\Sql\Return_ReasonSQL;++class ReturnForm extends Base {+ function index() {+ $reason = new Return_ReasonSQL();+ $reasons = $reason->getAll($this->global + ['start' => 0, 'limit' => 100])['return_reason'] ?? [];++ $this->view->return_reason_id = $reasons;+ }+}diff --git a/app/controller/user/signup.php b/app/controller/user/signup.phpindex 9eaec89..1491fae 100755--- a/app/controller/user/signup.php+++ b/app/controller/user/signup.php@@ -48,7 +48,7 @@ class Signup extends \Vvveb\Controller\Base {if (is_array($result)) {$message = __('User created!');$this->session->set('success', ['login' => $message]);- $this->view->success['login'][] = $message;+ $this->view->success['login'][] = $message;$user_id = $result['user'];$this->request->request['user_id'] = $user_id;diff --git a/app/sql/mysqli/coupon.sql b/app/sql/mysqli/coupon.sqlnew file mode 100755index 0000000..5246952--- /dev/null+++ b/app/sql/mysqli/coupon.sql@@ -0,0 +1,5 @@+-- Coupon++ -- get common code from admin+ import(/admin/coupon.sql);+diff --git a/app/sql/mysqli/return_reason.sql b/app/sql/mysqli/return_reason.sqlnew file mode 100755index 0000000..6c13e58--- /dev/null+++ b/app/sql/mysqli/return_reason.sql@@ -0,0 +1,5 @@+-- Return reason++ -- get common code from admin+ import(/admin/return_reason.sql);+diff --git a/app/sql/pgsql/coupon.sql b/app/sql/pgsql/coupon.sqlnew file mode 100755index 0000000..5246952--- /dev/null+++ b/app/sql/pgsql/coupon.sql@@ -0,0 +1,5 @@+-- Coupon++ -- get common code from admin+ import(/admin/coupon.sql);+diff --git a/app/sql/pgsql/return_reason.sql b/app/sql/pgsql/return_reason.sqlnew file mode 100755index 0000000..6c13e58--- /dev/null+++ b/app/sql/pgsql/return_reason.sql@@ -0,0 +1,5 @@+-- Return reason++ -- get common code from admin+ import(/admin/return_reason.sql);+diff --git a/app/sql/sqlite/coupon.sql b/app/sql/sqlite/coupon.sqlnew file mode 100755index 0000000..5246952--- /dev/null+++ b/app/sql/sqlite/coupon.sql@@ -0,0 +1,5 @@+-- Coupon++ -- get common code from admin+ import(/admin/coupon.sql);+diff --git a/app/sql/sqlite/return_reason.sql b/app/sql/sqlite/return_reason.sqlnew file mode 100755index 0000000..6c13e58--- /dev/null+++ b/app/sql/sqlite/return_reason.sql@@ -0,0 +1,5 @@+-- Return reason++ -- get common code from admin+ import(/admin/return_reason.sql);+diff --git a/app/template/cart/cart.tpl b/app/template/cart/cart.tplindex d4e10a6..d1d5daf 100755--- a/app/template/cart/cart.tpl+++ b/app/template/cart/cart.tpl@@ -11,14 +11,16 @@ $products = $this->cart['products'];$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'product_id' => 1, 'image' => '#']] : false;$products = empty($products) ? $_default : $products;-if(is_array($products)) foreach ($products as $index => $product) {+if(is_array($products)) foreach ($products as $key => $product) {?>//@cart-product [data-v-cart-product-name] = $product['name']//@cart-product [data-v-cart-product-content] = $product['content']//@cart-product [data-v-cart-product-amount] = <?php echo $product['amount'];?>- @cart-product|data-product_id = $product['product_id']+ @cart-product|data-product_id = $product['product_id']+ @cart-product|data-key = $key+@cart-product img[data-v-cart-product-image]|src = $product['image']//catch all data attributes@@ -30,6 +32,24 @@ if(is_array($products)) foreach ($products as $index => $product) {@cart-product|after = <?php }?>+@cart-option = [data-v-cart] [data-v-cart-product] [data-v-product-option]+@cart-option|deleteAllButFirstChild+++@cart-option|before = <?php+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_option_value_id' => 1]] : false;+$option_value = empty($product['option_value']) ? $_default : $product['option_value'];++if($option_value) {+ foreach ($option_value as $product_option_value_id => $value) { ?>++ @cart-option [data-v-product-option-*]|innerText = $value['@@__data-v-product-option-(*)__@@']+++@cart-option|after = <?php }+}+?>+@total = [data-v-cart-page] [data-v-cart-totals] [data-v-cart-total]@total|deleteAllButFirstChild@@ -48,3 +68,23 @@ if(is_array($totals)) foreach ($totals as $index => $total) {@total input[data-v-cart-total-*]|value = $total['@@__data-v-cart-total-(*)__@@']@total|after = <?php }?>+++@coupon = [data-v-cart-page] [data-v-cart-coupons] [data-v-cart-coupon]++@coupon|deleteAllButFirstChild+@coupon|before = <?php++$coupons = $this->cart['coupons'];+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;+$coupons = empty($coupons) ? $_default : $coupons;++if(is_array($coupons)) foreach ($coupons as $index => $coupon) {+?>++ //catch all data attributes+ @coupon [data-v-cart-coupon-*]|innerText = $coupon['@@__data-v-cart-coupon-(*)__@@']+ @coupon a[data-v-cart-coupon-*]|href = $coupon['@@__data-v-cart-coupon-(*)__@@']+ @coupon input[data-v-cart-coupon-*]|value = $coupon['@@__data-v-cart-coupon-(*)__@@']++@coupon|after = <?php }?>diff --git a/app/template/components/cart.tpl b/app/template/components/cart.tplindex 9f36c14..9bbddbd 100755--- a/app/template/components/cart.tpl+++ b/app/template/components/cart.tpl@@ -23,7 +23,7 @@ $_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['produ$products = empty($products) ? $_default : $products;if($products) {- foreach ($products as $index => $product) { ?>+ foreach ($products as $key => $product) { ?>//@cart-product [data-v-product-name] = $product['name']//@cart-product [data-v-product-price] = $product['price']@@ -38,6 +38,7 @@ if($products) {<?php echo htmlentities(Vvveb\url(['module' => 'cart', 'action' => 'remove', 'product_id' => $product['product_id']]));?>@cart-product|data-product_id = $product['product_id']+ @cart-product|data-key = $key@cart-product [data-v-cart-product-image]|src = $product['image']@@ -46,6 +47,26 @@ if($products) {}?>++@cart-option = [data-v-component-cart] [data-v-cart-product] [data-v-product-option]+@cart-option|deleteAllButFirstChild+++@cart-option|before = <?php+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_option_value_id' => 1]] : false;+$option_value = empty($product['option_value']) ? $_default : $product['option_value'];++if($option_value) {+ foreach ($option_value as $product_option_value_id => $value) { ?>++ @cart-option [data-v-product-option-*]|innerText = $value['@@__data-v-product-option-(*)__@@']+++@cart-option|after = <?php }+}+?>++@total = [data-v-component-cart] [data-v-cart-totals] [data-v-cart-total]@total|deleteAllButFirstChild@@ -64,3 +85,23 @@ if(is_array($totals)) foreach ($totals as $index => $total) {@total input[data-v-cart-total-*]|value = $total['@@__data-v-cart-total-(*)__@@']@total|after = <?php }?>+++@coupon = [data-v-component-cart] [data-v-cart-coupons] [data-v-cart-coupon]++@coupon|deleteAllButFirstChild+@coupon|before = <?php++$coupons = $cart['coupons'] ?? [];+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;+$coupons = empty($coupons) ? $_default : $coupons;++if(is_array($coupons)) foreach ($coupons as $index => $coupon) {+?>++ //catch all data attributes+ @coupon [data-v-cart-coupon-*]|innerText = $coupon['@@__data-v-cart-coupon-(*)__@@']+ @coupon a[data-v-cart-coupon-*]|href = $coupon['@@__data-v-cart-coupon-(*)__@@']+ @coupon input[data-v-cart-coupon-*]|value = $coupon['@@__data-v-cart-coupon-(*)__@@']++@coupon|after = <?php }?>\ No newline at end of filediff --git a/app/template/components/reviews.tpl b/app/template/components/reviews.tplindex 1f4af84..0fa1ac5 100755--- a/app/template/components/reviews.tpl+++ b/app/template/components/reviews.tpl@@ -1,15 +1,17 @@@reviews = [data-v-component-reviews]@review = [data-v-component-reviews] [data-v-review]+@reviews [data-v-reviews-*] = $product_review['@@__data-v-reviews-(*)__@@']+@review|deleteAllButFirstChild@reviews|prepend = <?phpif (isset($_reviews_idx)) $_reviews_idx++; else $_reviews_idx = 0;$previous_component = isset($current_component)?$current_component:null;-$component_reviews = $current_component = $this->_component['reviews'][$_reviews_idx] ?? [];-$reviews = $component_reviews['product_review'] ?? [];+$product_review = $current_component = $this->_component['reviews'][$_reviews_idx] ?? [];+$reviews = $product_review['product_review'] ?? [];-$_pagination_count = $reviews['count'] ?? 0;+$_pagination_count = $count = $current_component['count'] ?? 0;$_pagination_limit = isset($reviews['limit']) ? $reviews['limit'] : 5;?>@@ -42,11 +44,26 @@ if($reviews && is_array($reviews)) {?>+@reviews [data-v-summary-five] = <?php echo $product_review['summary'][5]['count'];?>+@reviews [data-v-summary-four] = <?php echo $product_review['summary'][4]['count'];?>+@reviews [data-v-summary-three] = <?php echo $product_review['summary'][3]['count'];?>+@reviews [data-v-summary-two] = <?php echo $product_review['summary'][2]['count'];?>+@reviews [data-v-summary-one] = <?php echo $product_review['summary'][1]['count'];?>+++@reviews [data-v-summary-five-width]|style = <?php echo 'width:' . $product_review['summary'][5]['percent'] .'%';?>+@reviews [data-v-summary-four-width]|style = <?php echo 'width:' . $product_review['summary'][4]['percent'] .'%';?>+@reviews [data-v-summary-three-width]|style = <?php echo 'width:' . $product_review['summary'][3]['percent'] .'%';?>+@reviews [data-v-summary-two-width]|style = <?php echo 'width:' . $product_review['summary'][2]['percent'] .'%';?>+@reviews [data-v-summary-one-width]|style = <?php echo 'width:' . $product_review['summary'][1]['percent'] .'%';?>+++@images = [data-v-component-reviews] [data-v-image]@images|deleteAllButFirstChild@images|before = <?php-$_images = $component_reviews['images'] ?? [];+$_images = $product_review['images'] ?? [];$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_review_media_id' => 0, 'image' => '']] : false;$_images = empty($_images) ? $_default : $_images;diff --git a/app/template/user/return-form.tpl b/app/template/user/return-form.tplnew file mode 100755index 0000000..4279af2--- /dev/null+++ b/app/template/user/return-form.tpl@@ -0,0 +1,26 @@+//keep post values+input|value = <?php if (isset($_POST['@@__name__@@'])) echo $_POST['@@__name__@@']; else echo '@@__value__@@';?>++import(common.tpl)++[data-v-return] select[data-v-return-*]|before =+<?php+ $name = '@@__data-v-return-(*)__@@';+ $selected = '';+ if (isset($this->return[$name]))+ $selected = $this->return[$name];+?>++@reason = [data-v-return_reason] [data-v-option]+[data-v-return_reason] [data-v-option]|deleteAllButFirstChild+[data-v-return_reason] [data-v-option]|before = <?php+ if (isset($this->return_reason_id))+ foreach ($this->return_reason_id as $value => $text) {+ ?>++ @reason|value = $value+ // @reason|addNewAttribute = <?php if ($value == $selected) echo 'selected';?>+ @reason span = <?php if (is_array($text)) { if (isset($text['name'])) echo Vvveb\humanReadable($text['name']);} else echo $text;?>++@reason|after = <?php+} ?>diff --git a/config/routes.php b/config/routes.phpindex 3c02af6..fae67dc 100755--- a/config/routes.php+++ b/config/routes.php@@ -42,6 +42,7 @@ return ['/user/downloads' => ['module' => 'user/downloads/index'],'/user/downloads/#page#' => ['module' => 'user/downloads/index'],'/user/downloads/#download_id#' => ['module' => 'user/downloads/download'],+ '/user/return-form' => ['module' => 'user/return-form'],'/user/address' => ['module' => 'user/address/index'],'/user/address/edit' => ['module' => 'user/address/edit'],'/user/address/edit/#user_address_id#' => ['module' => 'user/address/edit'],diff --git a/install/sql/insert/post/post_content.sql b/install/sql/insert/post/post_content.sqlindex e9f44c7..fdc90e4 100755--- a/install/sql/insert/post/post_content.sql+++ b/install/sql/insert/post/post_content.sql@@ -190,19 +190,19 @@ INSERT INTO `post_content` VALUES(10,1,'Privacy policy','privacy-policy','Privacy Policy', '','',''),(11,1,'About','about','-<div class="my-5 text-center"><img src="../../media/biglogo.png"></div>+<div class="my-5"><img src="../../media/biglogo.png"></div><hr class="my-5 border">-<p class="lead fw-normal">Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores.</p>-<p class="lead fw-normal">The html for sections blocks and components and this template are built using Bootstrap 5.</p>+<p>Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores.</p>+<p>The html for sections blocks and components and this template are built using Bootstrap 5.</p><hr class="my-5 border">-<h5>Better Security</h5>-<p class="lead fw-normal">Vvveb is 100% safe against sql injections, a vulerability that affects most CMS.</p>-<h5>Unlimited customization</h5>-<p class="lead fw-normal">Vvveb uses only html for templating for maximum flexibility.</p>-<h5>Advanced Ecommerce</h5>-<p class="lead fw-normal">Vvveb is a full featured ecommerce platform with advanced functionality.</p>-<h5>Full Localization</h5>-<p class="lead fw-normal">Publish content in multiple languages or sell in different currencies.</p>+<h6>Better Security</h6>+<p>Vvveb is 100% safe against sql injections, a vulerability that affects most CMS.</p>+<h6>Unlimited customization</h6>+<p>Vvveb uses only html for templating for maximum flexibility.</p>+<h6>Advanced Ecommerce</h6>+<p>Vvveb is a full featured ecommerce platform with advanced functionality.</p>+<h6>Full Localization</h6>+<p>Publish content in multiple languages or sell in different currencies.</p>', '','',''),(12,1,'Services','services','Services', '','',''),(13,1,'Pricing','pricing','Pricing', '','',''),@@ -264,17 +264,17 @@ INSERT INTO `post_content` VALUES(11,2,'Despre','despre','<div class="my-5 text-center"><img src="../../media/biglogo.png"></div><hr class="my-5 border">-<p class="lead fw-normal">Unealta puternica si usor de folosit pentru a realiza blog-uri, site-uri de prezentare sau magazine online.</p>-<p class="lead fw-normal">The html for sections blocks and components and this template are built using Bootstrap 5.</p>+<p>Unealta puternica si usor de folosit pentru a realiza blog-uri, site-uri de prezentare sau magazine online.</p>+<p>The html for sections blocks and components and this template are built using Bootstrap 5.</p><hr class="my-5 border">-<h5>Better Security</h5>-<p class="lead fw-normal">Vvveb is 100% safe against sql injections, a vulerability that affects most CMS.</p>-<h5>Unlimited customization</h5>-<p class="lead fw-normal">Vvveb uses only html for templating for maximum flexibility.</p>-<h5>Advanced Ecommerce</h5>-<p class="lead fw-normal">Vvveb is a full featured ecommerce platform with advanced functionality.</p>-<h5>Full Localization</h5>-<p class="lead fw-normal">Publish content in multiple languages or sell in different currencies.</p>+<h6>Better Security</h6>+<p>Vvveb is 100% safe against sql injections, a vulerability that affects most CMS.</p>+<h6>Unlimited customization</h6>+<p>Vvveb uses only html for templating for maximum flexibility.</p>+<h6>Advanced Ecommerce</h6>+<p>Vvveb is a full featured ecommerce platform with advanced functionality.</p>+<h6>Full Localization</h6>+<p>Publish content in multiple languages or sell in different currencies.</p>', '','',''),(12,2,'Servicii','servicii','Servicii', '','',''),(13,2,'Preturi','preturi','Preturi', '','',''),diff --git a/install/sql/mysqli/schema/product/product_question.sql b/install/sql/mysqli/schema/product/product_question.sqlindex e395d31..943d921 100755--- a/install/sql/mysqli/schema/product/product_question.sql+++ b/install/sql/mysqli/schema/product/product_question.sql@@ -3,7 +3,7 @@ DROP TABLE IF EXISTS `product_question`;CREATE TABLE `product_question` (`product_question_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,`product_id` INT UNSIGNED NOT NULL,- `user_id` INT UNSIGNED NOT NULL,+ `user_id` INT UNSIGNED NOT NULL DEFAULT '0',`author` varchar(64) NOT NULL,`content` text NOT NULL,`status` tinyint UNSIGNED NOT NULL DEFAULT '0',diff --git a/install/sql/mysqli/schema/product/product_review.sql b/install/sql/mysqli/schema/product/product_review.sqlindex 8f5303a..217214f 100755--- a/install/sql/mysqli/schema/product/product_review.sql+++ b/install/sql/mysqli/schema/product/product_review.sql@@ -3,7 +3,7 @@ DROP TABLE IF EXISTS `product_review`;CREATE TABLE `product_review` (`product_review_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,`product_id` INT UNSIGNED NOT NULL,- `user_id` INT UNSIGNED NOT NULL,+ `user_id` INT UNSIGNED NOT NULL DEFAULT '0',`author` varchar(64) NOT NULL,`content` text NOT NULL,`rating` tinyint UNSIGNED NOT NULL,diff --git a/install/sql/sqlite/schema/product/product_question.sql b/install/sql/sqlite/schema/product/product_question.sqlindex b47a0e3..7a2d42c 100755--- a/install/sql/sqlite/schema/product/product_question.sql+++ b/install/sql/sqlite/schema/product/product_question.sql@@ -3,16 +3,16 @@ DROP TABLE IF EXISTS `product_question`;CREATE TABLE `product_question` (`product_question_id` INTEGER PRIMARY KEY AUTOINCREMENT,`product_id` INT NOT NULL,-`user_id` INT NOT NULL,+`user_id` INT NOT NULL DEFAULT '0',`author` TEXT NOT NULL,`content` text NOT NULL,`status` TINYINT NOT NULL DEFAULT '0',`parent_id` INT NOT NULL DEFAULT '0',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,-`updated_at` datetime NOT NULL+`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP-- PRIMARY KEY (`product_question_id`));-CREATE INDEX `product_question_product_id` ON `product_question` (`product_id`);+CREATE INDEX `product_question_product_id` ON `product_question` (`product_id`, `user_id`, `status`);diff --git a/install/sql/sqlite/schema/product/product_review.sql b/install/sql/sqlite/schema/product/product_review.sqlindex 289a5df..170d640 100755--- a/install/sql/sqlite/schema/product/product_review.sql+++ b/install/sql/sqlite/schema/product/product_review.sql@@ -3,14 +3,14 @@ DROP TABLE IF EXISTS `product_review`;CREATE TABLE `product_review` (`product_review_id` INTEGER PRIMARY KEY AUTOINCREMENT,`product_id` INT NOT NULL,-`user_id` INT NOT NULL,+`user_id` INT NOT NULL DEFAULT '0',`author` TEXT NOT NULL,`content` text NOT NULL,`rating` SMALLINTEGER NOT NULL,`status` TINYINT NOT NULL DEFAULT '0',`parent_id` INT NOT NULL DEFAULT '0',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,-`updated_at` datetime NOT NULL+`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP-- PRIMARY KEY (`product_review_id`));diff --git a/public/js/app.js b/public/js/app.jsindex 6a7bc74..067f93b 100755--- a/public/js/app.js+++ b/public/js/app.js@@ -32,15 +32,27 @@ VvvebTheme.Ajax = {data: parameters,//dataType: 'json',beforeSend: function() {- $('.loading', element).removeClass('d-none');- $('.button-text', element).addClass('d-none');+ let loading = $('.loading', element);+ let btn = $('.button-text', element);++ if (loading.hasClass("d-none")) {+ loading.removeClass('d-none');+ btn.addClass('d-none');+ }+if ($(element).is('button')) {$(element).attr("disabled", "true");}},complete: function() {- $('.loading', element).addClass('d-none');- $('.button-text', element).removeClass('d-none');+ let loading = $('.loading', element);+ let btn = $('.button-text', element);++ if (btn.hasClass("d-none")) {+ loading.addClass('d-none');+ btn.removeClass('d-none');+ }+if ($(element).is('button')) {$(element).removeAttr("disabled");}@@ -49,7 +61,7 @@ VvvebTheme.Ajax = {success: function(data) {//$("header [data-v-component-cart]")[0].outerHTML = data;if (selector) {- let response = $(data);+ let response = $(data);//new DOMParser().parseFromString(data, "text/html");if (Array.isArray (selector) ) {for (k in selector) {let elementSelector = selector[k];@@ -79,10 +91,10 @@ VvvebTheme.Cart = {component_id: '0',ajax: function(action, parameters, element, selector, callback) {- parameters['module'] = this.module;- parameters['action'] = action;- parameters['component'] = this.component;- parameters['component_id'] = this.component_id;+ parameters['module'] = parameters['module'] ?? this.module;+ parameters['action'] = parameters['action']?? action;+ parameters['component'] = parameters['component'] ?? this.component;+ parameters['component_id'] = parameters['component_id'] ?? this.component_id;VvvebTheme.Ajax.call(parameters, element, selector, callback);},@@ -104,19 +116,29 @@ VvvebTheme.Cart = {return this.ajax('add',options, element, selector, callback);},- update: function(productId, options, element, selector, callback = false) {+ update: function(key, options, element, selector, callback = false) {if (!callback) callback = this.callback;if (options) {- options['product_id'] = productId;+ options['key'] = key;} else {- options = {'product_id':productId};+ options = {'key':key};}return this.ajax('update',options, element, selector, callback);},- remove: function(productId, element, selector, callback = false) {+ remove: function(key, element, selector, callback = false) {if (!callback) callback = this.callback;- return this.ajax('remove', {'product_id':productId}, element, selector, callback);+ return this.ajax('remove', {'key':key}, element, selector, callback);+ },++ coupon: function(options, element, selector, callback = false) {+ if (!callback) callback = this.callback;+ return this.ajax('coupon', options, element, selector, callback);+ },++ removeCoupon: function(options, element, selector, callback = false) {+ if (!callback) callback = this.callback;+ return this.ajax('removeCoupon', options, element, selector, callback);}}@@ -164,8 +186,8 @@ VvvebTheme.Comments = {module: 'content/post',ajax: function(action, parameters, element, selector, callback = false) {- parameters['module'] = this.module;- parameters['action'] = action;+ parameters['module'] = parameters['module'] ?? this.module;+ parameters['action'] = parameters['action'] ?? action;VvvebTheme.Ajax.call(parameters, element, selector, callback);},@@ -368,7 +390,7 @@ VvvebTheme.Gui = {addToCompare : function (e) {return false;},-+replyTo : function (e) {let commentId = this.dataset.comment_id;@@ -406,6 +428,36 @@ VvvebTheme.Gui = {},+ addReview : function (e) {+ let selector = this.dataset.selector ?? ".product-reviews";+ let form = this;+ let parameters = $(form).serializeArray();+ parameters['module'] = 'product/product';+ parameters['action'] = 'addReview';++ VvvebTheme.Comments.add(parameters, this, selector, function () {+ form.reset();+ });++ e.preventDefault();++ },++ addQuestion : function (e) {+ let selector = this.dataset.selector ?? ".product-questions";+ let form = this;+ let parameters = $(form).serializeArray();+ parameters['module'] = 'product/product';+ parameters['action'] = 'addQuestion';++ VvvebTheme.Comments.add(parameters, this, selector, function () {+ form.reset();+ });++ e.preventDefault();++ },+search : function (e) {clearTimeout(window.searchDebounce);diff --git a/public/js/vvvebjs/components/ecommerce/checkout.js b/public/js/vvvebjs/components/ecommerce/checkout.jsindex 59b3f61..bfa15c8 100755--- a/public/js/vvvebjs/components/ecommerce/checkout.js+++ b/public/js/vvvebjs/components/ecommerce/checkout.js@@ -29,17 +29,17 @@<div class="card-body"><div class="row " data-v-if-not="this.global.user_id">- <div class="mb-3 col-6" id="first_name_group">+ <div class="mb-3 col-6"><label class="col-form-label" for="first_name">First Name <span class="text-danger text-small">*</span></label><input type="text" class="form-control" id="first_name" name="first_name" value="" minlength="3" required=""></div>- <div class="mb-3 col-6" id="last_name_group">+ <div class="mb-3 col-6"><label class="col-form-label" for="last_name">Last Name <span class="text-danger text-small">*</span></label><input type="text" class="form-control" id="last_name" name="last_name" value="" minlength="3" required=""></div>- <div class="mb-3 col-12 mb-3" id="email_group">+ <div class="mb-3 col-12 mb-3"><label class="col-form-label" for="email">Email Address <span class="text-danger text-small">*</span></label><input type="email" class="form-control" id="email" name="email" value="" required="">@@ -85,7 +85,7 @@<div class="row">- <div class="mb-3 col-12 mb-3" id="company_group">+ <div class="mb-3 col-12 mb-3"><label class="col-form-label" for="billing_company">Company Name</label><input type="text" class="form-control" id="billing_company" name="billing_address[company]" value=""></div>@@ -140,22 +140,22 @@ Ship To A Different Address </label><h5>Shipping Address</h5><div class="row">- <div class="mb-3 col-6" id="first_name_group">+ <div class="mb-3 col-6"><label class="col-form-label" for="first_name">First Name <span class="text-danger text-small">*</span></label><input type="text" class="form-control" id="first_name" name="shipping_address[first_name]" value="" minlength="3" required="" disabled=""></div>- <div class="mb-3 col-6" id="last_name_group">+ <div class="mb-3 col-6"><label class="col-form-label" for="last_name">Last Name <span class="text-danger text-small">*</span></label><input type="text" class="form-control" id="last_name" name="shipping_address[last_name]" value="" minlength="3" required="" disabled=""></div>- <div class="mb-3 col-12 mb-3" id="email_group">+ <div class="mb-3 col-12 mb-3"><label class="col-form-label" for="email">Email Address <span class="text-danger text-small">*</span></label><input type="email" class="form-control" id="email" name="shipping_address[email]" value="" required="" disabled=""></div>- <div class="mb-3 col-12 mb-3" id="company_group">+ <div class="mb-3 col-12 mb-3"><label class="col-form-label" for="company">Company Name</label><input type="text" class="form-control" id="company" name="shipping_address[company]" value="" disabled=""></div>diff --git a/system/cart/cart.php b/system/cart/cart.phpindex 49895ea..97844fe 100755--- a/system/cart/cart.php+++ b/system/cart/cart.php@@ -23,6 +23,8 @@namespace Vvveb\System\Cart;use function \Vvveb\url;+use Vvveb\Sql\Product_Option_ValueSQL;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Images;use Vvveb\System\Session;@@ -49,6 +51,8 @@ class Cart {protected $total_items = 0;+ use TaxTrait, ProductOptionTrait, CouponTrait;+public static function getInstance($options = []) {static $inst = null;@@ -87,71 +91,113 @@ class Cart {$results = ['products' => [], 'count' => 0];if (! empty($this->products)) {- $productIds = array_keys($this->products);+ $productIds = [];+ $productOptions = [];+ $productSubscriptions = [];+ foreach ($this->products as $product) {+ $productId = $product['product_id'];+ $productIds[$productId] = $productId;++ //get all product options to make one query to get all option values+ if (isset($product['option'])) {+ foreach ($product['option'] as $value) {+ if (is_numeric($value)) {+ $productOptions[$value] = $value;+ }+ }+ }++ if (isset($product['subscription_plan_id'])) {+ $productSubscriptions[$productId] = $product['subscription_plan_id'];+ }+ }++ //get product data from db for products in cart$options = ['product_id' => $productIds,- 'start' => 0,- 'include_image_gallery' => true,] + $this->options;- $productSql = new \Vvveb\Sql\ProductSQL();+ $productSql = new ProductSQL();$results = $productSql->getAll($options);- }- $products = $this->products;- $this->products = [];+ // if products have options get all product options in one query+ $optionResults = [];+ if ($productOptions) {+ $productOptionValueSql = new Product_Option_ValueSQL();+ $optionResults = $productOptionValueSql->getAll(+ ['product_option_value_id' => array_values($productOptions)] + $this->options+ )['product_option_value'] ?? [];+ }+ }- foreach ($results['products'] as $id => &$product) {- $productId = $product['product_id'];+ $products = $results['products'] ?? [];- if (isset($product['images'])) {- $product['images'] = json_decode($product['images'], true);+ if ($products) {+ foreach ($this->products as $key => &$prod) {+ if (! isset($products[$product['product_id']])) {+ unset($this->products[$key]);- foreach ($product['images'] as &$image) {- $image['image'] = Images::image($image['image'], 'product', 'thumb');+ continue;}- }- if (isset($product['image'])) {- $product['image'] = Images::image($product['image'], 'product', 'thumb');- }+ $productId = $prod['product_id'];+ $product = $products[$productId];++ $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 ($value['price']) {+ if ($value['price_operator'] == '-') {+ $prod['price'] -= $value['price'];+ } else {+ $prod['price'] += $value['price'];+ }+ }+ }+ }- $product['url'] = htmlentities(url('product/product/index', $product));- $product['remove-url'] = htmlentities(url('cart/cart/remove', $product));+ $prod['url'] = htmlentities(url('product/product/index', $product));+ $prod['remove-url'] = htmlentities(url('cart/cart/remove', $product));- $product['quantity'] = $products[$productId]['quantity'] ?? 1;- $product['option'] = $products[$productId]['option'] ?? [];- $product['total'] = (int)$product['price'] * $product['quantity'];- $product['total_formatted'] = $this->currency->format($product['total']);+ $prod['total'] = (int)$prod['price'] * $prod['quantity'];+ $prod['total_formatted'] = $this->currency->format($prod['total']);- $taxValue = $this->tax->addTaxes($product['price'], $product['tax_type_id'], true);- $product['price_tax'] = ($taxValue + $product['price']);- $product['tax'] = $product['price_tax'] * $product['quantity'];- $product['total_tax'] = $product['tax'];+ $taxValue = $this->tax->addTaxes($prod['price'], $product['tax_type_id'], true);+ $prod['price_tax'] = ($taxValue + $prod['price']);+ $prod['tax'] = $prod['price_tax'] * $prod['quantity'];+ $prod['total_tax'] = $prod['tax'];- $product['price_tax_formatted'] = $this->currency->format($product['price_tax']);- $product['price_formatted'] = $this->currency->format($product['price']);- $product['total_formatted'] = $this->currency->format($product['total']);- $product['total_tax_formatted'] = $this->currency->format($product['total_tax']);+ $prod['price_tax_formatted'] = $this->currency->format($prod['price_tax']);+ $prod['price_formatted'] = $this->currency->format($product['price']);+ $prod['total_formatted'] = $this->currency->format($prod['total']);+ $prod['total_tax_formatted'] = $this->currency->format($prod['total_tax']);- if (isset($products[$productId]['subscription_plan_id'])) {- $product['subscription_plan_id'] = $products[$productId]['subscription_plan_id'];- }+ if (isset($products[$productId]['subscription_plan_id'])) {+ //$prod['subscription_plan_id'] = $products[$productId]['subscription_plan_id'];+ }- $this->total += $product['total'];- $this->total_tax += $product['total_tax'];- $this->total_items += $product['quantity'];+ $this->total += $prod['total'];+ $this->total_tax += $prod['total_tax'];+ $this->total_items += $prod['quantity'];- if (isset($this->products[$productId])) {- $product = array_merge($this->products[$productId], $product);- }+ $prod = array_merge($prod, $product);+++ if (isset($product['image'])) {+ $prod['image'] = Images::image($product['image'], 'product', 'thumb');+ }- // options add to price+ // options add to price- $this->products[$productId] = $product;+ }}$this->addTotal('sub_total', 'Sub-total', $this->total);@@ -166,10 +212,23 @@ class Cart {return false;}- if (isset($this->products[$productId])) {- $this->products[$productId]['quantity'] += $quantity;+ $key = $productId;++ if ($option) {+ $key .= '_' . json_encode($option);+ }++ if ($subscriptionPlanId) {+ $key .= "_$subscriptionPlanId";+ }++ $key = str_replace('"', '', $key);++ if (isset($this->products[$key])) {+ $this->products[$key]['quantity'] += $quantity;} else {- $this->products[$productId] = [+ $this->products[$key] = [+ 'product_id' => $productId,'quantity' => $quantity,'option' => $option,'subscription_plan_id' => $subscriptionPlanId,@@ -179,16 +238,16 @@ class Cart {return $this->updateCart();}- function update($productId, $quantity = 1, $option = [], $subscriptionPlanId = false) {- if (isset($this->products[$productId])) {- $this->products[$productId]['quantity'] = max(1, $quantity);-+ function update($key, $quantity = 1, $option = [], $subscriptionPlanId = false) {+ if (isset($this->products[$key])) {+ $this->products[$key]['quantity'] = max(1, $quantity);+if ($option) {- $this->products[$productId]['option'] = $option;+ $this->products[$key]['option'] = $option;}if ($subscriptionPlanId) {- $this->products[$productId]['subscription_plan_id'] = $subscriptionPlanId;+ $this->products[$key]['subscription_plan_id'] = $subscriptionPlanId;}return $this->updateCart();@@ -203,8 +262,8 @@ class Cart {return count($this->products ?? []);}- function remove($productId) {- unset($this->products[$productId]);+ function remove($key) {+ unset($this->products[$key]);return $this->updateCart();}@@ -261,46 +320,6 @@ class Cart {return $this->currency->format($sum);}- public function addTax($name, $price, $taxTypeId) {- if ($price && $taxTypeId) {- $this->taxes[$name] = ['price' => $price, 'tax_type_id' => $taxTypeId];- }- }-- public function removeTax($name) {- unset($this->taxes[$name]);- }-- public function getTaxes() {- $taxes = [];- $products = $this->products + $this->taxes;-- foreach ($products as $product) {- if ($product['tax_type_id']) {- $tax_rates = $this->tax->getRates($product['price'], $product['tax_type_id']);-- foreach ($tax_rates as $tax_rate) {- if (! isset($taxes[$tax_rate['tax_rate_id']])) {- $taxes[$tax_rate['tax_rate_id']] = $tax_rate;- $taxes[$tax_rate['tax_rate_id']]['value'] = 0;- }-- $taxes[$tax_rate['tax_rate_id']]['value'] += ($tax_rate['amount'] * ($product['quantity'] ?? 1));- }- }- }-- return $taxes;- }-- function addTaxTotal() {- $taxes = $this->getTaxes();-- foreach ($taxes as $tax) {- $this->addTotal('tax.' . $tax['tax_rate_id'], $tax['name'], $tax['value']);- }- }-function addTotal($key, $title, $value, $text = '') {$data = ['key' => $key, 'title' => $title, 'value' => $value, 'value_formatted' => $this->currency->format($value), 'text' => $text];@@ -392,7 +411,7 @@ class Cart {protected function write() {//$data = get_object_vars($this);- foreach (['products', 'taxes', 'totals', 'total_items'] as $property) {+ foreach (['products', 'taxes', 'totals', 'total_items', 'coupons', 'product_options'] as $property) {$data[$property] = $this->$property;}diff --git a/system/cart/coupon-trait.php b/system/cart/coupon-trait.phpnew file mode 100644index 0000000..b1b00e3--- /dev/null+++ b/system/cart/coupon-trait.php@@ -0,0 +1,63 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\System\Cart;++use Vvveb\Sql\couponSQL;++trait CouponTrait {+ protected $coupons = [];++ public function addCoupon($code) {+ if ($code) {+ $coupon = new couponSQL();+ $options = $this->options + ['code' => $code, 'status' => 1];+ $result = $coupon->get($options);++ if ($result && $result['code'] == $code) {+ $this->coupons[$code] = $result;++ return true;+ }+ }++ return false;+ }++ public function removeCoupon($code) {+ unset($this->coupons[$code]);++ return true;+ }++ public function getCoupons() {+ return $this->coupons;+ }++ function addCouponTotal() {+ $coupons = $this->getCoupons();++ foreach ($coupons as $coupon) {+ $this->addTotal('coupon.' . $coupon['coupon_rate_id'], $coupon['name'], $coupon['value']);+ }+ }+}diff --git a/system/cart/product-option-trait.php b/system/cart/product-option-trait.phpnew file mode 100644index 0000000..aff197a--- /dev/null+++ b/system/cart/product-option-trait.php@@ -0,0 +1,67 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\System\Cart;++trait ProductOptionTrait {+ protected $product_options = [];++ public function addProductOption($name, $price, $product_optionTypeId) {+ if ($price && $product_optionTypeId) {+ $this->product_options[$name] = ['price' => $price, 'product_option_type_id' => $product_optionTypeId];+ }+ }++ public function removeProductOption($name) {+ unset($this->product_options[$name]);+ }++ public function getProductOptions() {+ $product_options = [];+ $products = $this->products + $this->product_options;++ foreach ($products as $product) {+ if ($product['product_option_type_id']) {+ $product_option_rates = $this->product_option->getRates($product['price'], $product['product_option_type_id']);++ foreach ($product_option_rates as $product_option_rate) {+ if (! isset($product_options[$product_option_rate['product_option_rate_id']])) {+ $product_options[$product_option_rate['product_option_rate_id']] = $product_option_rate;+ $product_options[$product_option_rate['product_option_rate_id']]['value'] = 0;+ }++ $product_options[$product_option_rate['product_option_rate_id']]['value'] += ($product_option_rate['amount'] * ($product['quantity'] ?? 1));+ }+ }+ }++ return $product_options;+ }++ function addProductOptionTotal() {+ $product_options = $this->getProductOptions();++ foreach ($product_options as $product_option) {+ $this->addTotal('product_option.' . $product_option['product_option_rate_id'], $product_option['name'], $product_option['value']);+ }+ }+}diff --git a/system/cart/tax-trait.php b/system/cart/tax-trait.phpnew file mode 100644index 0000000..36999d7--- /dev/null+++ b/system/cart/tax-trait.php@@ -0,0 +1,65 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\System\Cart;++trait TaxTrait {+ public function addTax($name, $price, $taxTypeId) {+ if ($price && $taxTypeId) {+ $this->taxes[$name] = ['price' => $price, 'tax_type_id' => $taxTypeId];+ }+ }++ public function removeTax($name) {+ unset($this->taxes[$name]);+ }++ public function getTaxes() {+ $taxes = [];+ $products = $this->products + $this->taxes;++ foreach ($products as $product) {+ if ($product['tax_type_id']) {+ $tax_rates = $this->tax->getRates($product['price'], $product['tax_type_id']);++ foreach ($tax_rates as $tax_rate) {+ if (! isset($taxes[$tax_rate['tax_rate_id']])) {+ $taxes[$tax_rate['tax_rate_id']] = $tax_rate;+ $taxes[$tax_rate['tax_rate_id']]['value'] = 0;+ }++ $taxes[$tax_rate['tax_rate_id']]['value'] += ($tax_rate['amount'] * ($product['quantity'] ?? 1));+ }+ }+ }++ return $taxes;+ }++ function addTaxTotal() {+ $taxes = $this->getTaxes();++ foreach ($taxes as $tax) {+ $this->addTotal('tax.' . $tax['tax_rate_id'], $tax['name'], $tax['value']);+ }+ }+}diff --git a/system/db.php b/system/db.phpindex 4dd465b..ed1a920 100755--- a/system/db.php+++ b/system/db.php@@ -26,7 +26,9 @@ class Db {public static function getInstance($engine = DB_ENGINE) {static $inst = [];- if (!$engine) return;+ if (! $engine) {+ return;+ }if (! isset($inst[$engine]) || $inst[$engine] === null) {$driverName = "\Vvveb\System\Db\\$engine";diff --git a/system/extensions/extensions.php b/system/extensions/extensions.phpindex d9a479a..fc93ade 100755--- a/system/extensions/extensions.php+++ b/system/extensions/extensions.php@@ -151,13 +151,13 @@ abstract class Extensions {//check if first entry is a directoryif (substr($folderName, -1, 1) != '/') {if ($validate) {- throw new \Exception(sprintf('%s zip must have only %s folder!', $extensionZipFile, $extension));+ throw new \Exception(sprintf('%s zip must have only %s folder!', $extensionZipFile, ucfirst($extension)));}} else {$slug = trim($folderName, '/');}- for ($i = $zip->numFiles; ($i > 0 && $success == true); $i--) {+ for ($i = $zip->numFiles - 1; ($i > 0 && $success == true); $i--) {$file = $zip->getNameIndex($i);if ($validate) {@@ -171,11 +171,12 @@ abstract class Extensions {}}- if (strpos($file, $fileCheck) !== false) {+ // plugin.php must be in the top most folder+ if (strpos($file, $fileCheck) !== false && substr_count($file, '/') < 2) {$content = $zip->getFromName($file);$info = static::getInfo($content);- if ($folderName == ($info['slug'] . '/')) {+ if (isset($info['slug']) && ($folderName == ($info['slug'] . '/'))) {// Unzip Pathif ($zip->extractTo($extractTo)) {$success = $info['slug'];@@ -184,7 +185,7 @@ abstract class Extensions {}} else {if ($validate) {- throw new \Exception(sprintf(__('%s slug `%s` does not match folder %s!'), $extension, $info['slug'], $folderName));+ throw new \Exception(sprintf(__('%s slug `%s` does not match folder %s!'), $extension, $info['slug'] ?? '', $folderName));} else {if ($zip->extractTo($extractTo . DS . $slug)) {$info = ['slug' => $slug];@@ -236,7 +237,7 @@ abstract class Extensions {if ($content) {$rss = new Rss($content);- $result[static :: $extension . 's'] = $rss->get(1, 10);+ $result[static :: $extension . 's'] = $rss->get($params['start'] ?? 1, $params['limit'] ?? 10);$result['count'] = $rss->value('count');return $result;diff --git a/system/extensions/plugins.php b/system/extensions/plugins.phpindex e8fc544..4d68da1 100755--- a/system/extensions/plugins.php+++ b/system/extensions/plugins.php@@ -52,7 +52,7 @@ class Plugins extends Extensions {$params = parent::getInfo($content, $name);$params['status'] = 'inactive';- if (isset($params['thumb']) &&+ if (isset($params['thumb']) &&file_exists(DIR_PUBLIC . ($file = 'plugins/' . $name . '/' . $params['thumb']))) {$params['thumb_url'] = PUBLIC_PATH . $file;} else {@@ -135,7 +135,7 @@ class Plugins extends Extensions {$pluginName = parent :: install($zipFile, $validate);self :: copyPublicDir($pluginName);- self :: clearPluginsCache($site_id);+ self :: clearPluginsCache();return $pluginName;}diff --git a/system/import/table-order.php b/system/import/table-order.phpindex 1231444..d86ac60 100755--- a/system/import/table-order.php+++ b/system/import/table-order.php@@ -40,7 +40,7 @@ return ['user_group_content','user_points','user_wishlist',-+//taxonomy'taxonomy_item','taxonomy_item_content',@@ -75,7 +75,7 @@ return ['attribute_content','attribute_group','attribute_group_content',-+//product'product','product_attribute',@@ -104,19 +104,18 @@ return ['coupon_product','currency',-- //digital_asset+ //digital_asset'digital_asset','digital_asset_content','digital_asset_log',-+'region_group','length_type','length_type_content','location','manufacturer','manufacturer_to_site',-+//order'order','order_log',diff --git a/system/setting.php b/system/setting.phpindex ed886bf..50a8af8 100755--- a/system/setting.php+++ b/system/setting.php@@ -111,7 +111,7 @@ class Setting {if ($settings) {foreach ($settings as $key => $value) {$this->setting[$namespace][$key] = $value;- $result = $this->settingSql->setSetting(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);+ $result = $this->settingSql->setSetting(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);}}diff --git a/system/sites.php b/system/sites.phpindex bbf0f4a..a3627b9 100755--- a/system/sites.php+++ b/system/sites.php@@ -286,12 +286,12 @@ class Sites {}return $result ?? [- 'host' => 'localhost',- 'theme' => 'landing',+ 'host' => 'localhost',+ 'theme' => 'landing','template' => '',- 'id' => 1,- 'state' => 'live',- ];+ 'id' => 1,+ 'state' => 'live',+ ];}public static function saveSite($site) {diff --git a/system/sqlp/sqlp.php b/system/sqlp/sqlp.phpindex 96afdd3..fee4513 100755--- a/system/sqlp/sqlp.php+++ b/system/sqlp/sqlp.php@@ -127,31 +127,34 @@ class SqlP {function removeParanthesis($query, $replace = '', $startChar = '(', $endChar = ')') {$level = 0;$start = null;- $end = 0;- for($i=0; $i<strlen($query); $i++) {+ $end = 0;++ for ($i=0; $i < strlen($query); $i++) {$char = $query[$i];-- if($char == $startChar) {- if ($start === null) $start = $i;++ if ($char == $startChar) {+ if ($start === null) {+ $start = $i;+ }$level++;+ } else {+ if ($char == $endChar) {+ $level--;+ }}- else if($char == $endChar) {- $level--;- }-- if($start && $level == 0) {- $end = $i + 1;++ if ($start && $level == 0) {+ $end = $i + 1;$query = substr_replace($query, $replace, $start, $end - $start);//reset- $i = 0;+ $i = 0;$start = null;-}- }-+ }+return $query;}-+/** Extract table name from sql statement*/