Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Use id instead of slug if translation is missing
givanz21c7e9a1f1b9
diff --git a/app/component/post.php b/app/component/post.phpindex 8214d84..5e9c0c8 100755--- a/app/component/post.php+++ b/app/component/post.php@@ -41,12 +41,12 @@ class Post extends ComponentBase {'language_id' => null,'site_id' => null,'slug' => 'url',- 'status' => 'publish',- 'comment_count' => 1,- 'comment_status' => 1,- 'type' => null,- 'image_size' => 'large',- //'type' => 'post',+ 'status' => 'publish', //'publish', 'draft', 'pending', 'private', 'scheduled'+ 'comment_count' => 1, // flag to include post comments count+ 'comment_status' => 1, // include only comments with status, 1 = published, 0 = unpublished/pending, 2 = spam, 3 = trash+ 'type' => null, // filter by post type eg: post+ 'image_size' => 'large', //options: xlarge, large, medium, thumb+ 'image_resize' => null, //options: cs = Crop & resize, c = crop, r = resize, s = stretch];public $cacheExpire = 0; //no cache@@ -60,7 +60,7 @@ class Post extends ComponentBase {//$languages = availableLanguages();if (! isset($this->options['date_format'])) {$site = siteSettings();- $this->options['date_format'] = $site['date_format'];+ $this->options['date_format'] = $site['date_format'] ?? 'human';}if ($results) {diff --git a/app/component/product.php b/app/component/product.phpindex 923b40e..7882335 100755--- a/app/component/product.php+++ b/app/component/product.php@@ -23,7 +23,6 @@namespace Vvveb\Component;use \Vvveb\Sql\Product_VariantSQL;-use function Vvveb\getCurrency;use function Vvveb\model;use function Vvveb\sanitizeHTML;use Vvveb\Sql\ProductSQL;@@ -33,20 +32,24 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Core\Request;use Vvveb\System\Event;use Vvveb\System\Images;+use Vvveb\System\Locale;+use Vvveb\System\Traits\Product as ProductTrait;use Vvveb\System\User\Admin;use function Vvveb\url;class Product extends ComponentBase {+ //use ProductTrait;+public static $defaultOptions = ['product_id' => 'url','slug' => 'url','status' => 1,'language_id' => null,'site_id' => null,- 'user_id' => null,- 'user_group_id' => null,- 'product_variant_id' => null,+ 'user_group_id' => null, // user group id to use to calculate promotional price+ 'product_variant_id' => null, // product variant id to display variant as default, for price and product options'variant' => null, //[true, false] include variants+ 'variant_price' => null, //[true, false] include variants prices'promotion' => null, //[true, false] include promotional price'points' => null, //[true, false] include points'stock_status' => null, //[true, false] include stock status info@@ -54,8 +57,8 @@ class Product extends ComponentBase {'length_type' => null, //[true, false] include length type info'rating' => null, //[true, false] include rating average'reviews' => null, //[true, false] include reviews count-- 'image_size' => 'large',+ 'image_size' => 'large', //options: xlarge, large, medium, thumb - if null site settings is used+ 'image_resize' => null, //options: cs = Crop & resize, c = crop, r = resize, s = stretch - if null site settings is used];public $cacheExpire = 0; //no cache@@ -67,7 +70,7 @@ class Product extends ComponentBase {$results['images'] = [];if (isset($results['product_image'])) {- $results['images'] = Images::images($results['product_image'], 'product', $this->options['image_size']);+ $results['images'] = Images::images($results['product_image'], 'product', $this->options['image_size'], $this->options['image_resize'] ?? 'cs');}if (isset($results['image'])) {@@ -113,7 +116,7 @@ class Product extends ComponentBase {$this->tax = Tax::getInstance($this->options);$this->currency = Currency::getInstance($this->options);- $this->currentCurrency = getCurrency();+ $this->currentCurrency = Locale :: getCurrency();foreach (['price', 'old_price', 'min_price', 'max_price'] as $price) {$amount = 0;@@ -124,7 +127,7 @@ class Product extends ComponentBase {$results["{$price}_tax"] = $amount ? $this->tax->addTaxes($amount, $results['tax_type_id']) : 0;$results["{$price}_formatted"] = $this->currency->format($amount);$results["{$price}_tax_formatted"] = $this->currency->format($results["{$price}_tax"]);- $results["{$price}_price_currency"] = $this->currentCurrency;+ $results["{$price}_currency"] = $this->currentCurrency;}$results['has_variants'] = false;@@ -140,6 +143,17 @@ class Product extends ComponentBase {$results['promotion_discount'] = 100 - ceil($results['promotion'] * 100 / $results['price']);}++ if ($results['language_id'] != $this->options['default_language_id']) {+ if ($results['name'] === null && isset($results['product_content'][$this->options['default_language_id']])) {+ $langFallback = $results['product_content'][$this->options['default_language_id']];+ $results['name'] = $langFallback['name'];+ $results['slug'] = $langFallback['slug'];+ $results['content'] = $langFallback['content'];+ $results['language_id'] = $langFallback['language_id'];+ }+ }+//rfc$results['pubDate'] = date('r', strtotime($results['created_at']));$results['modDate'] = date('r', strtotime($results['updated_at']));diff --git a/config/app-routes.php b/config/app-routes.phpold mode 100644new mode 100755index 255df3d..1477c2f--- a/config/app-routes.php+++ b/config/app-routes.php@@ -77,6 +77,8 @@ return ['/shop/{slug}' => ['module' => 'product/category/index'],'/shop/{slug}/#page#' => ['module' => 'product/category/index'],'/shop/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index'],+ '/ptag/{slug}' => ['module' => 'product/tag/index'],+ '/ptag/{slug}/#page#' => ['module' => 'product/tag/index'],'/brand/{slug}' => ['module' => 'product/manufacturer/index'],'/brand' => ['module' => 'product/manufacturer/index'],'/brand/#page#' => ['module' => 'product/manufacturer/index'],@@ -93,16 +95,19 @@ return ['/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'],- '/{language{2,5}}/shop/#page#' => ['module' => 'product/index'],- '/{language{2,5}}/shop/{slug}' => ['module' => 'product/category/index'],- '/{language{2,5}}/shop/{slug}/#page#' => ['module' => 'product/category/index'],- '/{language{2,5}}/shop/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index'],- '/{language{2,5}}/manufacturer/{slug}' => ['module' => 'product/manufacturer/index'],- '/{language{2,5}}/vendor/{slug}' => ['module' => 'product/vendor/index'],- '/{language{2,5}}/vendor/{slug}/#page#' => ['module' => 'product/vendor/index'],- //'/{language{2,5}}/product/{slug}-#product_id#' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id={product_id}'],- '/{language{2,5}}/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id={slug}'],+ '/{language{2,3}}/shop' => ['module' => 'product/index'],+ '/{language{2,3}}/shop/#page#' => ['module' => 'product/index'],+ '/{language{2,3}}/shop/{slug}' => ['module' => 'product/category/index'],+ '/{language{2,3}}/shop/{slug}/#page#' => ['module' => 'product/category/index'],+ '/{language{2,3}}/shop/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index'],+ '/{language{2,3}}/ptag/{slug}' => ['module' => 'product/tag/index'],+ '/{language{2,3}}/ptag/{slug}/#page#' => ['module' => 'product/tag/index'],+ '/{language{2,3}}/manufacturer/{slug}' => ['module' => 'product/manufacturer/index'],+ '/{language{2,3}}/vendor/{slug}' => ['module' => 'product/vendor/index'],+ '/{language{2,3}}/vendor/{slug}/#page#' => ['module' => 'product/vendor/index'],+ //'/{language{2,3}}/product/{slug}-#product_id#' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id={product_id}'],+ '/{language{2,3}}/product/p-#product_id#' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id=#product_id#'],+ '/{language{2,3}}/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&slug={slug}'],//checkout'/cart' => ['module' => 'cart/cart/index'],@@ -152,27 +157,34 @@ return [//'/page/{slug}-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id={post_id}&type=page'],//multi language content - language code must be at least 2 characters- '/{language{2,5}}/' => ['module' => 'index/index'],+ '/{language{2,3}}/' => ['module' => 'index/index'],//pagination for blog posts- '/{language{2,5}}/p/#page#' => ['module' => 'index/index'],+ '/{language{2,3}}/p/#page#' => ['module' => 'index/index'],//content- '/{language{2,5}}/blog' => ['module' => 'content'],- '/{language{2,5}}/cat/{slug}' => ['module' => 'content/category/language'],- '/{language{2,5}}/tag/{slug}' => ['module' => 'content/tag/index'],- //'/{language{2,5}}/{slug}-#post_id#' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id={post_id}'],- '/{language{2,5}}/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id={slug}'],- //'/{language{2,5}}/page/{slug}-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id={post_id}'],- '/{language{2,5}}/page/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}'],-- '/{language{2,5}}/tag/{slug}' => ['module' => 'content/tag/index'],- '/{language{2,5}}/tag/{slug}/#page#' => ['module' => 'content/tag/index'],- '/{language{2,5}}/author/{username}' => ['module' => 'content/user/index'],+ '/{language{2,3}}/blog' => ['module' => 'content'],+ '/{language{2,3}}/cat/{slug}' => ['module' => 'content/category/language'],+ '/{language{2,3}}/tag/{slug}' => ['module' => 'content/tag/index'],+ //'/{language{2,3}}/{slug}-#post_id#' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id={post_id}'],+ '/{language{2,3}}/p-#post_id#' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id=#post_id#'],+ '/{language{2,3}}/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&slug={slug}'],+ //'/{language{2,3}}/page/{slug}-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id={post_id}'],+ '/{language{2,3}}/page/p-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id=#post_id#'],+ '/{language{2,3}}/page/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}'],++ '/{language{2,3}}/tag/{slug}' => ['module' => 'content/tag/index'],+ '/{language{2,3}}/tag/{slug}/#page#' => ['module' => 'content/tag/index'],+ '/{language{2,3}}/author/{username}' => ['module' => 'content/user/index'],//archive year- '/{language{2,5}}/#year{4,4}#'=> ['module' => 'content/archive/index'],+ '/{language{2,3}}/#year{4,4}#'=> ['module' => 'content/archive/index'],//archive month and year- '/{language{2,5}}/#year{4,4}#/#month{2,2}#'=> ['module' => 'content/archive/index'],+ '/{language{2,3}}/#year{4,4}#/#month{2,2}#'=> ['module' => 'content/archive/index'],//archive day//'/#year#/#month#/#day#'=> ['module' => 'content/archive/index'],+ /*+ '/{language{2,3}}/cart' => ['module' => 'cart/cart/index'],+ '/{language{2,3}}/checkout' => ['module' => 'checkout/checkout/index'],+ '/{language{2,3}}/user' => ['module' => 'user/index'],+ *///custom post'/{type}' => ['module' => 'content'],@@ -190,6 +202,8 @@ return ['/{type}/cat/{slug}' => ['module' => 'product/category/index', 'type' => '{type}'],'/{type}/cat/{slug}/#page#' => ['module' => 'product/category/index', 'type' => '{type}'],'/{type}/cat/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index', 'type' => '{type}'],+ '/{type}/t/{slug}' => ['module' => 'product/tag/index', 'type' => '{type}'],+ '/{type}/t/{slug}/#page#' => ['module' => 'product/tag/index', 'type' => '{type}'],'/{type}/{slug}' => ['module' => 'product/product/index', 'type' => '{type}', 'edit'=>'?module=product/product&type={type}&slug={slug}'],//Crondiff --git a/system/traits/post.php b/system/traits/post.phpindex ffa0b3c..a746cc9 100644--- a/system/traits/post.php+++ b/system/traits/post.php@@ -37,13 +37,17 @@ trait Post {}function post(&$post, &$options = []) {+ if (! $post) {+ return $post;+ }+$type = $post['type'] ?? $options['type'] ?? 'post';if (isset($post['images'])) {$post['images'] = json_decode($post['images'], 1);foreach ($post['images'] as &$image) {- $image = Images::image($image, 'post', $options['image_size'] ?? 'medium');+ $image = Images::image($image, 'post', $options['image_size'] ?? 'medium', $options['image_resize'] ?? 'cs');}}@@ -67,7 +71,7 @@ trait Post {}if (isset($post['image'])) {- $post['image'] = $post['images'][] = Images::image($post['image'], 'post', $options['image_size'] ?? 'medium');+ $post['image'] = $post['images'][] = Images::image($post['image'], 'post', $options['image_size'] ?? 'medium', $options['image_resize'] ?? 'cs');}if (isset($post['avatar'])) {@@ -98,9 +102,16 @@ trait Post {if ($post['language_id'] != $options['default_language_id']) {$language = ['language' => $options['language']];- if (! $post['name']) {- $post['name'] = '[' . __('No translation') . ']';- $post['slug'] = 'no-translation';+ if ($post['name'] === null && isset($post['post_content'][$this->options['default_language_id']])) {+ $langFallback = $post['product_content'][$this->options['default_language_id']];+ $post['name'] = $langFallback['name'];+ $post['slug'] = $langFallback['slug'];+ $post['content'] = $langFallback['content'];+ $post['language_id'] = $langFallback['language_id'];+ } else {+ if (! $post['name']) {+ $post['name'] = '[' . __('No translation') . ']';+ }}}@@ -119,7 +130,11 @@ trait Post {}//url- $url = ['slug' => $post['slug'], 'post_id' => $post['post_id']] + $language;+ $url = ['post_id' => $post['post_id']] + $language;+ //if translation is missing slug is not available+ if (isset($post['slug'])) {+ $url['slug'] = $post['slug'];+ }if ($post['type'] != 'post') {$url['type'] = $post['type'];diff --git a/system/traits/product.php b/system/traits/product.phpindex 0d0d3ac..a36fafc 100644--- a/system/traits/product.php+++ b/system/traits/product.php@@ -23,10 +23,10 @@namespace Vvveb\System\Traits;use function Vvveb\__;-use function Vvveb\getCurrency;use Vvveb\System\Cart\Currency;use Vvveb\System\Cart\Tax;use Vvveb\System\Images;+use Vvveb\System\Locale;use function Vvveb\url;trait Product {@@ -36,7 +36,7 @@ trait Product {}if (! isset($this->currentCurrency)) {- $this->currentCurrency = getCurrency();+ $this->currentCurrency = Locale :: getCurrency();$this->tax = Tax::getInstance($options);$this->currency = Currency::getInstance($options);}@@ -52,7 +52,7 @@ trait Product {$language = [];if (! isset($this->currentCurrency)) {- $this->currentCurrency = getCurrency();+ $this->currentCurrency = Locale :: getCurrency();$this->tax = Tax::getInstance($options);$this->currency = Currency::getInstance($options);}@@ -62,7 +62,6 @@ trait Product {if (! $product['name']) {$product['name'] = '[' . __('No translation') . ']';- $product['slug'] = 'no-translation';}}@@ -70,12 +69,12 @@ trait Product {$product['images'] = json_decode($product['images'], true);foreach ($product['images'] as &$image) {- $image['image'] = Images::image($image['image'], 'product', $options['image_size'] ?? 'medium');+ $image['image'] = Images::image($image['image'], 'product', $options['image_size'] ?? 'medium', $options['image_resize'] ?? 'cs');}}if (isset($product['image']) && $product['image']) {- $product['image'] = Images::image($product['image'], 'product', $options['image_size'] ?? 'medium');+ $product['image'] = Images::image($product['image'], 'product', $options['image_size'] ?? 'medium', $options['image_resize'] ?? 'cs');//$product['images'][] = ['image' => Images::image($product['image'], 'product')];}@@ -84,7 +83,11 @@ trait Product {$product['modDate'] = date('r', strtotime($product['updated_at']));$product['lastMod'] = date('Y-m-d\TH:i:sP', strtotime($product['updated_at']));- $url = ['slug' => $product['slug'], 'type' => $product['type'], 'product_id' => $product['product_id']] + $language;+ $url = ['type' => $product['type'], 'product_id' => $product['product_id']] + $language;+ //if translation is missing slug is not available+ if (isset($product['slug'])) {+ $url['slug'] = $product['slug'];+ }$product['url'] = url('product/product/index', $url);$product['add_cart_url'] = url('cart/cart/add', ['product_id' => $product['product_id']]);@@ -102,7 +105,7 @@ trait Product {$product["{$price}_tax"] = $amount ? $this->tax->addTaxes($amount, $product['tax_type_id']) : 0;$product["{$price}_formatted"] = $this->currency->format($amount);$product["{$price}_tax_formatted"] = $this->currency->format($product["{$price}_tax"]);- $product["{$price}_price_currency"] = $this->currentCurrency;+ $product["{$price}_currency"] = $this->currentCurrency;}$product['has_variants'] = false;