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
Reuse components from app
givanz7e7103f92434
diff --git a/admin/component/product.php b/admin/component/product.phpindex 221d71a..7c34dcf 100644--- a/admin/component/product.php+++ b/admin/component/product.php@@ -22,66 +22,4 @@namespace Vvveb\Component;-use Vvveb\Sql\ProductSQL;-use Vvveb\System\Cart\Currency;-use Vvveb\System\Cart\Tax;-use Vvveb\System\Component\ComponentBase;-use Vvveb\System\Event;-use Vvveb\System\Images;-use function Vvveb\url;--class Product extends ComponentBase {- public static $defaultOptions = [- '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,- 'image_size' => '',- ];-- function results() {- $product = new ProductSQL();- $results = $product->get($this->options);-- $results['images'] = [];-- if (isset($results['product_image'])) {- $results['images'] = Images::images($results['product_image'], 'product', $this->options['image_size']);- }-- if (isset($results['image'])) {- //$results['images'][] = ['image' => Images::image('product', $results['image'])];- $results['image']= Images::image($results['image'], 'product', $this->options['image_size']);- }-- $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']]);-- $tax = Tax::getInstance();- $currency = Currency::getInstance();- $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']);- }-- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);-- return $results;- }-}+include DIR_ROOT . 'app' . DS . 'component' . DS . 'product.php';diff --git a/admin/component/products.php b/admin/component/products.phpindex 741a93e..21b28f7 100755--- a/admin/component/products.php+++ b/admin/component/products.php@@ -43,7 +43,7 @@ class Products extends ComponentBase {public $options = [];function __construct($class = __CLASS__) {- return parent::__construct($class);+ parent::__construct($class);}function results() {diff --git a/admin/template/components/product.tpl b/admin/template/components/product.tplindex fdfba8e..2b8807c 100644--- a/admin/template/components/product.tpl+++ b/admin/template/components/product.tpl@@ -1,66 +1 @@-@product = [data-v-component-product]-@images = [data-v-component-product] [data-v-product-images]---@product|data-v-id = $product['product_id']-@product|data-v-type = 'product'--@product|before = <?php-if (isset($_product_idx)) $_product_idx++; else $_product_idx = 0;-$previous_component = isset($component)?$component:null;--$previous_component = isset($current_component)?$current_component:null;-$product = $current_component = $this->_component['product'][$_product_idx] ?? [];--$_pagination_count = $product['count'] ?? 0;-$_pagination_limit = isset($product['limit']) ? $product['limit'] : 5;-?>--//editor attributes-@product|data-v-id = $product['product_id']-@product|data-v-type = 'product'--//catch all data attributes-@product [data-v-product-*]|innerText = $product['@@__data-v-product-(*)__@@']-@product input[data-v-product-*]|value = $product['@@__data-v-product-(*)__@@']-@product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']--//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 [data-v-product-main-image-background-image]|style = <?php echo 'background-image: url(\'' . $product['image'] . '\');';?>-@product a[data-v-product-main-image]|href = <?php echo reset($product['images'])['image'];?>--@images [data-v-product-image]|deleteAllButFirstChild--@images [data-v-product-image]|before = <?php-$_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 = 1;- 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['product_image_id']- @images img[data-v-product-image-src]|data-v-type = 'product_image'-- @images [data-v-product-image]|after = <?php- $i++;- }-}--$component = $previous_component;-?>---\ No newline at end of file+import(/app/template/components/product.tpl)\ No newline at end of filediff --git a/system/core/startup.php b/system/core/startup.phpindex fc47267..47570fb 100755--- a/system/core/startup.php+++ b/system/core/startup.php@@ -90,7 +90,7 @@ function logError($message) {}function regenerateSQL($sqlFile, $file, $modelName, $namespace) {- $sqlp = new SqlP();+ $sqlp = new Sqlp();$sqlp->parseSqlPfile($sqlFile, $modelName, $namespace);@@ -128,6 +128,17 @@ function autoload($class) {$root = DIR_ROOT;}+ //if namespace is App change to app dir+ if ((substr_compare($relativeClass, 'App\\', 0, 4) == 0)) {+ $root = DIR_ROOT . 'app' . DS;+ var_dump($root);+ }++ //if namespace is Admin change to admin dir+ if ((substr_compare($relativeClass, 'Admin\\', 0, 6) == 0)) {+ $root = DIR_ROOT . 'admin' . DS;+ }+$isSql = (substr_compare($relativeClass, 'SQL', -3, 3) === 0);//check if sql files are changed or missing to regenerate sql class@@ -272,7 +283,8 @@ function vErrorHandler($errno, $errstr, $errfile, $errline) {//check if error is generated by a plugin and disable itpluginErrorCheck($errfile);- throw new ErrorException($errstr, $errno, 0, $errfile, $errline);+ throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);+return true;//return FrontController::notFound(false, $errstr, 500);}