Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Notifications count added also for admin menu items for comments, reviews, questions, orders. Comment status change action renamed to save for permission convention. Stat query fix for mysql only_full_group_by. User gallery for product review. Default values added in component templates to avoid losing component html when saving in pages in page builder. Fixed SqlP getTableName subselect remove code.

givanz132395c0f93d
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..886562a
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+public/themes/** linguist-vendored
+public/admin/** linguist-vendored
+*.sql linguist-detectable=true
diff --git a/README.md b/README.md
index bd54a54..f5e96f3 100755
--- a/README.md
+++ b/README.md
@@ -55,9 +55,31 @@
* [Postgresql 11+](https://www.postgresql.org/)
+## Build
+
+* Clone the repository
+```bash
+#git 2.13+
+git clone --recurse-submodules https://github.com/givanz/Vvveb
+
+# older git versions
+git clone --recursive https://github.com/givanz/Vvveb
+```
+
+* Pull changes
+```bash
+git pull --recurse-submodules
+```
+
+* Build vvveb.zip to upload to server
+```bash
+./build.sh
+```
+
+
## Install
-* Clone the repository or download the latest [release](https://vvveb.com/download.php)
+* Clone the repository and [build](#build ) or download the latest [release](https://vvveb.com/download.php)
* Upload the files on your server or localhost and open `http://localhost/` or `http://myserver.com/`
* Follow the [installation instructions](https://docs.vvveb.com/installation)
diff --git a/admin/admin-bar.php b/admin/admin-bar.php
index c221af3..d904e55 100755
--- a/admin/admin-bar.php
+++ b/admin/admin-bar.php
@@ -183,7 +183,7 @@ if (! function_exists('printAdminBarMenu')) {
</span>
<span class="button-text text-dark">
- <i class="la la-sign-out-alt"></i><?php echo __('Log out'); ?></a>
+ <i class="la la-sign-out-alt"></i><?php echo __('Log out'); ?>
</span>
</button>
diff --git a/admin/component/notifications.php b/admin/component/notifications.php
old mode 100755
new mode 100644
index 7e957dd..5a9a77d
--- a/admin/component/notifications.php
+++ b/admin/component/notifications.php
@@ -28,59 +28,32 @@ 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\Update;
class Notifications extends ComponentBase {
public static $defaultOptions = [
- 'start' => 0,
- 'limit' => 10,
];
public $options = [];
+ private $stats;
+ private $count = 0;
+ private $notifications = [];
+ private $menu = [];
- function results() {
- // return [];
- $cache = Cache::getInstance();
-
- $notifications = [
- 'updates' => [
- 'core' => ['hasUpdate' => 1, 'version' => '1.0'],
- ],
- 'orders' => [
- 'processing' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-primary-subtle text-body'],
- 'complete' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-primary-subtle text-body'],
- 'processed' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-primary-subtle text-body'],
- ],
- 'users' => [
- 'month' => ['count' => 0, 'icon' => 'icon-person-outline', 'badge' => 'bg-secondary-subtle text-body'],
- 'year' => ['count' => 0, 'icon' => 'icon-person-outline', 'badge' => 'bg-secondary-subtle text-body'],
- ],
- 'products' => [
- ],
- 'comments' => [
- 'pending' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'approved' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'spam' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'trash' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- ],
- 'reviews' => [
- 'pending' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'approved' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'spam' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- 'trash' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
- ],
- 'questions' => [
- 'pending' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
- 'approved' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
- 'spam' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
- 'trash' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
- ],
- ];
-
- $stats = new StatSQL();
-
- $orderCount = $stats->getOrdersCount($this->options)['orders'] ?? [];
+ 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']['badge'] = $newOrders;
+ $this->menu['sales']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';
+ }
+
//set order name as array keys
foreach ($orderCount as $type => $orders) {
if (isset($orders['name'])) {
@@ -91,18 +64,26 @@ class Notifications extends ComponentBase {
}
}
- $notifications['orders'] = $orderCount + $notifications['orders'];
+ $this->notifications['orders'] = $orderCount + $this->notifications['orders'];
+ }
- $productCount = $stats->getProductStockCount($this->options)['products'] ?? [];
+ protected function users() {
+ }
+
+ protected function products() {
+ $productCount = $this->stats->getProductStockCount($this->options)['products'] ?? [];
foreach ($productCount as $type => &$products) {
$products['icon'] = 'icon-cube-outline';
$products['badge'] = commentStatusBadgeClass($products['stock_status_id']);
}
- $notifications['products'] = $productCount + $notifications['products'];
+ $this->notifications['products'] = $productCount + $this->notifications['products'];
+ }
+
+ protected function comments() {
- $commentCount = $stats->getCommentsCount($this->options)['comments'] ?? [];
+ $commentCount = $this->stats->getCommentsCount($this->options)['comments'] ?? [];
$comment_status = [
0 => 'pending',
1 => 'approved',
@@ -110,6 +91,20 @@ class Notifications extends ComponentBase {
3 => 'trash',
];
+ $commentStatsusNew = 0; //get from site config
+ $newComments = ($commentCount[$commentStatsusNew]['count'] ?? 0);
+
+ if ($newComments > 0) {
+ $this->count += $newComments;
+ $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']['items']['comments']['badge'] = $newComments;
+ $this->menu['post']['items']['comments']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';
+ }
+
foreach ($commentCount as $type => $comments) {
$comments['icon'] = 'la la-comment';
$comments['badge'] = commentStatusBadgeClass($comments['status']);
@@ -117,10 +112,32 @@ class Notifications extends ComponentBase {
unset($commentCount[$type]);
}
- $notifications['comments'] = $commentCount + $notifications['comments'];
+ $this->notifications['comments'] = $commentCount + $this->notifications['comments'];
+ }
+
+ protected function reviews() {
+ $reviewCount = $this->stats->getReviewsCount($this->options)['reviews'] ?? [];
+ $comment_status = [
+ 0 => 'pending',
+ 1 => 'approved',
+ 2 => 'spam',
+ 3 => 'trash',
+ ];
- $reviewCount = $stats->getReviewsCount($this->options)['reviews'] ?? [];
+ $reviewStatsusNew = 0; //get from site config
+ $newReviews = ($reviewCount[$reviewStatsusNew]['count'] ?? 0);
+ if ($newReviews > 0) {
+ $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']['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']);
@@ -128,10 +145,33 @@ class Notifications extends ComponentBase {
unset($reviewCount[$type]);
}
- $notifications['reviews'] = $reviewCount + $notifications['reviews'];
+ $this->notifications['reviews'] = $reviewCount + $this->notifications['reviews'];
- $questionCount = $stats->getQuestionsCount($this->options)['questions'] ?? [];
+ }
+
+ protected function questions() {
+ $questionCount = $this->stats->getQuestionsCount($this->options)['questions'] ?? [];
+ $comment_status = [
+ 0 => 'pending',
+ 1 => 'approved',
+ 2 => 'spam',
+ 3 => 'trash',
+ ];
+
+ $questionStatsusNew = 0; //get from site config
+ $newQuestions = ($questionCount[$questionStatsusNew]['count'] ?? 0);
+ if ($newQuestions > 0) {
+ $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']['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']);
@@ -139,21 +179,80 @@ class Notifications extends ComponentBase {
unset($questionCount[$type]);
}
- $notifications['questions'] = $questionCount + $notifications['questions'];
+ $this->notifications['questions'] = $questionCount + $this->notifications['questions'];
+ }
+
+ function request(&$results, $index) {
+ //add menu notification count
+
+ if ($results['menu'] && $index == 0) {
+ $view = View::getInstance();
+ $view->menu = array_merge_recursive($view->menu, $results['menu']);
+ }
+ }
+
+ function results() {
+ // return [];
+ $cache = Cache::getInstance();
+
+ $this->notifications = [
+ 'updates' => [
+ 'core' => ['hasUpdate' => 1, 'version' => '1.0'],
+ ],
+ 'orders' => [
+ 'processing' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-primary-subtle text-body'],
+ 'complete' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-success-subtle text-body'],
+ 'processed' => ['count' => 0, 'icon' => 'icon-bag-handle-outline', 'badge' => 'bg-secondary-subtle text-body'],
+ ],
+ 'users' => [
+ 'month' => ['count' => 0, 'icon' => 'icon-person-outline', 'badge' => 'bg-secondary-subtle text-body'],
+ 'year' => ['count' => 0, 'icon' => 'icon-person-outline', 'badge' => 'bg-secondary-subtle text-body'],
+ ],
+ 'products' => [
+ ],
+ 'comments' => [
+ 'pending' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-primary-subtle text-body'],
+ 'approved' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ 'spam' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ 'trash' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ ],
+ 'reviews' => [
+ 'pending' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-primary-subtle text-body'],
+ 'approved' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ 'spam' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ 'trash' => ['count' => 0, 'icon' => 'la la-comment', 'badge' => 'bg-secondary-subtle text-body'],
+ ],
+ 'questions' => [
+ 'pending' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-primary-subtle text-body'],
+ 'approved' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
+ 'spam' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
+ 'trash' => ['count' => 0, 'icon' => 'la la-question-circle', 'badge' => 'bg-secondary-subtle text-body'],
+ ],
+ ];
+
+ $this->stats = new StatSQL();
+ $this->orders();
+ $this->users();
+ $this->products();
+ $this->comments();
+ $this->reviews();
+ $this->questions();
+
$update = new Update();
$updates = $update->checkUpdates('core');
- $notifications['updates']['core'] = $updates;
- $count = max($updates['hasUpdate'], 0);
+ $this->notifications['updates']['core'] = $updates;
+ $this->count += max($updates['hasUpdate'], 0);
$results = [
- 'notifications' => $notifications,
- 'count' => $count,
+ 'notifications' => $this->notifications,
+ 'count' => $this->count,
+ 'menu' => $this->menu,
];
list($results) = Event::trigger(__CLASS__, __FUNCTION__, $results);
-
+
return $results;
}
}
diff --git a/admin/controller/base.php b/admin/controller/base.php
index 40c4203..091d3fb 100755
--- a/admin/controller/base.php
+++ b/admin/controller/base.php
@@ -430,20 +430,20 @@ class Base {
}
if (isset($this->request->get['errors'])) {
- $view->errors[] = htmlentities($this->request->get['errors']);
+ $view->errors['get'] = htmlentities($this->request->get['errors']);
}
if ($errors = $this->session->get('errors')) {
- $view->errors[] = $errors;
+ $view->errors['session'] = $errors;
$this->session->delete('errors');
}
if (isset($this->request->get['success'])) {
- $view->success[] = htmlentities($this->request->get['success']);
+ $view->success['get'] = htmlentities($this->request->get['success']);
}
if ($success = $this->session->get('success')) {
- $view->success[] = $success;
+ $view->success['session'] = $success;
$this->session->delete('success');
}
@@ -467,16 +467,6 @@ class Base {
$products_menu = $this->customProducts();
$menu = array_insert_array_after('sales', $menu, $products_menu);
- $stats = new StatSQL();
- $orderCount = $stats->getOrdersCount($this->global);
- $orderStatsusNew = 1; //get from site config
- $newOrders = ($orderCount['orders'][$orderStatsusNew]['count'] ?? 0);
-
- if ($newOrders > 0) {
- $menu['sales']['badge'] = $newOrders;
- $menu['sales']['badge-class'] = 'badge bg-primary-subtle text-body mx-2';
- }
-
list($menu) = Event::trigger(__CLASS__, __FUNCTION__ . '-menu', $menu);
$urls = [];
diff --git a/admin/controller/content/comments.php b/admin/controller/content/comments.php
index 6f599f7..d49bc92 100755
--- a/admin/controller/content/comments.php
+++ b/admin/controller/content/comments.php
@@ -40,7 +40,7 @@ class Comments extends Listing {
protected $listController = 'comments';
- function status() {
+ function save() {
$type = $this->type;
$comment_id = $this->request->get[$type . '_id'] ?? false;
$status = $this->request->get['newstatus'] ?? false;
@@ -96,7 +96,7 @@ class Comments extends Listing {
$comment['image'] = Images::image($type, $comment['image']);
}
- $url = ['module' => "$module/$listController", 'action' => 'status', 'status' => $status, $type . '_id' => $comment[$type . '_id']];
+ $url = ['module' => "$module/$listController", 'action' => 'save', 'status' => $status, $type . '_id' => $comment[$type . '_id']];
$postUrl = ['module' => "$module/$controller", $type . '_id' => $comment[$type . '_id']];
$comment['edit-url'] = \Vvveb\url($postUrl);
$comment['delete-url'] = \Vvveb\url(['module' => "$module/$list", 'action' => 'delete'] + $url);
diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.php
index 3a14313..8514187 100644
--- a/admin/controller/content/edit.php
+++ b/admin/controller/content/edit.php
@@ -263,7 +263,7 @@ class Edit extends Base {
$result = $posts->edit([$this->object => $post, $this->object . '_id' => $post_id] + $this->global);
if ($result >= 0) {
- $this->view->success[] = ucfirst($this->type) . ' ' . __('saved') . '!';
+ $this->view->success['get'] = ucfirst($this->type) . ' ' . __('saved') . '!';
if ($this->revisions) {
$revisions = model($this->object . '_content_revision');
@@ -305,7 +305,7 @@ class Edit extends Base {
$new = true;
$message = ucfirst($this->type) . ' ' . __('saved') . '!';
- $view->success[] = $message;
+ $view->success['get'] = $message;
}
}
diff --git a/admin/controller/order/order.php b/admin/controller/order/order.php
index b64f2fa..e0551d3 100755
--- a/admin/controller/order/order.php
+++ b/admin/controller/order/order.php
@@ -74,16 +74,16 @@ class Order extends Base {
//$product['images'][] = ['image' => Images::image($product['image'], 'product')];
}
- $product['tax_formatted'] = $currency->format($product['tax'], '$');
+ $product['tax_formatted'] = $currency->format($product['tax']);
}
}
foreach ($results['total'] as $id => &$total) {
- $total['value_formatted'] = $currency->format($total['value'], '$');
+ $total['value_formatted'] = $currency->format($total['value']);
}
$order = &$results['order'];
- $order['total_formatted'] = $currency->format($order['total'], '$');
+ $order['total_formatted'] = $currency->format($order['total']);
$order['shipping_data'] = json_decode($order['shipping_data'] ?? '', true);
$order['payment_data'] = json_decode($order['payment_data'] ?? '', true);
$order['class'] = orderStatusBadgeClass($order['order_status_id']);
diff --git a/admin/controller/order/return-order.php b/admin/controller/order/return-order.php
index 9723990..d05e5dd 100644
--- a/admin/controller/order/return-order.php
+++ b/admin/controller/order/return-order.php
@@ -22,7 +22,12 @@
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_StatusSQL;
+
//Return is a reserved keyword using ReturnOrder and return-order instead
class ReturnOrder extends Crud {
protected $type = 'return';
@@ -30,4 +35,20 @@ class ReturnOrder extends Crud {
protected $controller = 'return-order';
protected $module = 'order';
+
+ function index() {
+ parent :: index();
+
+ $resolution = new Return_ResolutionSQL();
+ $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'] ?? [];
+
+ $this->view->return_resolution_id = $resolutions;
+ $this->view->return_reason_id = $reasons;
+ $this->view->return_status_id = $statuses;
+ }
}
diff --git a/admin/controller/user/user.php b/admin/controller/user/user.php
index 1c33ba9..c09b039 100755
--- a/admin/controller/user/user.php
+++ b/admin/controller/user/user.php
@@ -117,7 +117,7 @@ class User extends Base {
if (! $id) {
$view->errors = [$users->error];
} else {
- $view->success[] = ucfirst($this->type) . __(' added!');
+ $view->success['get'] = ucfirst($this->type) . __(' added!');
$this->redirect(['module'=> $this->type . '/user', $this->type . '_id' => $id, 'success' => $this->type . __(' added!')]);
}
}
diff --git a/admin/sql/mysqli/comment.sql b/admin/sql/mysqli/comment.sql
index 937a26b..7507988 100755
--- a/admin/sql/mysqli/comment.sql
+++ b/admin/sql/mysqli/comment.sql
@@ -23,8 +23,10 @@
)
BEGIN
- SELECT *, comment_id as array_key
+ SELECT comment.*, user.*, comment_id as array_key
FROM comment AS comment
+ LEFT JOIN user ON (comment.user_id = comment.user_id)
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sql
index 9120ce2..d3d2c6e 100755
--- a/admin/sql/mysqli/post.sql
+++ b/admin/sql/mysqli/post.sql
@@ -193,7 +193,13 @@
@IF isset(:taxonomy_item_slug)
THEN
- AND pt.taxonomy_item_id = (SELECT taxonomy_item_id FROM taxonomy_item_content WHERE slug = :taxonomy_item_slug LIMIT 1)
+ AND pt.taxonomy_item_id IN (
+ SELECT ti.taxonomy_item_id
+ FROM taxonomy_item_content AS tic
+ -- include child categories
+ LEFT JOIN taxonomy_item AS ti ON ti.parent_id = tic.taxonomy_item_id OR ti.taxonomy_item_id = tic.taxonomy_item_id
+ WHERE slug = :taxonomy_item_slug
+ )
END @IF
-- month
diff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sql
index 59a41f1..87e6a3b 100755
--- a/admin/sql/mysqli/product.sql
+++ b/admin/sql/mysqli/product.sql
@@ -6,6 +6,14 @@
IN product_id INT,
IN slug CHAR,
IN language_id INT,
+ IN promotion INT,
+ IN points INT,
+ IN stock_status INT,
+ IN weight_type INT,
+ IN length_type INT,
+ IN rating INT,
+ IN reviews INT,
+
OUT fetch_row,
OUT fetch_all,
OUT fetch_all,
@@ -28,6 +36,98 @@
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
+ -- include promotional price
+ @IF !empty(:promotion) && !empty(:user_group_id)
+ THEN
+ ,(SELECT pp.price FROM product_promotion pp
+ WHERE pp.product_id = _.product_id AND pp.user_group_id = :user_group_id
+ AND (
+ (pp.from_date = '0000-00-00' OR pp.from_date < NOW())
+ AND (pp.to_date = '0000-00-00' OR pp.to_date > NOW())
+ )
+ ORDER BY pp.priority ASC, pp.price ASC
+ LIMIT 1
+ ) AS promotion
+ END @IF
+
+ -- include points
+ @IF !empty(:points) && !empty(:user_group_id)
+ THEN
+
+ ,(SELECT points
+ FROM product_points pp
+ WHERE pp.product_id = _.product_id
+ AND pp.user_group_id = :user_group_id
+ AS points
+
+ END @IF
+
+ -- include stock_status
+ @IF !empty(:stock_status)
+ THEN
+
+ ,(SELECT ss.name
+ FROM stock_status ss
+ WHERE ss.stock_status_id = _.stock_status_id
+ AND ss.language_id = :language_id)
+ AS stock_status
+
+ END @IF
+
+
+ -- include weight_type
+ @IF !empty(:weight_type)
+ THEN
+
+ ,(SELECT wcd.unit
+ FROM weight_type_content wcd
+ WHERE _.weight_type_id = wcd.weight_type_id
+ AND wcd.language_id = :language_id)
+ AS weight_type
+
+ END @IF
+
+
+ -- include length_type
+ @IF !empty(:length_type)
+ THEN
+
+ ,(SELECT lcd.unit
+ FROM length_type_content lcd
+ WHERE _.length_type_id = lcd.length_type_id
+ AND lcd.language_id = :language_id)
+ AS length_type
+
+ END @IF
+
+
+ -- include rating
+ @IF !empty(:rating)
+ THEN
+
+ ,(SELECT AVG(rating) AS total
+ FROM product_review prvr
+ WHERE prvr.product_id = _.product_id
+ AND prvr.status = '1'
+ GROUP BY prvr.product_id)
+ AS rating
+
+
+ END @IF
+
+ -- include reviews
+ @IF !empty(:reviews)
+ THEN
+
+ ,(SELECT COUNT(*) AS total
+ FROM product_review prv
+ WHERE prv.product_id = _.product_id
+ AND prv.status = 1
+ GROUP BY prv.product_id) AS reviews
+
+
+ END @IF
+
FROM product as _ -- (underscore) _ means that data will be kept in main array ['data'] and not default ['product'=>['data']]
LEFT JOIN product_content pc ON (
_.product_id = pc.product_id
@@ -614,12 +714,12 @@
IN direction CHAR,
-- columns options (local variables used for conditional sql)
- LOCAL include_manufacturer INT,
- LOCAL include_discount INT,
- LOCAL include_special INT,
- LOCAL include_points INT,
- LOCAL include_stock_status INT,
- LOCAL include_image_gallery INT,
+ LOCAL manufacturer INT,
+ LOCAL discount INT,
+ LOCAL special INT,
+ LOCAL points INT,
+ LOCAL stock_status INT,
+ LOCAL product_image INT,
-- return array of products for products query
OUT fetch_all,
@@ -630,7 +730,7 @@
SELECT pd.*,products.*
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
,m.name AS manufacturer
END @IF
@@ -638,13 +738,13 @@
-- include image gallery
- @IF !empty(:include_image_gallery)
+ @IF !empty(:product_image)
THEN
,(SELECT CONCAT('[', 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 images
END @IF
-- include discount
- @IF !empty(:include_discount) && !empty(:user_group_id)
+ @IF !empty(:discount) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -662,7 +762,7 @@
END @IF
-- include special price
- @IF !empty(:include_special) && !empty(:user_group_id)
+ @IF !empty(:promotion) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -680,7 +780,7 @@
-- include points
- @IF !empty(:include_points) && !empty(:user_group_id)
+ @IF !empty(:points) && !empty(:user_group_id)
THEN
,(SELECT points
@@ -692,7 +792,7 @@
END @IF
-- include stock_status
- @IF !empty(:include_stock_status)
+ @IF !empty(:stock_status)
THEN
,(SELECT ss.name
@@ -706,7 +806,7 @@
-- include weight_type
- @IF !empty(:include_weight_type)
+ @IF !empty(:weight_type)
THEN
,(SELECT wcd.unit
@@ -719,7 +819,7 @@
-- include length_type
- @IF !empty(:include_length_type)
+ @IF !empty(:length_type)
THEN
,(SELECT lcd.unit
@@ -732,7 +832,7 @@
-- include rating
- @IF !empty(:include_rating)
+ @IF !empty(:rating)
THEN
,(SELECT AVG(rating) AS total
@@ -746,7 +846,7 @@
END @IF
-- include reviews
- @IF !empty(:include_reviews)
+ @IF !empty(:reviews)
THEN
,(SELECT COUNT(*) AS total
@@ -778,7 +878,7 @@
)
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
END @IF
diff --git a/admin/sql/mysqli/product_question.sql b/admin/sql/mysqli/product_question.sql
index 575e2bf..fe9843e 100755
--- a/admin/sql/mysqli/product_question.sql
+++ b/admin/sql/mysqli/product_question.sql
@@ -20,6 +20,7 @@
SELECT *
FROM product_question AS product_question
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE 1 = 1
@@ -68,6 +69,7 @@
-- question
SELECT *
FROM product_question as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE product_question_id = :product_question_id LIMIT 1;
END
diff --git a/admin/sql/mysqli/product_review.sql b/admin/sql/mysqli/product_review.sql
index 4d2e59c..43a7ff4 100755
--- a/admin/sql/mysqli/product_review.sql
+++ b/admin/sql/mysqli/product_review.sql
@@ -19,8 +19,13 @@
)
BEGIN
- SELECT *
- FROM product_review AS product_review
+ SELECT product_review.*,user.*,user.user_id as user_id,
+ (SELECT CONCAT('[', GROUP_CONCAT('{"id":"', prm.product_review_media_id, '","image":"' , prm.image, '"}'), ']')
+ FROM product_review_media as prm
+ WHERE prm.product_review_id = product_review.product_review_id) as images
+
+ FROM product_review
+ LEFT JOIN user ON user.user_id = product_review.user_id
WHERE 1 = 1
@@ -32,9 +37,9 @@
-- post slug
@IF isset(:slug)
- THEN
- AND product_review.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
- END @IF
+ THEN
+ AND product_review.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
+ END @IF
-- user
@IF isset(:user_id)
@@ -69,6 +74,7 @@
-- review
SELECT *
FROM product_review as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_review.user_id
WHERE product_review_id = :product_review_id LIMIT 1;
END
diff --git a/admin/sql/mysqli/product_review_media.sql b/admin/sql/mysqli/product_review_media.sql
new file mode 100644
index 0000000..0876d5a
--- /dev/null
+++ b/admin/sql/mysqli/product_review_media.sql
@@ -0,0 +1,122 @@
+-- Product reviews
+
+
+ CREATE PROCEDURE getAll(
+ -- variables
+ IN language_id INT,
+ IN site_id INT,
+ IN product_id INT,
+ IN product_review_id INT,
+ IN status INT,
+
+ -- pagination
+ IN start INT,
+ IN limit INT,
+
+ -- return
+ OUT fetch_all, -- orders
+ OUT fetch_one -- count
+ )
+ BEGIN
+
+ SELECT *
+ FROM product_review_media
+ INNER JOIN product_review ON product_review.product_review_id = product_review_media.product_review_id
+
+ WHERE 1 = 1
+
+ -- post
+ @IF isset(:product_id)
+ THEN
+ AND product_review_media.product_id = :product_id
+ END @IF
+
+
+ -- product_review
+ @IF isset(:product_review_id)
+ THEN
+ AND product_review_media.product_review_id = :product_review_id
+ END @IF
+
+ -- status
+ @IF isset(:status)
+ THEN
+ AND product_review.status = :status
+ END @IF
+
+
+ @SQL_LIMIT(:start, :limit);
+
+ SELECT count(*) FROM (
+
+ @SQL_COUNT(product_review_media.product_review_media_id, product_review_media) -- this takes previous query removes limit and replaces select columns with parameter product_review_media_id
+
+ ) as count;
+
+
+ END
+
+ -- Get product review
+
+ CREATE PROCEDURE get(
+ IN product_review_media_id INT,
+ OUT fetch_row,
+ )
+ BEGIN
+ -- review
+ SELECT *
+ FROM product_review_media as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN product_review on product_review.product_review_id = product_review_media.product_review_id
+ WHERE product_review_media_id = :product_review_media_id LIMIT 1;
+
+ END
+
+ -- Add new product review
+
+ CREATE PROCEDURE add(
+ IN product_review_media ARRAY,
+ OUT insert_id
+ )
+ BEGIN
+
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ INSERT INTO product_review_media
+
+ ( @KEYS(:product_review_media) )
+
+ VALUES ( :product_review_media )
+
+ END
+
+ -- Edit product review
+
+ CREATE PROCEDURE edit(
+ IN product_review_media ARRAY,
+ IN id_product_review_media INT,
+ OUT affected_rows
+ )
+ BEGIN
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ UPDATE product_review_media
+
+ SET @LIST(:product_review_media)
+
+ WHERE product_review_media_id = :product_review_media_id
+
+ END
+
+ -- Delete product review
+
+ CREATE PROCEDURE delete(
+ IN product_review_media_id ARRAY,
+ OUT affected_rows
+ )
+ BEGIN
+
+ DELETE FROM product_review_media WHERE product_review_media_id IN (:product_review_media_id)
+
+ END
diff --git a/admin/sql/mysqli/return.sql b/admin/sql/mysqli/return.sql
index cfcb187..f7abfa4 100755
--- a/admin/sql/mysqli/return.sql
+++ b/admin/sql/mysqli/return.sql
@@ -11,8 +11,11 @@
)
BEGIN
-- return
- SELECT return.*, return_resolution.name as return_resolution, return_reason.name as return_reason, return_status.name as return_status
- FROM return AS return
+ SELECT `return`.*,
+ return_resolution.name as return_resolution,
+ return_reason.name as return_reason,
+ return_status.name as return_status
+ FROM `return`
INNER JOIN return_resolution ON return_resolution.return_resolution_id = return.return_resolution_id AND return_resolution.language_id = :language_id
INNER JOIN return_reason ON return_reason.return_reason_id = return.return_reason_id AND return_reason.language_id = :language_id
INNER JOIN return_status ON return_status.return_status_id = return.return_status_id AND return_status.language_id = :language_id
@@ -42,7 +45,7 @@
BEGIN
-- return
SELECT *
- FROM return as _ WHERE return_id = :return_id;
+ FROM `return` as _ WHERE return_id = :return_id;
END
-- add return
@@ -57,7 +60,7 @@
:return_data = @FILTER(:return, return);
- INSERT INTO return
+ INSERT INTO `return`
( @KEYS(:return_data) )
@@ -76,7 +79,7 @@
-- allow only table fields and set defaults for missing values
@FILTER(:return, return);
- UPDATE return
+ UPDATE `return`
SET @LIST(:return)
diff --git a/admin/sql/mysqli/site.sql b/admin/sql/mysqli/site.sql
index ab8553b..eb11260 100755
--- a/admin/sql/mysqli/site.sql
+++ b/admin/sql/mysqli/site.sql
@@ -139,10 +139,12 @@
)
BEGIN
+ -- allow only table fields and set defaults for missing values
+ :site_data = @FILTER(:site, site);
UPDATE site
- SET @LIST(:site)
+ SET @LIST(:site_data)
WHERE site_id = :site_id
diff --git a/admin/sql/mysqli/stat.sql b/admin/sql/mysqli/stat.sql
index 5482d2d..2c88ba0 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, orders.created_at, os.name, orders.order_status_id, orders.order_status_id as array_key
+ SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key
FROM `order` AS orders
LEFT 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, orders.created_at, os.name;
+ GROUP BY orders.order_status_id, os.name, date, orders.order_status_id;
END
CREATE PROCEDURE getCommentsCount(
@@ -162,7 +162,7 @@
END @IF
- GROUP BY comments.status, comments.created_at;
+ GROUP BY comments.status, comments.created_at, date;
END
@@ -184,7 +184,7 @@
-- reviews
- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status,reviews.created_at, reviews.status as array_key FROM product_review AS reviews
+ SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews
WHERE 1 = 1
@@ -210,7 +210,7 @@
END @IF
- GROUP BY reviews.status, reviews.created_at;
+ GROUP BY reviews.status, date;
END
CREATE PROCEDURE getQuestionsCount(
@@ -231,7 +231,7 @@
-- questions
- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.created_at, questions.status as array_key FROM product_question AS questions
+ SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions
WHERE 1 = 1
@@ -257,7 +257,7 @@
END @IF
- GROUP BY questions.status, questions.created_at;
+ GROUP BY questions.status, date;
END
CREATE PROCEDURE getProductStockCount(
@@ -276,7 +276,7 @@
-- products
- SELECT COUNT(*) AS count, products.stock_status_id, products.created_at as array_key FROM product AS products
+ SELECT COUNT(*) AS count, products.stock_status_id, st.name as array_key FROM product AS products
LEFT JOIN stock_status AS st ON (products.stock_status_id = st.stock_status_id AND st.language_id = :language_id)
@@ -299,6 +299,6 @@
END @IF
- GROUP BY products.stock_status_id, products.created_at ORDER BY products.stock_status_id;
+ GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;
END
diff --git a/admin/sql/pgsql/comment.sql b/admin/sql/pgsql/comment.sql
index 1fd5606..aa86522 100755
--- a/admin/sql/pgsql/comment.sql
+++ b/admin/sql/pgsql/comment.sql
@@ -23,8 +23,10 @@
)
BEGIN
- SELECT *, comment_id as array_key
+ SELECT comment.*, user.*, comment_id as array_key
FROM comment AS comment
+ LEFT JOIN user ON (comment.user_id = comment.user_id)
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
diff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sql
index 33ca02b..1bdcee3 100755
--- a/admin/sql/pgsql/post.sql
+++ b/admin/sql/pgsql/post.sql
@@ -135,7 +135,13 @@
@IF isset(:taxonomy_item_slug)
THEN
- AND pt.taxonomy_item_id = (SELECT taxonomy_item_id FROM taxonomy_item_content WHERE slug = :taxonomy_item_slug LIMIT 1)
+ AND pt.taxonomy_item_id IN (
+ SELECT ti.taxonomy_item_id
+ FROM taxonomy_item_content AS tic
+ -- include child categories
+ LEFT JOIN taxonomy_item AS ti ON ti.parent_id = tic.taxonomy_item_id OR ti.taxonomy_item_id = tic.taxonomy_item_id
+ WHERE slug = :taxonomy_item_slug
+ )
END @IF
-- month
diff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sql
index 80c182f..845fb3d 100755
--- a/admin/sql/pgsql/product.sql
+++ b/admin/sql/pgsql/product.sql
@@ -6,6 +6,14 @@
IN product_id INT,
IN slug CHAR,
IN language_id INT,
+ IN promotion INT,
+ IN points INT,
+ IN stock_status INT,
+ IN weight_type INT,
+ IN length_type INT,
+ IN rating INT,
+ IN reviews INT,
+
OUT fetch_row,
OUT fetch_all,
OUT fetch_all,
@@ -28,6 +36,98 @@
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
+ -- include promotional price
+ @IF !empty(:promotion) && !empty(:user_group_id)
+ THEN
+ ,(SELECT pp.price FROM product_promotion pp
+ WHERE pp.product_id = _.product_id AND pp.user_group_id = :user_group_id
+ AND (
+ (pp.from_date = '0000-00-00' OR pp.from_date < NOW())
+ AND (pp.to_date = '0000-00-00' OR pp.to_date > NOW())
+ )
+ ORDER BY pp.priority ASC, pp.price ASC
+ LIMIT 1
+ ) AS promotion
+ END @IF
+
+ -- include points
+ @IF !empty(:points) && !empty(:user_group_id)
+ THEN
+
+ ,(SELECT points
+ FROM product_points pp
+ WHERE pp.product_id = _.product_id
+ AND pp.user_group_id = :user_group_id
+ AS points
+
+ END @IF
+
+ -- include stock_status
+ @IF !empty(:stock_status)
+ THEN
+
+ ,(SELECT ss.name
+ FROM stock_status ss
+ WHERE ss.stock_status_id = _.stock_status_id
+ AND ss.language_id = :language_id)
+ AS stock_status
+
+ END @IF
+
+
+ -- include weight_type
+ @IF !empty(:weight_type)
+ THEN
+
+ ,(SELECT wcd.unit
+ FROM weight_type_content wcd
+ WHERE _.weight_type_id = wcd.weight_type_id
+ AND wcd.language_id = :language_id)
+ AS weight_type
+
+ END @IF
+
+
+ -- include length_type
+ @IF !empty(:length_type)
+ THEN
+
+ ,(SELECT lcd.unit
+ FROM length_type_content lcd
+ WHERE _.length_type_id = lcd.length_type_id
+ AND lcd.language_id = :language_id)
+ AS length_type
+
+ END @IF
+
+
+ -- include rating
+ @IF !empty(:rating)
+ THEN
+
+ ,(SELECT AVG(rating) AS total
+ FROM product_review prvr
+ WHERE prvr.product_id = _.product_id
+ AND prvr.status = '1'
+ GROUP BY prvr.product_id)
+ AS rating
+
+
+ END @IF
+
+ -- include reviews
+ @IF !empty(:reviews)
+ THEN
+
+ ,(SELECT COUNT(*) AS total
+ FROM product_review prv
+ WHERE prv.product_id = _.product_id
+ AND prv.status = 1
+ GROUP BY prv.product_id) AS reviews
+
+
+ END @IF
+
FROM product as _ -- (underscore) _ means that data will be kept in main array ['data'] and not default ['product'=>['data']]
LEFT JOIN product_content pc ON (
_.product_id = pc.product_id
@@ -613,12 +713,12 @@
IN direction CHAR,
-- columns options (local variables used for conditional sql)
- LOCAL include_manufacturer INT,
- LOCAL include_discount INT,
- LOCAL include_special INT,
- LOCAL include_points INT,
- LOCAL include_stock_status INT,
- LOCAL include_image_gallery INT,
+ LOCAL manufacturer INT,
+ LOCAL discount INT,
+ LOCAL special INT,
+ LOCAL points INT,
+ LOCAL stock_status INT,
+ LOCAL image_gallery INT,
-- return array of products for products query
OUT fetch_all,
@@ -629,7 +729,7 @@
SELECT pd.*,products.*
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
,m.name AS manufacturer
END @IF
@@ -637,14 +737,14 @@
-- include image gallery
- @IF !empty(:include_image_gallery)
+ @IF !empty(:image_gallery)
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 images
END @IF
-- include discount
- @IF !empty(:include_discount) && !empty(:user_group_id)
+ @IF !empty(:discount) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -662,7 +762,7 @@
END @IF
-- include special price
- @IF !empty(:include_special) && !empty(:user_group_id)
+ @IF !empty(:special) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -680,7 +780,7 @@
-- include points
- @IF !empty(:include_points) && !empty(:user_group_id)
+ @IF !empty(:points) && !empty(:user_group_id)
THEN
,(SELECT points
@@ -692,7 +792,7 @@
END @IF
-- include stock_status
- @IF !empty(:include_stock_status)
+ @IF !empty(:stock_status)
THEN
,(SELECT ss.name
@@ -706,7 +806,7 @@
-- include weight_type
- @IF !empty(:include_weight_type)
+ @IF !empty(:weight_type)
THEN
,(SELECT wcd.unit
@@ -719,7 +819,7 @@
-- include length_type
- @IF !empty(:include_length_type)
+ @IF !empty(:length_type)
THEN
,(SELECT lcd.unit
@@ -732,7 +832,7 @@
-- include rating
- @IF !empty(:include_rating)
+ @IF !empty(:rating)
THEN
,(SELECT AVG(rating) AS total
@@ -746,7 +846,7 @@
END @IF
-- include reviews
- @IF !empty(:include_reviews)
+ @IF !empty(:reviews)
THEN
,(SELECT COUNT(*) AS total
@@ -782,7 +882,7 @@
)
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
END @IF
diff --git a/admin/sql/pgsql/product_question.sql b/admin/sql/pgsql/product_question.sql
index d9b6930..95ee84d 100755
--- a/admin/sql/pgsql/product_question.sql
+++ b/admin/sql/pgsql/product_question.sql
@@ -20,6 +20,7 @@
SELECT *
FROM product_question AS product_question
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE 1 = 1
@@ -68,6 +69,7 @@
-- question
SELECT *
FROM product_question as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE product_question_id = :product_question_id LIMIT 1;
END
diff --git a/admin/sql/pgsql/product_review.sql b/admin/sql/pgsql/product_review.sql
index 8197c9a..00734c3 100755
--- a/admin/sql/pgsql/product_review.sql
+++ b/admin/sql/pgsql/product_review.sql
@@ -19,8 +19,13 @@
)
BEGIN
- SELECT *
- FROM product_review AS product_review
+ SELECT product_review.*,user.*,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 prm
+ WHERE prm.product_review_id = product_review.product_review_id) as images
+
+ FROM product_review
+ LEFT JOIN user ON user.user_id = product_review.user_id
WHERE 1 = 1
@@ -69,6 +74,7 @@
-- review
SELECT *
FROM product_review as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_review.user_id
WHERE product_review_id = :product_review_id LIMIT 1;
END
diff --git a/admin/sql/pgsql/product_review_media.sql b/admin/sql/pgsql/product_review_media.sql
new file mode 100644
index 0000000..e8f1b34
--- /dev/null
+++ b/admin/sql/pgsql/product_review_media.sql
@@ -0,0 +1,122 @@
+-- Product reviews
+
+
+ CREATE PROCEDURE getAll(
+ -- variables
+ IN language_id INT,
+ IN site_id INT,
+ IN product_id INT,
+ IN product_review_id INT,
+ IN status INT,
+
+ -- pagination
+ IN start INT,
+ IN limit INT,
+
+ -- return
+ OUT fetch_all, -- orders
+ OUT fetch_one -- count
+ )
+ BEGIN
+
+ SELECT *
+ FROM product_review_media
+ INNER JOIN product_review ON product_review.product_review_id = product_review_media.product_review_id
+
+ WHERE 1 = 1
+
+ -- post
+ @IF isset(:product_id)
+ THEN
+ AND product_review_media.product_id = :product_id
+ END @IF
+
+
+ -- product_review
+ @IF isset(:product_review_id)
+ THEN
+ AND product_review_media.product_review_id = :product_review_id
+ END @IF
+
+ -- status
+ @IF isset(:status)
+ THEN
+ AND product_review.status = :status
+ END @IF
+
+
+ @SQL_LIMIT(:start, :limit);
+
+ SELECT count(*) FROM (
+
+ @SQL_COUNT(product_review_media.product_review_media_id, product_review_media) -- this takes previous query removes limit and replaces select columns with parameter product_review_media_id
+
+ ) as count;
+
+
+ END
+
+ -- Get product review
+
+ CREATE PROCEDURE get(
+ IN product_review_media_id INT,
+ OUT fetch_row,
+ )
+ BEGIN
+ -- review
+ SELECT *
+ FROM product_review_media as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN product_review on product_review.product_review_id = product_review_media.product_review_id
+ WHERE product_review_media_id = :product_review_media_id LIMIT 1;
+
+ END
+
+ -- Add new product review
+
+ CREATE PROCEDURE add(
+ IN product_review_media ARRAY,
+ OUT insert_id
+ )
+ BEGIN
+
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ INSERT INTO product_review_media
+
+ ( @KEYS(:product_review_media) )
+
+ VALUES ( :product_review_media )
+
+ END
+
+ -- Edit product review
+
+ CREATE PROCEDURE edit(
+ IN product_review_media ARRAY,
+ IN id_product_review_media INT,
+ OUT affected_rows
+ )
+ BEGIN
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ UPDATE product_review_media
+
+ SET @LIST(:product_review_media)
+
+ WHERE product_review_media_id = :product_review_media_id
+
+ END
+
+ -- Delete product review
+
+ CREATE PROCEDURE delete(
+ IN product_review_media_id ARRAY,
+ OUT affected_rows
+ )
+ BEGIN
+
+ DELETE FROM product_review_media WHERE product_review_media_id IN (:product_review_media_id)
+
+ END
diff --git a/admin/sql/pgsql/setting.sql b/admin/sql/pgsql/setting.sql
index 127b5e8..9fd5957 100755
--- a/admin/sql/pgsql/setting.sql
+++ b/admin/sql/pgsql/setting.sql
@@ -43,8 +43,7 @@
VALUES ( :namespace, :key, :value, :site_id )
- ON DUPLICATE KEY
- UPDATE value = values(value);
+ ON CONFLICT(`site_id`, `namespace`, `key`) DO UPDATE SET `value` = :value;
END
diff --git a/admin/sql/pgsql/setting_content.sql b/admin/sql/pgsql/setting_content.sql
index 99fb2c5..11183a6 100755
--- a/admin/sql/pgsql/setting_content.sql
+++ b/admin/sql/pgsql/setting_content.sql
@@ -42,8 +42,7 @@
VALUES ( :key, :value, :site_id , :language_id )
- ON DUPLICATE KEY
- UPDATE value = VALUES(value);
+ ON CONFLICT(`site_id`, `language_id`, `key`) DO UPDATE SET `value` = :value;
END
diff --git a/admin/sql/pgsql/site.sql b/admin/sql/pgsql/site.sql
index 1767219..74c7215 100755
--- a/admin/sql/pgsql/site.sql
+++ b/admin/sql/pgsql/site.sql
@@ -139,10 +139,12 @@
)
BEGIN
+ -- allow only table fields and set defaults for missing values
+ :site_data = @FILTER(:site, site);
UPDATE site
- SET @LIST(:site)
+ SET @LIST(:site_data)
WHERE site_id = :site_id
diff --git a/admin/sql/pgsql/stat.sql b/admin/sql/pgsql/stat.sql
index ed5e2e9..bca72ce 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, orders.created_at, os.name, orders.order_status_id, orders.order_status_id as array_key
+ SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key
FROM "order" AS orders
LEFT 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, orders.created_at, os.name;
+ GROUP BY orders.order_status_id, os.name, date, orders.order_status_id;
END
CREATE PROCEDURE getCommentsCount(
@@ -162,7 +162,7 @@
END @IF
- GROUP BY comments.status, comments.created_at;
+ GROUP BY comments.status, comments.created_at, date;
END
@@ -184,7 +184,7 @@
-- reviews
- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status,reviews.created_at, reviews.status as array_key FROM product_review AS reviews
+ SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews
WHERE 1 = 1
@@ -210,7 +210,7 @@
END @IF
- GROUP BY reviews.status, reviews.created_at;
+ GROUP BY reviews.status, date;
END
CREATE PROCEDURE getQuestionsCount(
@@ -231,7 +231,7 @@
-- questions
- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.created_at, questions.status as array_key FROM product_question AS questions
+ SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions
WHERE 1 = 1
@@ -257,7 +257,7 @@
END @IF
- GROUP BY questions.status, questions.created_at;
+ GROUP BY questions.status, date;
END
CREATE PROCEDURE getProductStockCount(
@@ -276,7 +276,7 @@
-- products
- SELECT COUNT(*) AS count, products.stock_status_id, products.created_at as array_key FROM product AS products
+ SELECT COUNT(*) AS count, products.stock_status_id, st.name as array_key FROM product AS products
LEFT JOIN stock_status AS st ON (products.stock_status_id = st.stock_status_id AND st.language_id = :language_id)
@@ -299,6 +299,6 @@
END @IF
- GROUP BY products.stock_status_id, products.created_at ORDER BY products.stock_status_id;
+ GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;
END
diff --git a/admin/sql/sqlite/comment.sql b/admin/sql/sqlite/comment.sql
index 7630604..487fc3e 100755
--- a/admin/sql/sqlite/comment.sql
+++ b/admin/sql/sqlite/comment.sql
@@ -23,8 +23,10 @@
)
BEGIN
- SELECT *, comment_id as array_key
+ SELECT comment.*, user.*, comment_id as array_key
FROM comment AS comment
+ LEFT JOIN user ON (comment.user_id = comment.user_id)
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
diff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sql
index 0069556..f013a07 100755
--- a/admin/sql/sqlite/post.sql
+++ b/admin/sql/sqlite/post.sql
@@ -131,7 +131,13 @@
@IF isset(:taxonomy_item_slug)
THEN
- AND pt.taxonomy_item_id = (SELECT taxonomy_item_id FROM taxonomy_item_content WHERE slug = :taxonomy_item_slug LIMIT 1)
+ AND pt.taxonomy_item_id IN (
+ SELECT ti.taxonomy_item_id
+ FROM taxonomy_item_content AS tic
+ -- include child categories
+ LEFT JOIN taxonomy_item AS ti ON ti.parent_id = tic.taxonomy_item_id OR ti.taxonomy_item_id = tic.taxonomy_item_id
+ WHERE slug = :taxonomy_item_slug
+ )
END @IF
-- month
diff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sql
index 37335d6..e492ea0 100755
--- a/admin/sql/sqlite/product.sql
+++ b/admin/sql/sqlite/product.sql
@@ -6,6 +6,14 @@
IN product_id INT,
IN slug CHAR,
IN language_id INT,
+ IN promotion INT,
+ IN points INT,
+ IN stock_status INT,
+ IN weight_type INT,
+ IN length_type INT,
+ IN rating INT,
+ IN reviews INT,
+
OUT fetch_row,
OUT fetch_all,
OUT fetch_all,
@@ -28,6 +36,98 @@
vd.slug as vendor_slug, vd.name as vendor_name,
st.name as stock_status_name
+ -- include promotional price
+ @IF !empty(:promotion) && !empty(:user_group_id)
+ THEN
+ ,(SELECT pp.price FROM product_promotion pp
+ WHERE pp.product_id = _.product_id AND pp.user_group_id = :user_group_id
+ AND (
+ (pp.from_date = '0000-00-00' OR pp.from_date < date('now'))
+ AND (pp.to_date = '0000-00-00' OR pp.to_date > date('now'))
+ )
+ ORDER BY pp.priority ASC, pp.price ASC
+ LIMIT 1
+ ) AS promotion
+ END @IF
+
+ -- include points
+ @IF !empty(:points) && !empty(:user_group_id)
+ THEN
+
+ ,(SELECT points
+ FROM product_points pp
+ WHERE pp.product_id = _.product_id
+ AND pp.user_group_id = :user_group_id
+ AS points
+
+ END @IF
+
+ -- include stock_status
+ @IF !empty(:stock_status)
+ THEN
+
+ ,(SELECT ss.name
+ FROM stock_status ss
+ WHERE ss.stock_status_id = _.stock_status_id
+ AND ss.language_id = :language_id)
+ AS stock_status
+
+ END @IF
+
+
+ -- include weight_type
+ @IF !empty(:weight_type)
+ THEN
+
+ ,(SELECT wcd.unit
+ FROM weight_type_content wcd
+ WHERE _.weight_type_id = wcd.weight_type_id
+ AND wcd.language_id = :language_id)
+ AS weight_type
+
+ END @IF
+
+
+ -- include length_type
+ @IF !empty(:length_type)
+ THEN
+
+ ,(SELECT lcd.unit
+ FROM length_type_content lcd
+ WHERE _.length_type_id = lcd.length_type_id
+ AND lcd.language_id = :language_id)
+ AS length_type
+
+ END @IF
+
+
+ -- include rating
+ @IF !empty(:rating)
+ THEN
+
+ ,(SELECT AVG(rating) AS total
+ FROM product_review prvr
+ WHERE prvr.product_id = _.product_id
+ AND prvr.status = '1'
+ GROUP BY prvr.product_id)
+ AS rating
+
+
+ END @IF
+
+ -- include reviews
+ @IF !empty(:reviews)
+ THEN
+
+ ,(SELECT COUNT(*) AS total
+ FROM product_review prv
+ WHERE prv.product_id = _.product_id
+ AND prv.status = 1
+ GROUP BY prv.product_id) AS reviews
+
+
+ END @IF
+
FROM product as _ -- (underscore) _ means that data will be kept in main array ['data'] and not default ['product'=>['data']]
LEFT JOIN product_content pc ON (
_.product_id = pc.product_id
@@ -614,12 +714,12 @@
IN direction CHAR,
-- columns options (local variables used for conditional sql)
- LOCAL include_manufacturer INT,
- LOCAL include_discount INT,
- LOCAL include_special INT,
- LOCAL include_points INT,
- LOCAL include_stock_status INT,
- LOCAL include_image_gallery INT,
+ LOCAL manufacturer INT,
+ LOCAL discount INT,
+ LOCAL special INT,
+ LOCAL points INT,
+ LOCAL stock_status INT,
+ LOCAL image_gallery INT,
-- return array of products for products query
OUT fetch_all,
@@ -630,7 +730,7 @@
SELECT pd.*,products.*
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
,m.name AS manufacturer
END @IF
@@ -638,7 +738,7 @@
-- include image gallery
- @IF !empty(:include_image_gallery)
+ @IF !empty(:image_gallery)
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 images
@@ -646,7 +746,7 @@
END @IF
-- include discount
- @IF !empty(:include_discount) && !empty(:user_group_id)
+ @IF !empty(:discount) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -655,16 +755,16 @@
AND pd2.user_group_id = :user_group_id
AND pd2.quantity = '1'
AND ((pd2.from_date = '0000-00-00'
- OR pd2.from_date < NOW())
+ OR pd2.from_date < date('now'))
AND (pd2.to_date = '0000-00-00'
- OR pd2.to_date > NOW()))
+ OR pd2.to_date > date('now')))
ORDER BY pd2.priority ASC, pd2.price ASC
LIMIT 1) AS discount
END @IF
-- include special price
- @IF !empty(:include_special) && !empty(:user_group_id)
+ @IF !empty(:special) && !empty(:user_group_id)
THEN
,(SELECT price
@@ -672,9 +772,9 @@
WHERE ps.product_id = products.product_id
AND ps.user_group_id = :user_group_id
AND ((ps.from_date = '0000-00-00'
- OR ps.from_date < NOW())
+ OR ps.from_date < date('now'))
AND (ps.to_date = '0000-00-00'
- OR ps.to_date > NOW()))
+ OR ps.to_date > date('now')))
ORDER BY ps.priority ASC, ps.price ASC
LIMIT 1) AS special
@@ -682,7 +782,7 @@
-- include points
- @IF !empty(:include_points) && !empty(:user_group_id)
+ @IF !empty(:points) && !empty(:user_group_id)
THEN
,(SELECT points
@@ -694,7 +794,7 @@
END @IF
-- include stock_status
- @IF !empty(:include_stock_status)
+ @IF !empty(:stock_status)
THEN
,(SELECT ss.name
@@ -708,7 +808,7 @@
-- include weight_type
- @IF !empty(:include_weight_type)
+ @IF !empty(:weight_type)
THEN
,(SELECT wcd.unit
@@ -721,7 +821,7 @@
-- include length_type
- @IF !empty(:include_length_type)
+ @IF !empty(:length_type)
THEN
,(SELECT lcd.unit
@@ -734,7 +834,7 @@
-- include rating
- @IF !empty(:include_rating)
+ @IF !empty(:rating)
THEN
,(SELECT AVG(rating) AS total
@@ -748,7 +848,7 @@
END @IF
-- include reviews
- @IF !empty(:include_reviews)
+ @IF !empty(:reviews)
THEN
,(SELECT COUNT(*) AS total
@@ -773,7 +873,7 @@
)
- @IF !empty(:include_manufacturer)
+ @IF !empty(:manufacturer)
THEN
LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
END @IF
diff --git a/admin/sql/sqlite/product_question.sql b/admin/sql/sqlite/product_question.sql
index 58f87d8..5e6d47d 100755
--- a/admin/sql/sqlite/product_question.sql
+++ b/admin/sql/sqlite/product_question.sql
@@ -20,6 +20,7 @@
SELECT *
FROM product_question AS product_question
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE 1 = 1
@@ -68,6 +69,7 @@
-- question
SELECT *
FROM product_question as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_question.user_id
WHERE product_question_id = :product_question_id LIMIT 1;
END
diff --git a/admin/sql/sqlite/product_review.sql b/admin/sql/sqlite/product_review.sql
index 8197c9a..e9080e3 100755
--- a/admin/sql/sqlite/product_review.sql
+++ b/admin/sql/sqlite/product_review.sql
@@ -19,8 +19,13 @@
)
BEGIN
- SELECT *
- FROM product_review AS product_review
+ SELECT product_review.*,user.*,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 prm
+ WHERE prm.product_review_id = product_review.product_review_id) as images
+
+ FROM product_review
+ LEFT JOIN user ON user.user_id = product_review.user_id
WHERE 1 = 1
@@ -69,6 +74,7 @@
-- review
SELECT *
FROM product_review as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN user on user.user_id = product_review.user_id
WHERE product_review_id = :product_review_id LIMIT 1;
END
diff --git a/admin/sql/sqlite/product_review_media.sql b/admin/sql/sqlite/product_review_media.sql
new file mode 100644
index 0000000..e8f1b34
--- /dev/null
+++ b/admin/sql/sqlite/product_review_media.sql
@@ -0,0 +1,122 @@
+-- Product reviews
+
+
+ CREATE PROCEDURE getAll(
+ -- variables
+ IN language_id INT,
+ IN site_id INT,
+ IN product_id INT,
+ IN product_review_id INT,
+ IN status INT,
+
+ -- pagination
+ IN start INT,
+ IN limit INT,
+
+ -- return
+ OUT fetch_all, -- orders
+ OUT fetch_one -- count
+ )
+ BEGIN
+
+ SELECT *
+ FROM product_review_media
+ INNER JOIN product_review ON product_review.product_review_id = product_review_media.product_review_id
+
+ WHERE 1 = 1
+
+ -- post
+ @IF isset(:product_id)
+ THEN
+ AND product_review_media.product_id = :product_id
+ END @IF
+
+
+ -- product_review
+ @IF isset(:product_review_id)
+ THEN
+ AND product_review_media.product_review_id = :product_review_id
+ END @IF
+
+ -- status
+ @IF isset(:status)
+ THEN
+ AND product_review.status = :status
+ END @IF
+
+
+ @SQL_LIMIT(:start, :limit);
+
+ SELECT count(*) FROM (
+
+ @SQL_COUNT(product_review_media.product_review_media_id, product_review_media) -- this takes previous query removes limit and replaces select columns with parameter product_review_media_id
+
+ ) as count;
+
+
+ END
+
+ -- Get product review
+
+ CREATE PROCEDURE get(
+ IN product_review_media_id INT,
+ OUT fetch_row,
+ )
+ BEGIN
+ -- review
+ SELECT *
+ FROM product_review_media as _ -- (underscore) _ means that data will be kept in main array
+ INNER JOIN product_review on product_review.product_review_id = product_review_media.product_review_id
+ WHERE product_review_media_id = :product_review_media_id LIMIT 1;
+
+ END
+
+ -- Add new product review
+
+ CREATE PROCEDURE add(
+ IN product_review_media ARRAY,
+ OUT insert_id
+ )
+ BEGIN
+
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ INSERT INTO product_review_media
+
+ ( @KEYS(:product_review_media) )
+
+ VALUES ( :product_review_media )
+
+ END
+
+ -- Edit product review
+
+ CREATE PROCEDURE edit(
+ IN product_review_media ARRAY,
+ IN id_product_review_media INT,
+ OUT affected_rows
+ )
+ BEGIN
+ -- allow only table fields and set defaults for missing values
+ @FILTER(:product_review_media, product_review_media);
+
+ UPDATE product_review_media
+
+ SET @LIST(:product_review_media)
+
+ WHERE product_review_media_id = :product_review_media_id
+
+ END
+
+ -- Delete product review
+
+ CREATE PROCEDURE delete(
+ IN product_review_media_id ARRAY,
+ OUT affected_rows
+ )
+ BEGIN
+
+ DELETE FROM product_review_media WHERE product_review_media_id IN (:product_review_media_id)
+
+ END
diff --git a/admin/sql/sqlite/setting.sql b/admin/sql/sqlite/setting.sql
index 539de10..86f6e38 100755
--- a/admin/sql/sqlite/setting.sql
+++ b/admin/sql/sqlite/setting.sql
@@ -43,8 +43,7 @@
VALUES ( :namespace, :key, :value, :site_id )
- ON DUPLICATE KEY
- UPDATE value = values(value);
+ ON CONFLICT(`site_id`, `namespace`, `key`) DO UPDATE SET `value` = :value;
END
diff --git a/admin/sql/sqlite/setting_content.sql b/admin/sql/sqlite/setting_content.sql
index f0ac823..9f1d4fd 100755
--- a/admin/sql/sqlite/setting_content.sql
+++ b/admin/sql/sqlite/setting_content.sql
@@ -42,8 +42,7 @@
VALUES ( :key, :value, :site_id , :language_id )
- ON DUPLICATE KEY
- UPDATE value = VALUES(value);
+ ON CONFLICT(`site_id`, `language_id`, `key`) DO UPDATE SET `value` = :value;
END
diff --git a/admin/sql/sqlite/site.sql b/admin/sql/sqlite/site.sql
index 1767219..74c7215 100755
--- a/admin/sql/sqlite/site.sql
+++ b/admin/sql/sqlite/site.sql
@@ -139,10 +139,12 @@
)
BEGIN
+ -- allow only table fields and set defaults for missing values
+ :site_data = @FILTER(:site, site);
UPDATE site
- SET @LIST(:site)
+ SET @LIST(:site_data)
WHERE site_id = :site_id
diff --git a/admin/sql/sqlite/stat.sql b/admin/sql/sqlite/stat.sql
index 5482d2d..4f04a35 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, orders.created_at, os.name, orders.order_status_id, orders.order_status_id as array_key
+ SELECT COUNT(*) AS count, DATE(created_at) as date, os.name, orders.order_status_id as array_key
FROM `order` AS orders
LEFT 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, orders.created_at, os.name;
+ GROUP BY orders.order_status_id, os.name, date;
END
CREATE PROCEDURE getCommentsCount(
@@ -162,7 +162,7 @@
END @IF
- GROUP BY comments.status, comments.created_at;
+ GROUP BY comments.status, comments.created_at, date;
END
@@ -184,7 +184,7 @@
-- reviews
- SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status,reviews.created_at, reviews.status as array_key FROM product_review AS reviews
+ SELECT COUNT(*) AS count, DATE(created_at) as date, reviews.status, reviews.status as array_key FROM product_review AS reviews
WHERE 1 = 1
@@ -210,7 +210,7 @@
END @IF
- GROUP BY reviews.status, reviews.created_at;
+ GROUP BY reviews.status, date;
END
CREATE PROCEDURE getQuestionsCount(
@@ -231,7 +231,7 @@
-- questions
- SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.created_at, questions.status as array_key FROM product_question AS questions
+ SELECT COUNT(*) AS count, DATE(created_at) as date, questions.status, questions.status as array_key FROM product_question AS questions
WHERE 1 = 1
@@ -257,7 +257,7 @@
END @IF
- GROUP BY questions.status, questions.created_at;
+ GROUP BY questions.status, date;
END
CREATE PROCEDURE getProductStockCount(
@@ -276,7 +276,7 @@
-- products
- SELECT COUNT(*) AS count, products.stock_status_id, products.created_at as array_key FROM product AS products
+ SELECT COUNT(*) AS count, products.stock_status_id, st.name as array_key FROM product AS products
LEFT JOIN stock_status AS st ON (products.stock_status_id = st.stock_status_id AND st.language_id = :language_id)
@@ -299,6 +299,6 @@
END @IF
- GROUP BY products.stock_status_id, products.created_at ORDER BY products.stock_status_id;
+ GROUP BY products.stock_status_id, st.name, products.created_at ORDER BY products.stock_status_id;
END
diff --git a/admin/template/components/notifications.tpl b/admin/template/components/notifications.tpl
old mode 100755
new mode 100644
index 8212931..1f1396d
--- a/admin/template/components/notifications.tpl
+++ b/admin/template/components/notifications.tpl
@@ -29,7 +29,7 @@ $count = $notificationComponent['count'] ?? 0;
@notifications [data-v-group-notification-*]|innerText = <?php
$name = '@@__data-v-group-notification-(*)__@@';
- if (isset($notification[$name])) echo ucfirst($notification[$name]);
+ if (isset($notification[$name])) echo Vvveb\humanReadable($notification[$name]);
?>
@@ -50,6 +50,9 @@ $count = $notificationComponent['count'] ?? 0;
$name = '@@__data-v-notification-(*)__@@';
$default = '@@__innerHtml__@@';
$path = str_replace('-', '.', $name);
+if ($path == 'count') {
+ echo $count;
+} else
if (isset($notifications) && $path) {
echo \Vvveb\arrayPath($notifications, $path);
} else echo $default;
diff --git a/admin/template/order/return-order.tpl b/admin/template/order/return-order.tpl
index b4a2adc..5e38a8b 100755
--- a/admin/template/order/return-order.tpl
+++ b/admin/template/order/return-order.tpl
@@ -1 +1 @@
-import(crud.tpl, {"type":"voucher"})
+import(crud.tpl, {"type":"return"})
diff --git a/app/component/breadcrumb.php b/app/component/breadcrumb.php
index 88d9150..2866788 100755
--- a/app/component/breadcrumb.php
+++ b/app/component/breadcrumb.php
@@ -68,10 +68,12 @@ class Breadcrumb extends ComponentBase {
if ($result) {
$breadcrumb = array_merge($breadcrumb, [
['text' => $result['name'], 'url' => url('product/category/index', $result)],
- ['text' => $slug, 'url' => false],
+ //['text' => $slug, 'url' => false],
]);
}
}
+
+ $breadcrumb[] = ['text' => $name, 'url' => false];
break;
//product category page
diff --git a/app/component/comments.php b/app/component/comments.php
index 9138d0d..34f2124 100755
--- a/app/component/comments.php
+++ b/app/component/comments.php
@@ -115,13 +115,13 @@ class Comments extends ComponentBase {
}
}
- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
+ //list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
return $results;
}
//called on each request
- function request(&$results) {
+ function request(&$results, $index = 0) {
//check for user pending comments
$slug = $this->options['slug'] ?? false;
$pendingComments = session($this->type, []);
@@ -132,6 +132,9 @@ class Comments extends ComponentBase {
$results['count'] += count($comments);
}
+ //for component event convention use `results` as function
+ list($results) = Event :: trigger(__CLASS__, 'results', $results);
+
return $results;
}
}
diff --git a/app/component/order.php b/app/component/order.php
index 29eef4b..a447448 100755
--- a/app/component/order.php
+++ b/app/component/order.php
@@ -68,16 +68,16 @@ class Order extends ComponentBase {
//$product['images'][] = ['image' => Images::image($product['image'], 'product')];
}
- $product['tax_formatted'] = $currency->format($product['tax'], '$');
+ $product['tax_formatted'] = $currency->format($product['tax']);
}
}
foreach ($results['total'] as $id => &$total) {
- $total['value_formatted'] = $currency->format($total['value'], '$');
+ $total['value_formatted'] = $currency->format($total['value']);
}
$order = &$results['order'];
- $order['total_formatted'] = $currency->format($order['total'], '$');
+ $order['total_formatted'] = $currency->format($order['total']);
$order['shipping_data'] = json_decode($order['shipping_data'], true);
$order['payment_data'] = json_decode($order['payment_data'], true);
diff --git a/app/component/post.php b/app/component/post.php
index 53f9cff..0dfc7b5 100755
--- a/app/component/post.php
+++ b/app/component/post.php
@@ -71,7 +71,7 @@ class Post extends ComponentBase {
}
//called on each request
- function request($results) {
+ function request($results, $index = 0) {
}
//called by editor on page save for each component on page
diff --git a/app/component/product.php b/app/component/product.php
index 577e090..bc8372d 100755
--- a/app/component/product.php
+++ b/app/component/product.php
@@ -32,16 +32,20 @@ use function Vvveb\url;
class Product extends ComponentBase {
public static $defaultOptions = [
- 'product_id' => 'url',
- 'slug' => 'url',
- 'status' => 1,
- 'language_id' => null,
- 'site_id' => null,
+ 'product_id' => 'url',
+ 'slug' => 'url',
+ 'status' => 1,
+ 'language_id' => null,
+ 'site_id' => null,
+ 'user_id' => null,
+ 'user_group_id' => null,
+ 'reviews' => true,
+ 'rating' => true,
+ 'promotion' => true,
];
function results() {
$product = new ProductSQL();
-
$results = $product->get($this->options);
if (isset($results['product_image'])) {
@@ -53,10 +57,10 @@ class Product extends ComponentBase {
$results['image']= Images::image($results['image'], 'product');
}
- $results['add-cart-url'] = url('cart/cart/add', ['product_id' => $results['product_id']]);
- $results['buy-now-url'] = url('checkout/checkout/index', ['product_id' => $results['product_id']]);
- $results['wishlist-url'] = url('cart/wishlist/add', ['product_id' => $results['product_id']]);
- $results['compare-url'] = url('cart/compare/add', ['product_id' => $results['product_id']]);
+ $results['add_cart_url'] = url('cart/cart/add', ['product_id' => $results['product_id']]);
+ $results['buy_url'] = url('checkout/checkout/index', ['product_id' => $results['product_id']]);
+ $results['add_wishlist_url'] = url('user/wishlist/add', ['product_id' => $results['product_id']]);
+ $results['add_compare_url'] = url('cart/compare/add', ['product_id' => $results['product_id']]);
$results['manufacturer_url'] = url('product/manufacturer/index', ['slug' => $results['manufacturer_slug']]);
$results['vendor_url'] = url('product/vendor/index', ['slug' => $results['vendor_slug']]);
@@ -65,6 +69,13 @@ class Product extends ComponentBase {
$results['price_tax'] = $tax->addTaxes($results['price'], $results['tax_type_id']);
$results['price_tax_formatted'] = $currency->format($results['price_tax']);
$results['price_formatted'] = $currency->format($results['price']);
+
+ if ($results['promotion']) {
+ $results['promotion_tax'] = $tax->addTaxes($results['promotion'], $results['tax_type_id']);
+ $results['promotion_tax_formatted'] = $currency->format($results['promotion_tax']);
+ $results['promotion_formatted'] = $currency->format($results['promotion']);
+ $results['promotion_discount'] = 100 - ceil($results['promotion'] * 100 / $results['price']);
+ }
//$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_type_id'], $this->config->get('config_tax')), $this->session->data['currency']);
diff --git a/app/component/products.php b/app/component/products.php
index d04488e..9ac7f7f 100755
--- a/app/component/products.php
+++ b/app/component/products.php
@@ -41,11 +41,11 @@ class Products extends ComponentBase {
'type' => 'product',
'parent' => null,
'manufacturer_id' => NULL,
- 'vendor_id' => NULL,
+ 'vendor_id' => NULL,
'order_by' => NULL,
'direction' => ['url', 'asc', 'desc'],
- 'taxonomy_item_id' => NULL,
- 'include_image_gallery' => true,
+ 'taxonomy_item_id' => NULL,
+ 'image_gallery' => true,
'product_id' => [],
'search' => null,
'slug' => null,
@@ -120,13 +120,13 @@ class Products extends ComponentBase {
//rfc
$product['pubDate'] = date('r', strtotime($product['created_at']));
- $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']] + $language;
- $product['url'] = url('product/product/index', $url);
- $product['add-cart-url'] = url('cart/cart/add', ['product_id' => $product['product_id']]);
- $product['buy-now-url'] = url('checkout/checkout/index', ['product_id' => $product['product_id']]);
- $product['wishlist-url'] = url('cart/wishlist/add', ['product_id' => $product['product_id']]);
- $product['compare-url'] = url('cart/compare/add', ['product_id' => $product['product_id']]);
- $product['full-url'] = url('product/product/index', $url + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']);
+ $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']] + $language;
+ $product['url'] = url('product/product/index', $url);
+ $product['add_cart_url'] = url('cart/cart/add', ['product_id' => $product['product_id']]);
+ $product['buy_url'] = url('checkout/checkout/index', ['product_id' => $product['product_id']]);
+ $product['add_wishlist_url'] = url('user/wishlist/add', ['product_id' => $product['product_id']]);
+ $product['add_compare_url'] = url('cart/compare/add', ['product_id' => $product['product_id']]);
+ $product['full-url'] = url('product/product/index', $url + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']);
$product['price_tax'] = $tax->addTaxes($product['price'], $product['tax_type_id']);
$product['price_tax_formatted'] = $currency->format($product['price_tax']);
diff --git a/app/component/reviews.php b/app/component/reviews.php
index 6e050bf..63cb908 100755
--- a/app/component/reviews.php
+++ b/app/component/reviews.php
@@ -21,6 +21,8 @@
*/
namespace Vvveb\Component;
+use Vvveb\Sql\Product_Review_MediaSQL;
+use Vvveb\System\Images;
class Reviews extends Comments {
protected $type = 'review';
@@ -30,12 +32,44 @@ class Reviews extends Comments {
protected $model = 'product_review';
public static $defaultOptions = [
- 'product_id' => 'url',
- 'slug' => 'url',
- 'post_title' => null, //include post title (for recent reviews etc)
- 'status' => 1, //approved reviews
- 'start' => 0,
- 'limit' => 10,
- 'order' => 'asc', //desc
+ 'product_id' => 'url',
+ 'user_id' => NULL,
+ 'status' => 1, //approved reviews
+ 'start' => 0,
+ 'limit' => 10,
+ 'image_size' => 'thumb',
+ 'order' => 'asc', //desc
];
+
+ function results() {
+ $results = parent::results();
+
+ //review images
+ foreach ($results['product_review'] as $id => &$review) {
+ if (isset($review['images'])) {
+ $review['images'] = json_decode($review['images'], true);
+
+ foreach ($review['images'] as &$image) {
+ $image['thumb'] = Images::image($image['image'], 'product', $this->options['image_size']);
+ $image['image'] = Images::image($image['image'], 'product');
+ }
+ }
+ }
+
+ //all product reviews images
+ $media = new Product_Review_MediaSQL();
+ $gallery = $media->getAll($this->options + ['status'=> 1])['product_review_media'] ?? [];
+
+ if ($gallery) {
+ //$gallery = Images::images($gallery, 'product', $this->options['image_size']);
+ foreach ($gallery as &$image) {
+ $image['thumb'] = Images::image($image['image'], 'product', $this->options['image_size']);
+ $image['image'] = Images::image($image['image'], 'product');
+ }
+ }
+
+ $results['images'] = $gallery;
+
+ return $results;
+ }
}
diff --git a/app/component/user/address.php b/app/component/user/address.php
index 9e9dfe9..7b94293 100755
--- a/app/component/user/address.php
+++ b/app/component/user/address.php
@@ -59,6 +59,6 @@ class Address extends ComponentBase {
}
//called on each request
- function request($results) {
+ function request($results, $index = 0) {
}
}
diff --git a/app/component/user/wishlist.php b/app/component/user/wishlist.php
index f50a96f..133f00c 100644
--- a/app/component/user/wishlist.php
+++ b/app/component/user/wishlist.php
@@ -59,6 +59,6 @@ class Wishlist extends ComponentBase {
}
//called on each request
- function request($results) {
+ function request($results, $index = 0) {
}
}
diff --git a/app/controller/base.php b/app/controller/base.php
index 02424e8..3c7f314 100755
--- a/app/controller/base.php
+++ b/app/controller/base.php
@@ -154,6 +154,7 @@ class Base {
$this->global['site_id'] = SITE_ID ?? 1;
$this->global['user_id'] = $user['user_id'] ?? false;
+ $this->global['user_group_id'] = $user['user_group_id'] ?? 1;
$this->global['site'] = $site;
$this->global['user'] = $user ?? [];
@@ -169,12 +170,20 @@ class Base {
$view = View :: getInstance();
if ($errors = $this->session->get('errors')) {
- $view->errors[] = $errors;
+ if (is_array($errors)) {
+ $view->errors = ($view->errors ?? []) + $errors;
+ } else {
+ $view->errors['session'] = $errors;
+ }
$this->session->delete('errors');
}
if ($success = $this->session->get('success')) {
- $view->success[] = $success;
+ if (is_array($success)) {
+ $view->success = ($view->success ?? []) + $success;
+ } else {
+ $view->success['session'] = $success;
+ }
$this->session->delete('success');
}
diff --git a/app/controller/cart/cart.php b/app/controller/cart/cart.php
index fb11607..88612de 100755
--- a/app/controller/cart/cart.php
+++ b/app/controller/cart/cart.php
@@ -54,6 +54,17 @@ class Cart extends Base {
$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);
diff --git a/app/controller/content/post.php b/app/controller/content/post.php
index b60df6f..6e1d95b 100755
--- a/app/controller/content/post.php
+++ b/app/controller/content/post.php
@@ -60,7 +60,7 @@ class Post extends Base {
$comments = $this->session->get('comments', []);
$comments[$comment['slug']][$comment['comment_id']] = $comment;
- $this->session->set('comments', $comments);
+ $this->session->set('comment', $comments);
$this->view->success[] = __('Comment was posted!');
} else {
diff --git a/app/controller/product/product.php b/app/controller/product/product.php
index 240039b..98f92e4 100755
--- a/app/controller/product/product.php
+++ b/app/controller/product/product.php
@@ -105,6 +105,7 @@ class Product extends Base {
$this->request->get['product_id'] = $languageContent['product_id'];
$this->request->request['product_id'] = $languageContent['product_id'];
+ $this->request->get['name'] = $languageContent['name'];
$this->request->request['name'] = $languageContent['name'];
if (isset($languageContent['template']) && $languageContent['template']) {
@@ -124,3 +125,4 @@ class Product extends Base {
}
}
}
+
diff --git a/app/controller/user/login.php b/app/controller/user/login.php
index 56238ab..aab2f2e 100755
--- a/app/controller/user/login.php
+++ b/app/controller/user/login.php
@@ -29,12 +29,20 @@ class Login extends \Vvveb\Controller\Base {
$view = $this->view;
if ($errors = $this->session->get('errors')) {
- $view->errors['login'] = $errors;
+ if (is_array($errors)) {
+ $view->errors = ($view->errors ?? []) + $errors;
+ } else {
+ $view->errors['login'] = $errors;
+ }
$this->session->delete('errors');
}
if ($success = $this->session->get('success')) {
- $view->success['login'] = $success;
+ if (is_array($success)) {
+ $view->success = ($view->success ?? []) + $success;
+ } else {
+ $view->success['login'] = $success;
+ }
$this->session->delete('success');
}
diff --git a/app/controller/user/reset.php b/app/controller/user/reset.php
old mode 100755
new mode 100644
index 6caec80..e5f08e9
--- a/app/controller/user/reset.php
+++ b/app/controller/user/reset.php
@@ -44,7 +44,7 @@ class Reset extends Base {
if ($password && $admin) {
if (User::update(['token' => '', 'password' => $password], ['username' => $user, 'token' => $token])) {
$success = __('Password was reset!');
- $this->view->success[] = $success;
+ $this->view->success['get'] = $success;
$this->session->set('success', $success);
$this->redirect('/user/login');
//header('Location: ' . url(['module' => 'user/login', 'success' => $success]));
@@ -89,7 +89,7 @@ class Reset extends Base {
$reset_url = url('user/reset/reset', [
'token' => $token,
- 'user' => $adminData['user'],
+ 'user' => $adminData['username'],
'host' => $site['host'] ?? false,
'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',
]);
@@ -104,7 +104,7 @@ class Reset extends Base {
if (email($adminData['email'], __('Password reset'),'user/reset', $data)) {
$success = __('A reset email was sent, please use it to reset your password!');
$this->view->success[] = $success;
- $this->session->set('success', $success);
+ $this->session->set('success', ['login' => $success]);
$this->redirect('/user/login');
} else {
$this->view->errors[] = __('Error sending reset email!');
diff --git a/app/controller/user/signup.php b/app/controller/user/signup.php
index 75f340b..9eaec89 100755
--- a/app/controller/user/signup.php
+++ b/app/controller/user/signup.php
@@ -42,13 +42,13 @@ class Signup extends \Vvveb\Controller\Base {
$userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];
$result = User::add($userInfo);
- $this->view->errors['signup'] = [];
+ $this->view->errors['login'] = [];
if ($result) {
if (is_array($result)) {
$message = __('User created!');
- $this->session->set('success', ['signup' => $message]);
- $this->view->success['signup'][] = $message;
+ $this->session->set('success', ['login' => $message]);
+ $this->view->success['login'][] = $message;
$user_id = $result['user'];
$this->request->request['user_id'] = $user_id;
@@ -58,24 +58,23 @@ class Signup extends \Vvveb\Controller\Base {
$error = __('Error sending account creation mail!');
if (! email([$userInfo['email'], $site['admin-email']], __('Your account has been created!'), 'user/signup', $userInfo)) {
- $this->session->set('errors', ['signup' => $error]);
+ $this->session->set('errors', ['login' => $error]);
$this->view->errors[] = $error;
}
} catch (\Exception $e) {
if (DEBUG) {
$error .= "\n" . $e->getMessage();
}
- $this->session->set('errors', ['signup' => $error]);
- $this->view->errors['signup'] = $error;
+ $this->session->set('errors', ['login' => $error]);
+ $this->view->errors['login'] = $error;
}
return $this->redirect('user/index');
- //header('Location: /user');
} else {
- $this->view->errors['signup'] = __('This email is already in use. Please use another one."');
+ $this->view->errors['login'] = __('This email is already in use. Please use another one.');
}
} else {
- $this->view->errors['signup'] = __('Error creating user!');
+ $this->view->errors['login'] = __('Error creating user!');
}
}
}
diff --git a/app/controller/user/wishlist.php b/app/controller/user/wishlist.php
index 527b6c7..eb8e1ca 100755
--- a/app/controller/user/wishlist.php
+++ b/app/controller/user/wishlist.php
@@ -26,10 +26,9 @@ use Vvveb\System\User\User;
class Wishlist extends Base {
function index() {
- $user = User::current();
+ }
- if (! $user) {
- $this->redirect('/user/login');
- }
+ function add() {
+ $productId = $this->request->request['product_id'];
}
}
diff --git a/app/sql/mysqli/product.sql b/app/sql/mysqli/product.sql
index 623d2fe..4750a0d 100755
--- a/app/sql/mysqli/product.sql
+++ b/app/sql/mysqli/product.sql
@@ -2,7 +2,6 @@
import(/admin/product.sql);
-
-- get all languages content
CREATE PROCEDURE getContent(
diff --git a/app/sql/mysqli/product_review_media.sql b/app/sql/mysqli/product_review_media.sql
new file mode 100755
index 0000000..5def885
--- /dev/null
+++ b/app/sql/mysqli/product_review_media.sql
@@ -0,0 +1,5 @@
+-- Product review media
+
+ -- get common code from admin
+ import(/admin/product_review_media.sql);
+
diff --git a/app/sql/pgsql/product_review_media.sql b/app/sql/pgsql/product_review_media.sql
new file mode 100755
index 0000000..5def885
--- /dev/null
+++ b/app/sql/pgsql/product_review_media.sql
@@ -0,0 +1,5 @@
+-- Product review media
+
+ -- get common code from admin
+ import(/admin/product_review_media.sql);
+
diff --git a/app/sql/sqlite/product_review_media.sql b/app/sql/sqlite/product_review_media.sql
new file mode 100755
index 0000000..5def885
--- /dev/null
+++ b/app/sql/sqlite/product_review_media.sql
@@ -0,0 +1,5 @@
+-- Product review media
+
+ -- get common code from admin
+ import(/admin/product_review_media.sql);
+
diff --git a/app/template/cart/cart.tpl b/app/template/cart/cart.tpl
index 555fddc..d4e10a6 100755
--- a/app/template/cart/cart.tpl
+++ b/app/template/cart/cart.tpl
@@ -8,6 +8,9 @@ import(common.tpl)
@cart-product|before = <?php
$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) {
?>
@@ -15,14 +18,14 @@ if(is_array($products)) foreach ($products as $index => $product) {
//@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 img[data-v-cart-product-image]|src = $product['image']
//catch all data attributes
- @cart-product [data-v-cart-product-*]|innerText = <?php echo Vvveb\escHtml( $product['@@__data-v-cart-product-(*)__@@'] ?? '' )?>
- @cart-product a[data-v-cart-product-*]|href = $product['@@__data-v-cart-product-(*)__@@']
- @cart-product img[data-v-cart-product-*]|src = $product['@@__data-v-cart-product-(*)__@@']
- @cart-product input[data-v-cart-product-*]|value = <?php echo Vvveb\escAttr( $product['@@__data-v-cart-product-(*)__@@'] )?>
+ @cart-product [data-v-cart-product-*]|innerText = $product['@@__data-v-cart-product-(*)__@@']
+ @cart-product a[data-v-cart-product-*]|href = $product['@@__data-v-cart-product-(*)__@@']
+ @cart-product img[data-v-cart-product-*]|src = $product['@@__data-v-cart-product-(*)__@@']
+ @cart-product input[data-v-cart-product-*]|value = $product['@@__data-v-cart-product-(*)__@@']
@cart-product|after = <?php }?>
@@ -33,12 +36,15 @@ if(is_array($products)) foreach ($products as $index => $product) {
@total|before = <?php
$totals = $this->cart['totals'];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$totals = empty($totals) ? $_default : $totals;
+
if(is_array($totals)) foreach ($totals as $index => $total) {
?>
//catch all data attributes
- @total [data-v-cart-total-*]|innerText = $total['@@__data-v-cart-total-(*)__@@']
- @total a[data-v-cart-total-*]|href = $total['@@__data-v-cart-total-(*)__@@']
+ @total [data-v-cart-total-*]|innerText = $total['@@__data-v-cart-total-(*)__@@']
+ @total a[data-v-cart-total-*]|href = $total['@@__data-v-cart-total-(*)__@@']
@total input[data-v-cart-total-*]|value = $total['@@__data-v-cart-total-(*)__@@']
@total|after = <?php }?>
diff --git a/app/template/common.tpl b/app/template/common.tpl
index b8e1baf..7a88df0 100755
--- a/app/template/common.tpl
+++ b/app/template/common.tpl
@@ -20,11 +20,15 @@ import(notifications.tpl)
import(editor.tpl)
import(pagination.tpl)
-html|addNewAttribute = <?php if (isset($_COOKIE['theme'])) {
+html|addNewAttribute = <?php
+if (isset($_COOKIE['theme'])) {
echo 'data-bs-theme="';
if ($_COOKIE['theme'] == 'dark') echo 'dark'; else if ($_COOKIE['theme'] == 'light') echo 'light';else echo 'auto';
echo '"';
-} ?>
+}
+
+$vvveb_is_page_edit = Vvveb\isEditor();
+?>
[data-v-global-*] = <?php
$name = '@@__data-v-global-(*)__@@';
@@ -56,4 +60,4 @@ head > link[hreflang]|before = <?php
head > link[hreflang]|after = <?php
}
}
-?>
+?>
\ No newline at end of file
diff --git a/app/template/components.tpl b/app/template/components.tpl
index e264c1e..19dcba2 100755
--- a/app/template/components.tpl
+++ b/app/template/components.tpl
@@ -1,13 +1,13 @@
import(components/categories.tpl, [data-v-component-categories])
import(components/categories/pages.tpl, [data-v-component-categories-pages])
import(components/menu.tpl, [data-v-component-menu])
+import(components/product.tpl, [data-v-component-product])
import(components/products.tpl, [data-v-component-products])
import(components/posts.tpl, [data-v-component-posts])
import(components/comments.tpl, [data-v-component-comments])
import(components/reviews.tpl, [data-v-component-reviews])
import(components/questions.tpl, [data-v-component-questions])
import(components/post.tpl, [data-v-component-post])
-import(components/product.tpl, [data-v-component-product])
import(components/filters.tpl, [data-v-component-filters])
import(components/cart.tpl, [data-v-component-cart])
import(components/search.tpl, [data-v-component-search])
@@ -30,5 +30,4 @@ import(components/orders.tpl, [data-v-component-orders])
import(components/order.tpl, [data-v-component-order])
import(components/checkout/payment.tpl, [data-v-component-checkout-payment])
import(components/checkout/shipping.tpl, [data-v-component-checkout-shipping])
-import(components/site.tpl, [data-v-component-site])
-
+import(components/site.tpl, [data-v-component-site])
\ No newline at end of file
diff --git a/app/template/components/breadcrumb.tpl b/app/template/components/breadcrumb.tpl
index 19c60ed..5333099 100755
--- a/app/template/components/breadcrumb.tpl
+++ b/app/template/components/breadcrumb.tpl
@@ -16,6 +16,9 @@ $_pagination_limit = isset($breadcrumb['limit']) ? $breadcrumb['limit'] : 5;
@item|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$breadcrumb['breadcrumb'] = empty($breadcrumb['breadcrumb']) ? $_default : $breadcrumb['breadcrumb'];
+
if($breadcrumb && is_array($breadcrumb['breadcrumb'])) {
foreach ($breadcrumb['breadcrumb'] as $index => $breadcrumb) {?>
diff --git a/app/template/components/cart.tpl b/app/template/components/cart.tpl
index 7996770..9f36c14 100755
--- a/app/template/components/cart.tpl
+++ b/app/template/components/cart.tpl
@@ -19,6 +19,8 @@ $products = $cart['products'] ?? [];
[data-v-component-cart] [data-v-cart-cart-*]|innerText = $cart['@@__data-v-cart-cart-(*)__@@']
@cart-product|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'image' => '#']] : false;
+$products = empty($products) ? $_default : $products;
if($products) {
foreach ($products as $index => $product) { ?>
@@ -50,6 +52,9 @@ if($products) {
@total|before = <?php
$totals = $cart['totals'] ?? [];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$totals = empty($totals) ? $_default : $totals;
+
if(is_array($totals)) foreach ($totals as $index => $total) {
?>
diff --git a/app/template/components/checkout/payment.tpl b/app/template/components/checkout/payment.tpl
index 780a6fa..3a258fa 100755
--- a/app/template/components/checkout/payment.tpl
+++ b/app/template/components/checkout/payment.tpl
@@ -14,6 +14,9 @@ $_pagination_limit = isset($payments['limit']) ? $payments['limit'] : 5;
@payment|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['payment_id' => 1]] : false;
+$payments['payment'] = empty($payments['payment']) ? $_default : $payments['payment'];
+
if($payments && is_array($payments['payment'])) {
foreach ($payments['payment'] as $index => $payment) {?>
diff --git a/app/template/components/checkout/shipping.tpl b/app/template/components/checkout/shipping.tpl
index e465379..78f0d68 100755
--- a/app/template/components/checkout/shipping.tpl
+++ b/app/template/components/checkout/shipping.tpl
@@ -14,6 +14,9 @@ $_pagination_limit = isset($shippings['limit']) ? $shippings['limit'] : 5;
@shipping|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['shipping_id' => 1]] : false;
+$shippings['shipping'] = empty($shippings['shipping']) ? $_default : $shippings['shipping'];
+
if($shippings && is_array($shippings['shipping'])) {
foreach ($shippings['shipping'] as $index => $shipping) {?>
diff --git a/app/template/components/comments.tpl b/app/template/components/comments.tpl
index 6e95bd7..f58a70a 100755
--- a/app/template/components/comments.tpl
+++ b/app/template/components/comments.tpl
@@ -14,8 +14,12 @@ $limit = isset($comments['limit']) ? $comments['limit'] : 5;
@comment|before = <?php
-if($comments && is_array($comments['comment'])) {
- foreach ($this->_component['comments'][$_comments_idx]['comment'] as $index => $comment) {?>
+$_comments = $comments['comment'] ?? [];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['comment_id' => 1, 'content' => '']] : false;
+$_comments = empty($_comments) ? $_default : $_comments;
+
+if($_comments && is_array($_comments)) {
+ foreach ($_comments as $index => $comment) {?>
@comment|data-comment_id = $comment['comment_id']
@@ -26,6 +30,7 @@ if($comments && is_array($comments['comment'])) {
@comment [data-v-comment-content] = <?php echo $comment['content'];?>
@comment img[data-v-comment-*]|src = $comment['@@__data-v-comment-(*)__@@']
+ @comment img[data-v-comment-*]|width = <?php echo $comment['size'] ?? '60';?>
@comment [data-v-comment-*]|innerText = $comment['@@__data-v-comment-(*)__@@']
@@ -34,4 +39,4 @@ if($comments && is_array($comments['comment'])) {
@comment|after = <?php
}
}
-?>
+?>
\ No newline at end of file
diff --git a/app/template/components/currency.tpl b/app/template/components/currency.tpl
index b23729d..f67cbdf 100755
--- a/app/template/components/currency.tpl
+++ b/app/template/components/currency.tpl
@@ -16,6 +16,9 @@ $_pagination_limit = isset($currencies['limit']) ? $currencies['limit'] : 5;
[data-v-component-currency] [data-v-currency-info-*] = $current_component['active']['@@__data-v-currency-info-(*)__@@']
@currency|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$currencies = empty($currencies) ? $_default : $currencies;
+
if($currencies) {
foreach ( $currencies as $index => $currency) { ?>
diff --git a/app/template/components/language.tpl b/app/template/components/language.tpl
index f4277b3..e08ea40 100755
--- a/app/template/components/language.tpl
+++ b/app/template/components/language.tpl
@@ -12,6 +12,9 @@ if(isset($this->_component['language']) && $this->_component['language'][$_langu
[data-v-component-language] img[data-v-language-info-*]|src = $language['active']['@@__data-v-language-info-(*)__@@']
@language|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$language['language'] = empty($language['language']) ? $_default : $language['language'];
+
if (is_array($language['language'])) {
foreach ($language['language'] as $index => $lang) {?>
@@ -35,4 +38,4 @@ if(isset($this->_component['language']) && $this->_component['language'][$_langu
[data-v-component-language]|append = <?php
}
-?>
+?>
\ No newline at end of file
diff --git a/app/template/components/menu.tpl b/app/template/components/menu.tpl
index 606092f..7871703 100755
--- a/app/template/components/menu.tpl
+++ b/app/template/components/menu.tpl
@@ -11,8 +11,6 @@
if (isset($_menu_idx)) $_menu_idx++; else $_menu_idx = 0;
$_categories = [];
-$vvveb_is_page_edit = Vvveb\isEditor();
-
if (isset($this->_component['menu']) && isset($this->_component['menu'][$_menu_idx])) {
//$_pagination_count = $this->menu[$_menu_idx]['count'];
//$_pagination_limit = $this->categories[$_menu_idx]['limit'];
diff --git a/app/template/components/orders.tpl b/app/template/components/orders.tpl
index d815ebc..58f7627 100755
--- a/app/template/components/orders.tpl
+++ b/app/template/components/orders.tpl
@@ -14,6 +14,9 @@ $_pagination_limit = isset($ordercomp['limit']) ? $ordercomp['limit'] : 5;
@order|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$ordercomp['order'] = empty($ordercomp['order']) ? $_default : $ordercomp['order'];
+
if($ordercomp && is_array($ordercomp['order'])) {
foreach ($ordercomp['order'] as $index => $order) {?>
diff --git a/app/template/components/product.tpl b/app/template/components/product.tpl
index 1c2bdcb..1fa2db4 100755
--- a/app/template/components/product.tpl
+++ b/app/template/components/product.tpl
@@ -28,31 +28,29 @@ $_pagination_limit = isset($product['limit']) ? $product['limit'] : 5;
//manual echo to avoid html escape
@product [data-v-product-content] = <?php echo $product['content'];?>
+@product button[data-v-product-*]|formaction = $product['@@__data-v-product-(*)__@@']
+@product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']
+
+
@product img[data-v-product-main-image]|src = <?php echo $product['image'];?>
@product a[data-v-product-main-image]|href = <?php echo reset($product['images'])['image'];?>
-
@images [data-v-product-image]|deleteAllButFirstChild
-@product a[data-v-product-cart-url]|href = $product['add-cart-url']
-@product a[data-v-product-buy-url]|href = $product['buy-now-url']
-
-@product button[data-v-product-cart-url]|formaction = $product['add-cart-url']
-@product button[data-v-product-buy-url]|formaction = $product['buy-now-url']
-@product button[data-v-product-wishlist-url]|formaction = $product['wishlist-url']
-@product button[data-v-product-compare-url]|formaction = $product['compare-url']
-
-
@images [data-v-product-image]|before = <?php
-if(isset($product['images']) && is_array($product['images'])) {
+$_images = $product['images'] ?? [];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_image_id' => 1, 'image' => '']] : false;
+$_images = empty($_images) ? $_default : $_images;
+
+if($_images) {
$i = 0;
- foreach ($product['images'] as $index => $image) { ?>
+ foreach ($_images as $index => $_image) { ?>
@images [data-bs-slide-to]|data-bs-slide-to = <?php echo $i;?>
- @images img[data-v-product-image-src]|src = $image['image']
- @images [data-v-product-image-background-image]|style = <?php echo 'background-image: url(\'' . $image['image'] . '\');';?>
- @images a[data-v-product-image-src]|href = $image['image']
- @images img[data-v-product-image-src]|data-v-id = $image['id']
+ @images img[data-v-product-image-src]|src = $_image['image']
+ @images [data-v-product-image-background-image]|style = <?php echo 'background-image: url(\'' . $_image['image'] . '\');';?>
+ @images a[data-v-product-image-src]|href = $_image['image']
+ @images img[data-v-product-image-src]|data-v-id = $_image['product_image_id']
@images img[data-v-product-image-src]|data-v-type = 'product_image'
@images [data-v-product-image]|after = <?php
diff --git a/app/template/components/product/attributes.tpl b/app/template/components/product/attributes.tpl
index b7efbac..2cbb30b 100755
--- a/app/template/components/product/attributes.tpl
+++ b/app/template/components/product/attributes.tpl
@@ -14,6 +14,9 @@ $_pagination_limit = isset($attributes['limit']) ? $attributes['limit'] : 5;
@attribute [data-v-attribute]|deleteAllButFirstChild
@attribute|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['attribute_id' => 1]] : false;
+$attributes['attribute'] = empty($attributes['attribute']) ? $_default : $attributes['attribute'];
+
if($attributes && is_array($attributes['attribute'])) {
$group = false;
foreach ($attributes['attribute'] as $index => $attribute) {?>
diff --git a/app/template/components/product/manufacturers.tpl b/app/template/components/product/manufacturers.tpl
index 1c6b8d5..5f6b26b 100755
--- a/app/template/components/product/manufacturers.tpl
+++ b/app/template/components/product/manufacturers.tpl
@@ -14,6 +14,9 @@ $_pagination_limit = isset($manufacturers['limit']) ? $manufacturers['limit'] :
@manufacturer|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$manufacturers['manufacturer'] = empty($manufacturers['manufacturer']) ? $_default : $manufacturers['manufacturer'];
+
if($manufacturers && is_array($manufacturers['manufacturer'])) {
foreach ($manufacturers['manufacturer'] as $index => $manufacturer) {?>
diff --git a/app/template/components/product/options.tpl b/app/template/components/product/options.tpl
index 7c38429..0177307 100755
--- a/app/template/components/product/options.tpl
+++ b/app/template/components/product/options.tpl
@@ -18,6 +18,28 @@ $_pagination_limit = isset($options['limit']) ? $options['limit'] : 5;
@option|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [
+ 1 => [
+ 'product_option_id' => 1,
+ 'option_id' => 1,
+ 'required' => 1,
+ 'type' => 'radio',
+ 'values' => [ 0 =>
+ [
+ 'product_option_value_id' => 1,
+ 'product_option_id' => 1,
+ 'product_id' => 1,
+ 'option_id' => 1,
+ 'option_value_id' => 1,
+ 'price' => 1,
+ 'image' => 'img',
+ ]
+ ]
+ ]
+] : false;
+
+$options = empty($options) ? $_default : $options;
+
if($options && is_array($options)) {
foreach ($options as $index => $option) {?>
diff --git a/app/template/components/product/subscriptions.tpl b/app/template/components/product/subscriptions.tpl
index e87e458..046e615 100755
--- a/app/template/components/product/subscriptions.tpl
+++ b/app/template/components/product/subscriptions.tpl
@@ -14,8 +14,14 @@ $_pagination_limit = isset($subscriptions['limit']) ? $subscriptions['limit'] :
@subscription|before = <?php
-if($subscriptions && is_array($subscriptions['product_subscription'])) {
- foreach ($subscriptions['product_subscription'] as $index => $subscription) {?>
+//if page loaded in editor then set a fist empty product if there are no products
+//to render an empty product to avoid losing the html on edit
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$product_subscription = empty($subscriptions['product_subscription']) ? $_default : $subscriptions['product_subscription'];
+
+
+if($product_subscription) {
+ foreach ($product_subscription as $index => $subscription) {?>
@subscription [data-v-subscription-*]|innerText = $subscription['@@__data-v-subscription-(*)__@@']
diff --git a/app/template/components/products.tpl b/app/template/components/products.tpl
index 4ccee66..926911e 100755
--- a/app/template/components/products.tpl
+++ b/app/template/components/products.tpl
@@ -11,53 +11,51 @@
//use a counter to know which component instance we need to use if there are more than one component on page
if (isset($_products_idx)) $_products_idx++; else $_products_idx = 0;
$previous_component = isset($current_component)?$current_component:null;
- $products = $current_component = $this->_component['products'][$_products_idx] ?? [];
+ $_products = $current_component = $this->_component['products'][$_products_idx] ?? [];
- $count = $products['count'] ?? 0;
- $limit = isset($products['limit'])? $products['limit'] : 5;
+ $count = $_products['count'] ?? 0;
+ $limit = isset($_products['limit'])? $_products['limit'] : 5;
?>
-@products [data-v-products-category] = <?php $_category = current($products['products']);echo $_category['category'];?>
-@products [data-v-products-count] = <?php echo $products['count'] ?? ''?>
-@products [data-v-products-manufacturer] = <?php $_manufacturer = current($products['products']);echo $_manufacturer['manufacturer'];?>
+@products [data-v-products-category] = <?php $_category = current($_products['products']);echo $_category['category'];?>
+@products [data-v-products-count] = <?php echo $_products['count'] ?? ''?>
+@products [data-v-products-manufacturer] = <?php $_manufacturer = current($_products['products']);echo $_manufacturer['manufacturer'];?>
@product|before = <?php
//if page loaded in editor then set a fist empty product if there are no products
//to render an empty product to avoid losing the html on edit
-$vvveb_is_page_edit = Vvveb\isEditor();
$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
//$_default = [0 => []];
-$_products = empty($products['products']) ? $_default : $products['products'];
+$_products = empty($_products['products']) ? $_default : $_products['products'];
if ($_products) {
- foreach ($_products as $index => $product) {
- ?>
+ foreach ($_products as $index => $_product) { ?>
- @product [data-v-product-*]|innerText = $product['@@__data-v-product-(*)__@@']
- @product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']
+ @product [data-v-product-*]|innerText = $_product['@@__data-v-product-(*)__@@']
+ @product a[data-v-product-*]|href = $_product['@@__data-v-product-(*)__@@']
//editor attributes
- @product|data-v-id = $product['product_id']
+ @product|data-v-id = $_product['product_id']
@product|data-v-type = 'product'
//title attributes
- @product [data-v-product-alt]|alt = $product['name']
+ @product [data-v-product-alt]|alt = $_product['name']
- @product [data-product_id]|data-product_id = $product['product_id']
+ @product [data-product_id]|data-product_id = $_product['product_id']
//url
- @product [data-v-product-url]|title = $product['name']
- @product a[data-v-product-url]|href = $product['url']
+ @product [data-v-product-url]|title = $_product['name']
+ @product a[data-v-product-url]|href = $_product['url']
//image
- //@product [data-v-product-image]|src = $product['images'][0]['image']
- //@product [data-v-product-image]|data-v-id = $product['images'][0]['id']
+ //@product [data-v-product-image]|src = $_product['images'][0]['image']
+ //@product [data-v-product-image]|data-v-id = $_product['images'][0]['id']
//@product [data-v-product-image]|data-v-type = 'product_image'
@product [data-v-product-image]|src = <?php
- if (isset($product['image'])) {
- $image = $product['image'] ?? '';
+ if (isset($_product['image'])) {
+ $image = $_product['image'] ?? '';
//$size = '@@__data-v-product-image__@@';
$size = '@@__data-v-size__@@';
if ($size) {
@@ -69,21 +67,21 @@ if ($_products) {
}
?>
- @product [data-v-product-image-url] = $product['image']
+ @product [data-v-product-image-url] = $_product['image']
//@product [data-v-product-image]|data-v-id = 'image'
//@product [data-v-product-image]|data-v-type = 'product_image'
//usually used for second image to show hover [data-v-product-image-0] [data-v-product-image-1]
- //@product [data-v-product-image-*]|src = $product['images']['@@__data-v-product-image-(\d+)__@@']['image']
+ //@product [data-v-product-image-*]|src = $_product['images']['@@__data-v-product-image-(\d+)__@@']['image']
@product [data-v-product-image-*]|src = <?php
//$size = '@@__data-v-product-image-\d+__@@';
$size = '@@__data-v-size__@@';
$nr = '@@__data-v-product-image-(\d+)__@@';
- if (isset($product['images'][$nr]['image'])) {
- $image = $product['images'][$nr]['image'];
+ if (isset($_product['images'][$nr]['image'])) {
+ $image = $_product['images'][$nr]['image'];
if ($size) {
- //echo imageSize($product['image'], $size);
+ //echo imageSize($_product['image'], $size);
//$image = Vvveb\System\Images::size($image, $size);
echo $image;
} else {
@@ -94,17 +92,17 @@ if ($_products) {
- @product [data-v-product-image-*]|data-v-id = $product['images']['@@__data-v-product-image-(\d+)__@@']['id']
+ @product [data-v-product-image-*]|data-v-id = $_product['images']['@@__data-v-product-image-(\d+)__@@']['id']
@product [data-v-product-image-*]|data-v-type = 'product_image'
//image gallery
@product [data-v-product-images] [data-v-product-image]|before = <?php
- if(isset($product['images']) && is_array($product['images']))
- foreach ($product['images'] as $product_image_id => $image) {
+ if(isset($_product['images']) && is_array($_product['images']))
+ foreach ($_product['images'] as $_product_image_id => $image) {
?>
@product [data-v-product-images] img[data-v-product-image-src]|src = $image['image']
- @product [data-v-product-images] img[data-v-product-image-src]|data-v-id = $product_image_id
+ @product [data-v-product-images] img[data-v-product-image-src]|data-v-id = $_product_image_id
@product [data-v-product-images] img[data-v-product-image-src]|data-v-type = 'product_image'
@product [data-v-product-images] a[data-v-product-image-src]|href = $image['image']
@@ -112,9 +110,9 @@ if ($_products) {
} ?>
//catch all data attributes
- @product [data-v-product-*]|innerText = $product['@@__data-v-product-(*)__@@']
+ @product [data-v-product-*]|innerText = $_product['@@__data-v-product-(*)__@@']
//echo description directly to avoid htmlentities escape
- @product [data-v-product-content] = <?php echo $product['content'];?>
+ @product [data-v-product-content] = <?php echo $_product['content'];?>
@product|after = <?php
}
diff --git a/app/template/components/questions.tpl b/app/template/components/questions.tpl
index 306f89e..df10512 100644
--- a/app/template/components/questions.tpl
+++ b/app/template/components/questions.tpl
@@ -6,26 +6,30 @@
@questions|prepend = <?php
if (isset($_questions_idx)) $_questions_idx++; else $_questions_idx = 0;
$previous_component = isset($current_component)?$current_component:null;
-$questions = $current_component = $this->_component['questions'][$_questions_idx] ?? [];
+$component_questions = $current_component = $this->_component['questions'][$_questions_idx] ?? [];
+$questions = $component_questions['product_question'] ?? [];
$_pagination_count = $questions['count'] ?? 0;
$_pagination_limit = isset($questions['limit']) ? $questions['limit'] : 5;
?>
-
@question|before = <?php
-if($questions && is_array($questions['question'])) {
- foreach ($this->_component['questions'][$_questions_idx]['question'] as $index => $question) {?>
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;
+$questions = empty($questions) ? $_default : $questions;
+
+if($questions && is_array($questions)) {
+ foreach ($questions as $index => $question) {?>
@question|data-question_id = $question['question_id']
@question|addClass = <?php echo 'level-' . ($question['level'] ?? 0);?>
- @question|id = <?php echo 'question-' . $question['question_id'];?>
+ @question|id = <?php echo 'question-' . $question['product_question_id'];?>
@question [data-v-question-content] = <?php echo $question['content'];?>
@question img[data-v-question-*]|src = $question['@@__data-v-question-(*)__@@']
+ @question img[data-v-question-avatar]|width = <?php echo $question['size'] ?? '60';?>
@question [data-v-question-*]|innerText = $question['@@__data-v-question-(*)__@@']
diff --git a/app/template/components/reviews.tpl b/app/template/components/reviews.tpl
index 012679b..1f4af84 100755
--- a/app/template/components/reviews.tpl
+++ b/app/template/components/reviews.tpl
@@ -6,7 +6,8 @@
@reviews|prepend = <?php
if (isset($_reviews_idx)) $_reviews_idx++; else $_reviews_idx = 0;
$previous_component = isset($current_component)?$current_component:null;
-$reviews = $current_component = $this->_component['reviews'][$_reviews_idx] ?? [];
+$component_reviews = $current_component = $this->_component['reviews'][$_reviews_idx] ?? [];
+$reviews = $component_reviews['product_review'] ?? [];
$_pagination_count = $reviews['count'] ?? 0;
$_pagination_limit = isset($reviews['limit']) ? $reviews['limit'] : 5;
@@ -14,16 +15,20 @@ $_pagination_limit = isset($reviews['limit']) ? $reviews['limit'] : 5;
@review|before = <?php
-if($reviews && is_array($reviews['review'])) {
- foreach ($this->_component['reviews'][$_reviews_idx]['review'] as $index => $review) {?>
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_review_id']] : false;
+$reviews = empty($reviews) ? $_default : $reviews;
+
+if($reviews && is_array($reviews)) {
+ foreach ($reviews as $index => $review) {?>
@review|data-review_id = $review['review_id']
@review|addClass = <?php echo 'level-' . ($review['level'] ?? 0);?>
- @review|id = <?php echo 'review-' . $review['review_id'];?>
+ @review|id = <?php echo 'review-' . $review['product_review_id'];?>
@review [data-v-review-content] = <?php echo $review['content'];?>
+ @review img[data-v-review-avatar]|width = <?php echo $review['size'] ?? '60';?>
@review img[data-v-review-*]|src = $review['@@__data-v-review-(*)__@@']
@@ -34,4 +39,62 @@ if($reviews && is_array($reviews['review'])) {
@review|after = <?php
}
}
+?>
+
+
+@images = [data-v-component-reviews] [data-v-image]
+@images|deleteAllButFirstChild
+
+@images|before = <?php
+$_images = $component_reviews['images'] ?? [];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_review_media_id' => 0, 'image' => '']] : false;
+$_images = empty($_images) ? $_default : $_images;
+
+if($_images) {
+ $i = 0;
+ foreach ($_images as $index => $_image) { ?>
+
+ @images img[data-v-thumb-src]|src = $_image['thumb']
+ @images img[data-v-image-src]|src = $_image['image']
+ @images [data-v-image-background-image]|style = <?php echo 'background-image: url(\'' . $_image['image'] . '\');';?>
+
+ @images a[data-v-thumb-src]|href = $_image['thumb']
+ @images a[data-v-image-src]|href = $_image['image']
+ @images img[data-v-image-src]|data-v-id = $_image['product_review_media_id']
+ @images img[data-v-image-src]|data-v-type = 'product_review_media'
+
+ @images|after = <?php
+ $i++;
+ }
+}
+?>
+
+
+@review_images = [data-v-component-reviews] [data-v-review] [data-v-user-image]
+@review_images|deleteAllButFirstChild
+
+@review_images|before = <?php
+$_images = $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;
+
+if($_images) {
+ $i = 0;
+ foreach ($_images as $index => $_image) { ?>
+
+ @review_images [data-bs-slide-to]|data-bs-slide-to = <?php echo $i;?>
+ @review_images img[data-v-image-src]|src = $_image['image']
+ @review_images img[data-v-thumb-src]|src = $_image['thumb']
+ @review_images [data-v-image-background-image]|style = <?php echo 'background-image: url(\'' . $_image['image'] . '\');';?>
+
+ @review_images [data-gallery]|data-gallery = <?php echo 'user-' . $review['product_review_id'];?>
+ @review_images a[data-v-thumb-src]|href = $_image['thumb']
+ @review_images a[data-v-image-src]|href = $_image['image']
+ @review_images img[data-v-image-src]|data-v-id = $_image['product_review_media_id']
+ @review_images img[data-v-image-src]|data-v-type = 'product_review_media'
+
+ @review_images|after = <?php
+ $i++;
+ }
+}
?>
\ No newline at end of file
diff --git a/app/template/components/user/address.tpl b/app/template/components/user/address.tpl
index bbd47fa..99bdbc8 100755
--- a/app/template/components/user/address.tpl
+++ b/app/template/components/user/address.tpl
@@ -15,6 +15,9 @@ $addresses = $addresscomp['user_address'] ?? [];
@address|before = <?php
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['user_address_id' => 1]] : false;
+$addresses = empty($addresses) ? $_default : $addresses;
+
if($addresses) {
foreach ($addresses as $index => $address) {?>
diff --git a/app/template/pagination.tpl b/app/template/pagination.tpl
index e633457..7803271 100755
--- a/app/template/pagination.tpl
+++ b/app/template/pagination.tpl
@@ -22,7 +22,7 @@ $page_stop = $pagecount;
$url = '@@__data-v-url__@@';
if (empty($url)) {
- $url = Vvveb\System\Core\FrontController :: getRoute();
+ $url = Vvveb\System\Core\FrontController :: getRoute();
if (is_array($parameters)) {
$parameters += Vvveb\System\Core\Request :: getInstance()->get;
} else {
diff --git a/config/routes.php b/config/routes.php
index c04767f..3c02af6 100755
--- a/config/routes.php
+++ b/config/routes.php
@@ -87,8 +87,9 @@ return [
'/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&slug={slug}'],
//compare
- '/product/compare' => ['module' => 'product/compare/index'],
- '/product/compare/#product_id#' => ['module' => 'product/compare/index'],
+ '/cart/compare' => ['module' => 'cart/compare/index'],
+ '/cart/compare/add/#product_id#' => ['module' => 'cart/compare/add'],
+ '/cart/compare/remove/#product_id#' => ['module' => 'cart/compare/remove'],
//multi language catalog - language code must be at least 2 characters
'/{language{2,5}}/shop' => ['module' => 'product/index'],
diff --git a/install/controller/index.php b/install/controller/index.php
index 07bf742..f14a416 100755
--- a/install/controller/index.php
+++ b/install/controller/index.php
@@ -231,7 +231,8 @@ class Index extends Base {
$site['settings'] = json_encode($settings);
if ($theme) {
- @\Vvveb\set_config('sites.* * *.theme', $theme);
+ //@\Vvveb\set_config('sites.* * *.theme', $theme);
+ $site['theme'] = $theme;
}
if ($noecommerce) {
@@ -255,6 +256,8 @@ class Index extends Base {
$site = [
'host' => $_SERVER['HTTP_HOST'] ?? '*.*.*',
+ 'id' => 1,
+ 'name' => 'Default',
'theme' => $theme,
'settings' => json_encode($settings),
];
@@ -286,6 +289,9 @@ class Index extends Base {
'default' => 1,
]]);
}
+
+ unset($site['settings']);
+ @\Vvveb\set_config('sites.* * *', $site);
$lang = \Vvveb\session('language');
diff --git a/install/sql/insert/product/product_review.sql b/install/sql/insert/product/product_review.sql
index 9c514f2..c781e22 100755
--- a/install/sql/insert/product/product_review.sql
+++ b/install/sql/insert/product/product_review.sql
@@ -1,7 +1,7 @@
INSERT INTO `product_review` (`product_review_id`, `product_id`, `user_id`, `author`, `content`, `rating`, `status`, `parent_id`, `created_at`, `updated_at`) VALUES
-(1, 1, 1, 'John Doe', 'Cool product!', 5, 1, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
-(2, 1, 1, 'John Doe', 'This is another review', 5, 1, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
-(3, 1, 1, 'John Doe', 'Pending review', 5, 0, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
-(4, 1, 1, 'John Doe', 'Spam review', 5, 2, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
-(5, 1, 1, 'John Doe', 'Trash review', 5, 3, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00');
\ No newline at end of file
+(1, 19, 1, 'John Doe', 'Cool product!', 5, 1, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
+(2, 19, 1, 'John Doe', 'This is another review', 5, 1, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
+(3, 19, 1, 'John Doe', 'Pending review', 5, 0, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
+(4, 19, 1, 'John Doe', 'Spam review', 5, 2, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00'),
+(5, 19, 1, 'John Doe', 'Trash review', 5, 3, 0, '2022-05-01 00:00:00', '2022-05-01 00:00:00');
\ No newline at end of file
diff --git a/install/sql/insert/product/product_review_media.sql b/install/sql/insert/product/product_review_media.sql
new file mode 100644
index 0000000..2e12aba
--- /dev/null
+++ b/install/sql/insert/product/product_review_media.sql
@@ -0,0 +1,20 @@
+INSERT INTO `product_review_media` (product_review_id, product_id, user_id, image) VALUES
+-- 1
+(1,19,1,'product/1-1.jpg'),
+(1,19,1,'product/1-2.jpg'),
+(1,19,1,'product/1-3.jpg'),
+-- 2
+(2,19,1,'product/2-1.jpg'),
+(2,19,1,'product/2-2.jpg'),
+(2,19,1,'product/3-3.jpg'),
+-- 3
+(3,19,1,'product/3-1.jpg'),
+(3,19,1,'product/3-2.jpg'),
+(3,19,1,'product/3-3.jpg'),
+-- 4
+(4,19,1,'product/4-1.jpg'),
+(4,19,1,'product/4-2.jpg'),
+(4,19,1,'product/4-3.jpg'),
+-- 5
+(5,19,1,'product/5-1.jpg'),
+(5,19,1,'product/5-2.jpg');
\ No newline at end of file
diff --git a/install/sql/insert/site/site.sql b/install/sql/insert/site/site.sql
index b57155c..a308791 100755
--- a/install/sql/insert/site/site.sql
+++ b/install/sql/insert/site/site.sql
@@ -1,2 +1,2 @@
INSERT INTO `site` (`site_id`, `key`, `name`, `host`, `theme`, `template`, `settings`) VALUES
-(1, 'default','Default','*.*.*', 'landing', '', '{"title":"Vvveb","description":"The next generation website builder","meta-keywords":"cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description":"Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number":"+55 (111) 123 777","address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"0","post_medium_width":"400","post_medium_height":"0","post_thumb_width":"150","post_thumb_height":"0","product_large_width":"800","product_large_height":"0","product_medium_width":"400","product_medium_height":"0","product_thumb_width":"150","product_thumb_height":"0","date_format":"F j, Y","time_format":"g:i A", "country_id":"223","region_id":"3624","language_id":"1","currency_id":"1","language":"en_US","currency":"USD"}');
\ No newline at end of file
+(1, 'default','Default','*.*.*', 'landing', '', '{"title":"Vvveb","description":"The next generation website builder","meta-keywords":"cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description":"Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number":"+55 (111) 123 777","address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"0","post_medium_width":"400","post_medium_height":"0","post_thumb_width":"150","post_thumb_height":"0","product_large_width":"800","product_large_height":"0","product_medium_width":"400","product_medium_height":"0","product_thumb_width":"150","product_thumb_height":"0","date_format":"F j, Y","time_format":"g:i A", "country_id":"222","region_id":"3553","language_id":"1","currency_id":"1","language":"en_US","currency":"USD"}');
\ No newline at end of file
diff --git a/install/sql/mysqli/schema/product/product_review.sql b/install/sql/mysqli/schema/product/product_review.sql
index a2d517e..8f5303a 100755
--- a/install/sql/mysqli/schema/product/product_review.sql
+++ b/install/sql/mysqli/schema/product/product_review.sql
@@ -12,6 +12,5 @@ CREATE TABLE `product_review` (
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`product_review_id`),
- KEY `product_id` (`product_id`, `status`),
- KEY `user_id` (`user_id`)
+ KEY `product_id` (`product_id`, `user_id`,`status`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
diff --git a/install/sql/mysqli/schema/product/product_review_media.sql b/install/sql/mysqli/schema/product/product_review_media.sql
new file mode 100644
index 0000000..4ab51d7
--- /dev/null
+++ b/install/sql/mysqli/schema/product/product_review_media.sql
@@ -0,0 +1,13 @@
+DROP TABLE IF EXISTS `product_review_media`;
+
+CREATE TABLE `product_review_media` (
+ `product_review_media_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ `product_review_id` INT UNSIGNED NOT NULL,
+ `product_id` INT UNSIGNED NOT NULL,
+ `user_id` INT UNSIGNED NOT NULL,
+ `image` varchar(191) NOT NULL,
+ `sort_order` int(3) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`product_review_media_id`),
+ KEY `product_review_id` (`product_review_id`),
+ KEY `product_id` (`product_id`,`user_id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
diff --git a/install/sql/pgsql/schema/product/product_review.sql b/install/sql/pgsql/schema/product/product_review.sql
index e46dd34..e1b0747 100755
--- a/install/sql/pgsql/schema/product/product_review.sql
+++ b/install/sql/pgsql/schema/product/product_review.sql
@@ -18,4 +18,4 @@ CREATE TABLE product_review (
PRIMARY KEY ("product_review_id")
);
-CREATE INDEX "product_review_product_id" ON product_review ("product_id");
\ No newline at end of file
+CREATE INDEX "product_review_product_id" ON product_review ("product_id", "user_id", "status");
\ No newline at end of file
diff --git a/install/sql/pgsql/schema/product/product_review_media.sql b/install/sql/pgsql/schema/product/product_review_media.sql
new file mode 100644
index 0000000..8447bc3
--- /dev/null
+++ b/install/sql/pgsql/schema/product/product_review_media.sql
@@ -0,0 +1,18 @@
+DROP TABLE IF EXISTS product_review_media;
+
+DROP SEQUENCE IF EXISTS product_review_media_seq;
+CREATE SEQUENCE product_review_media_seq;
+
+
+CREATE TABLE product_review_media (
+ "product_review_media_id" int check ("product_review_media_id" > 0) NOT NULL DEFAULT NEXTVAL ('product_review_media_seq'),
+ "product_review_id" int check ("product_id" > 0) NOT NULL,
+ "product_id" int check ("product_id" > 0) NOT NULL,
+ "user_id" int check ("user_id" > 0) NOT NULL,
+ "image" varchar(191) NOT NULL,
+ "sort_order" int NOT NULL DEFAULT 0,
+ PRIMARY KEY ("product_review_media_id")
+);
+
+CREATE INDEX "product_review_media_product_id" ON product_review_media ("product_id", "user_id");
+CREATE INDEX "product_review_media_product_review_id" ON product_review_media ("product_review_id");
\ No newline at end of file
diff --git a/install/sql/sqlite/schema/product/product_image.sql b/install/sql/sqlite/schema/product/product_image.sql
index 8e10ae4..dd642e7 100755
--- a/install/sql/sqlite/schema/product/product_image.sql
+++ b/install/sql/sqlite/schema/product/product_image.sql
@@ -9,5 +9,4 @@ CREATE TABLE `product_image` (
);
-
CREATE UNIQUE INDEX `product_image_product_id_image` ON `product_image` (`product_id`, `image`);
diff --git a/install/sql/sqlite/schema/product/product_review.sql b/install/sql/sqlite/schema/product/product_review.sql
index 70f5ead..289a5df 100755
--- a/install/sql/sqlite/schema/product/product_review.sql
+++ b/install/sql/sqlite/schema/product/product_review.sql
@@ -15,4 +15,4 @@ CREATE TABLE `product_review` (
);
-CREATE INDEX `product_review_product_id` ON `product_review` (`product_id`);
+CREATE INDEX `product_review_product_id` ON `product_review` (`product_id`, `user_id`, `status`);
diff --git a/install/sql/sqlite/schema/product/product_review_media.sql b/install/sql/sqlite/schema/product/product_review_media.sql
new file mode 100644
index 0000000..7d2c243
--- /dev/null
+++ b/install/sql/sqlite/schema/product/product_review_media.sql
@@ -0,0 +1,15 @@
+DROP TABLE IF EXISTS `product_review_media`;
+
+CREATE TABLE `product_review_media` (
+`product_review_media_id` INTEGER PRIMARY KEY AUTOINCREMENT,
+`product_review_id` INT NOT NULL,
+`product_id` INT NOT NULL,
+`user_id` INT NOT NULL,
+`image` TEXT NOT NULL,
+`sort_order` INTEGER NOT NULL DEFAULT '0'
+-- PRIMARY KEY (`product_review_media_id`)
+);
+
+
+CREATE INDEX `product_review_media_product_id_image` ON `product_review_media` (`product_id`, `user_id`);
+CREATE INDEX `product_review_media_product_review_id_image` ON `product_review_media` (`product_review_id`);
diff --git a/public/js/admin.js b/public/js/admin.js
index d8a7947..adfef58 100755
--- a/public/js/admin.js
+++ b/public/js/admin.js
@@ -31,75 +31,8 @@ window.themes = Themes;
window.plugins = Plugins;
window.table = Table;
-window.delay = (function(){
- var timer = 0;
- return function(callback, ms){
- clearTimeout (timer);
- timer = setTimeout(callback, ms);
- };
-})();
-
-//let theme = localStorage.getItem("theme", "dark");
-let theme = $("html").attr("data-bs-theme");
-if (theme) {
- if (theme == "dark") {
- $("#color-theme-switch i").removeClass("la-sun").addClass("la-moon");
- }
- //$("html").attr("data-bs-theme", theme);
-}
-
-//let smallNav = localStorage.getItem("sidebar-size", "small-nav");
-let smallNav = document.cookie.indexOf("sidebar-size=small-nav") > 0;
-if (smallNav) {
- $("#container").addClass(smallNav);
-}
-
-//$.ajax(window.location.pathname + '?action=heartbeat');
-
-function toggleClass(container, className) {
-}
-
-function setCookie(name, value) {
- //try to set cookie to all subdomains
- document.cookie = name + "=" + value + ";path=/;domain=." + window.location.host.replace(/^.*?\./, '') + ";";
- document.cookie = name + "=" + value + ";";
-}
-
jQuery(document).ready(function() {
Router.init();
-
- jQuery(".menu-toggle").click(function() {
- if ($("#container").hasClass("small-nav")) {
- $("#container").removeClass("small-nav");
- smallNav = "";
- } else {
- smallNav = "small-nav";
- $("#container").addClass(smallNav);
- }
-
- //localStorage.setItem('sidebar-size', smallNav);
- setCookie('sidebar-size', smallNav);
- });
-
- $("#color-theme-switch").click(function () {
-
- let theme = $("html").attr("data-bs-theme");
-
- if (theme == "dark") {
- theme = "light";
- $("i",this).removeClass("la-moon").addClass("la-sun");
- } else if (theme == "light" || theme == "auto" || !theme) {
- theme = "dark";
- $("i", this).removeClass("la-sun").addClass("la-moon");
- } else {
- theme = "auto";
- }
-
- $("html").attr("data-bs-theme", theme);
- //localStorage.setItem("theme", theme);
- setCookie("theme", theme);
- //serverStorage.setItem();
- });
});
class AjaxStack {
diff --git a/public/js/libs/tinymce-options.js b/public/js/libs/tinymce-options.js
index 06267d5..c1285e6 100755
--- a/public/js/libs/tinymce-options.js
+++ b/public/js/libs/tinymce-options.js
@@ -24,16 +24,16 @@ function fixWrapper(body){
const isSmallScreen = window.matchMedia('(max-width: 1023.5px)').matches;
let tinyMceSkin = "oxide";
-let theme = 'auto'
+let tinyMceTheme = 'auto'
if (window.matchMedia("(prefers-color-scheme: dark)").matches || $("html").attr("data-bs-theme") == "dark") {
tinyMceSkin = "oxide-dark";
- theme = 'dark';
+ tinyMceTheme = 'dark';
}
let make_wysiwyg = function(inst){
fixWrapper(inst.contentDocument.body);
//set dark theme
- inst.contentDocument.documentElement.setAttribute("data-bs-theme", theme);
+ inst.contentDocument.documentElement.setAttribute("data-bs-theme", tinyMceTheme);
}
var tinyMceOptions = {
diff --git a/system/component/component-base.php b/system/component/component-base.php
index cd56bb6..dbfd57e 100755
--- a/system/component/component-base.php
+++ b/system/component/component-base.php
@@ -42,6 +42,7 @@ class ComponentBase {
self :: $global['start'] = 0;
self :: $global['site_id'] = defined('SITE_ID') ? SITE_ID : 0;
self :: $global['user_id'] = $user['user_id'] ?? null;
+ self :: $global['user_group_id'] = $user['user_group_id'] ?? 1;
self :: $global['language_id'] = session('language_id') ?? 1;
self :: $global['language'] = session('language') ?? 'en_US';
self :: $global['default_language'] = session('default_language') ?? 'en_US';
@@ -51,7 +52,7 @@ class ComponentBase {
static :: $defaultOptions = array_merge(self :: $global, static :: $defaultOptions);
- foreach (['site_id', 'language_id', 'currency_id'] as $key) {
+ foreach (['site_id', 'language_id', 'currency_id', 'user_group_id'] as $key) {
if (! isset(static :: $defaultOptions[$key]) || empty(static :: $defaultOptions[$key])) {
static :: $defaultOptions[$key] = self :: $global[$key];
}
diff --git a/system/component/component.php b/system/component/component.php
old mode 100755
new mode 100644
index d31e57a..e6d63af
--- a/system/component/component.php
+++ b/system/component/component.php
@@ -274,7 +274,7 @@ class Component {
$object = $results['_instance'];
if (method_exists($object, 'request')) {
- $object->request($results);
+ $object->request($results, $index);
}
}
}
diff --git a/system/core/frontcontroller.php b/system/core/frontcontroller.php
index ab1a592..786b3eb 100755
--- a/system/core/frontcontroller.php
+++ b/system/core/frontcontroller.php
@@ -150,7 +150,9 @@ class FrontController {
}
static function closeConnections() {
- \Vvveb\System\Db::getInstance()->close();
+ if (defined('DB_ENGINE') && ($instance = \Vvveb\System\Db::getInstance())) {
+ $instance->close();
+ }
}
/**
@@ -325,7 +327,7 @@ class FrontController {
}
$uri = preg_replace('/\?.*$/', '', $uri);
- if (! $module && (APP != 'admin' && (Routes::init() && $parameters = Routes::match($uri)))) {
+ if (! $module && (APP != 'admin' && APP != 'install' && (Routes::init() && $parameters = Routes::match($uri)))) {
$_GET = array_merge($parameters, $_GET);
} else {
$module = $module ?? ((APP == 'app') ? 'error404' : 'index');
diff --git a/system/core/startup.php b/system/core/startup.php
index f031377..bf84277 100755
--- a/system/core/startup.php
+++ b/system/core/startup.php
@@ -366,7 +366,7 @@ function start() {
FrontController::dispatch();
} else {
- define('SITE_URL', $_SERVER['HTTP_HOST']);
+ define('SITE_URL', $_SERVER['HTTP_HOST'] ?? 'localhost');
define('SITE_ID', 1);
FrontController::notFound(false, 'Website not found!');
}
diff --git a/system/core/view.php b/system/core/view.php
index 33a3ec1..d805aad 100755
--- a/system/core/view.php
+++ b/system/core/view.php
@@ -167,7 +167,8 @@ class View {
if (! $this->template) {
return false;
}
-
+
+ $this->template = str_replace(['/', '\\'], DS, $this->template);
$templatePath = $this->templatePath;
$template = $this->template;
$templateMtime = null;
@@ -347,7 +348,7 @@ class View {
$jsonFlags = 0;
//if (defined('CLI')) {
- $jsonFlags = JSON_PRETTY_PRINT;
+ $jsonFlags = JSON_PRETTY_PRINT;
//}
ob_start();
echo json_encode($this, $jsonFlags);
@@ -378,4 +379,4 @@ class View {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/system/db.php b/system/db.php
index 7e73483..4dd465b 100755
--- a/system/db.php
+++ b/system/db.php
@@ -26,6 +26,8 @@ class Db {
public static function getInstance($engine = DB_ENGINE) {
static $inst = [];
+ if (!$engine) return;
+
if (! isset($inst[$engine]) || $inst[$engine] === null) {
$driverName = "\Vvveb\System\Db\\$engine";
diff --git a/system/db/dbdriver.php b/system/db/dbdriver.php
index 2dfe76c..ed9a209 100755
--- a/system/db/dbdriver.php
+++ b/system/db/dbdriver.php
@@ -173,7 +173,7 @@ class DBDriver {
//mysql
$query = preg_replace('/LIMIT\s+(\d+|:\w+),\s*(\d+|:\w+)\s*;?$/', '', $query);
- $query = preg_replace("/^\s*SELECT .*?\s*FROM\s*$table /ms", "SELECT $column FROM $table ", $query);
+ $query = preg_replace("/^\s*SELECT .*?\s*FROM\s*$table\s/ms", "SELECT $column FROM $table ", $query);
return $query;
}
diff --git a/system/extensions/plugins.php b/system/extensions/plugins.php
index 7485bc7..e8fc544 100755
--- a/system/extensions/plugins.php
+++ b/system/extensions/plugins.php
@@ -52,10 +52,11 @@ class Plugins extends Extensions {
$params = parent::getInfo($content, $name);
$params['status'] = 'inactive';
- if (isset($params['thumb'])) {
- $params['thumb_url'] = PUBLIC_PATH . 'plugins/' . $name . '/' . $params['thumb'];
+ if (isset($params['thumb']) &&
+ file_exists(DIR_PUBLIC . ($file = 'plugins/' . $name . '/' . $params['thumb']))) {
+ $params['thumb_url'] = PUBLIC_PATH . $file;
} else {
- //$params['thumb_url'] = PUBLIC_PATH . 'plugins/plugin.svg';
+ $params['thumb_url'] = PUBLIC_PATH . 'media/placeholder.svg';
}
return $params;
diff --git a/system/functions.php b/system/functions.php
index d99eaea..5316044 100755
--- a/system/functions.php
+++ b/system/functions.php
@@ -1454,8 +1454,8 @@ function commentStatusBadgeClass($status = 0) {
$classes = [
0 => 'bg-primary-subtle text-body', //pending
1 => 'bg-success-subtle text-body', //approved
- 2 => 'bg-danger-subtle text-body', //spam
- 3 => 'bg-warning-subtle text-body', //trash
+ 2 => 'bg-warning-subtle text-body', //spam
+ 3 => 'bg-danger-subtle text-body', //trash
];
return $classes[$status] ?? 'bg-secondary-subtle text-dark';
diff --git a/system/sites.php b/system/sites.php
index cbc270a..bbf0f4a 100755
--- a/system/sites.php
+++ b/system/sites.php
@@ -285,7 +285,13 @@ class Sites {
$result['host'] = self :: url($result['host']);
}
- return $result ?? false;
+ return $result ?? [
+ 'host' => 'localhost',
+ 'theme' => 'landing',
+ 'template' => '',
+ 'id' => 1,
+ 'state' => 'live',
+ ];
}
public static function saveSite($site) {
diff --git a/system/sqlp/sqlp.php b/system/sqlp/sqlp.php
index 07b3059..96afdd3 100755
--- a/system/sqlp/sqlp.php
+++ b/system/sqlp/sqlp.php
@@ -121,6 +121,37 @@ class SqlP {
return '';
}
+ /*
+ * Replace subqueries with provided string to keep only main query for getTableName to correctly extract table name
+ */
+ function removeParanthesis($query, $replace = '', $startChar = '(', $endChar = ')') {
+ $level = 0;
+ $start = null;
+ $end = 0;
+ for($i=0; $i<strlen($query); $i++) {
+ $char = $query[$i];
+
+ if($char == $startChar) {
+ if ($start === null) $start = $i;
+ $level++;
+ }
+ else if($char == $endChar) {
+ $level--;
+ }
+
+ if($start && $level == 0) {
+ $end = $i + 1;
+ $query = substr_replace($query, $replace, $start, $end - $start);
+ //reset
+ $i = 0;
+ $start = null;
+
+ }
+ }
+
+ return $query;
+ }
+
/*
* Extract table name from sql statement
*/
@@ -128,12 +159,7 @@ class SqlP {
$tableName = '';
//remove subselects
- $count = 1;
-
- while ($count != 0) {
- $query = preg_replace('/\([^\(\)]{10,}?\)/ms', 'replaced_subselect', $query, -1, $count);
- }
-
+ $query = $this->removeParanthesis($query, 'replace_subselect');
//remove macros
$count = 1;