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
Products compare
givanz72d690504419
diff --git a/app/component/breadcrumb.php b/app/component/breadcrumb.phpindex 31db330..944e713 100755--- a/app/component/breadcrumb.php+++ b/app/component/breadcrumb.php@@ -158,6 +158,14 @@ class Breadcrumb extends ComponentBase {['text' => $slug, 'url' => false],];+ break;+ //compare+ case 'cart/compare/index':+ $breadcrumb = [+ ['text' => $homeText, 'url' => '/'],+ ['text' => __('Compare'), 'url' => false],+ ];+break;default:diff --git a/app/component/compare.php b/app/component/compare.phpnew file mode 100644index 0000000..98ceafb--- /dev/null+++ b/app/component/compare.php@@ -0,0 +1,146 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Component;++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 Wishlist extends ComponentBase {+ public static $defaultOptions = [+ 'start' => 0,+ 'page' => 1,+ 'limit' => 4,+ 'status' => 1,+ 'language_id' => null,+ 'site_id' => null,+ 'type' => 'product',+ 'user_id' => NULL,+ 'taxonomy_item_id' => NULL,+ 'image_size' => 'medium',+ 'filter' => null,+ ];++ public $options = [];++ function results() {+ $products = new \Vvveb\Sql\User_wishlistSQL();++ if ($page = $this->options['page']) {+ $this->options['start'] = ($page - 1) * $this->options['limit'];+ }++ if ($this->options['filter']) {+ foreach ($this->options['filter'] as $name => $values) {+ if ($name == 'manufacturer_id' || $name == 'vendor_id') {+ $this->options[$name] = $values;+ }+ }+ }++ if (isset($this->options['product_id']) &&+ ($this->options['related'] || $this->options['variant'] || $this->options['source'] == 'autocomplete')) {+ if (! is_array($this->options['product_id'])) {+ $this->options['product_id'] = [$this->options['product_id'] => 1];+ }+ $this->options['product_id'] = array_keys($this->options['product_id']);+ } else {+ $this->options['product_id'] = [];+ }++ if (isset($this->options['order_by']) &&+ ! in_array($this->options['order_by'], ['product_id', 'price', 'created_at', 'updated_at'])) {+ unset($this->options['order_by']);+ }++ if (isset($this->options['direction']) &&+ ! in_array($this->options['direction'], ['asc', 'desc'])) {+ unset($this->options['direction']);+ }++ //if only one slug is provided then add it to array+ if (isset($this->options['slug']) && ! is_array($this->options['slug'])) {+ $this->options['slug'] = [$this->options['slug']];+ }++ //if only one manufacturer_id is provided then add it to array+ if (isset($this->options['manufacturer_id']) && ! is_array($this->options['manufacturer_id'])) {+ $this->options['manufacturer_id'] = [$this->options['manufacturer_id']];+ }++ //if only one vendor_id is provided then add it to array+ if (isset($this->options['vendor_id']) && ! is_array($this->options['vendor_id'])) {+ $this->options['vendor_id'] = [$this->options['vendor_id']];+ }++ $results = $products->getAll($this->options) + $this->options;++ if ($results && isset($results['products'])) {+ $tax = Tax::getInstance($this->options);+ $currency = Currency::getInstance($this->options);++ foreach ($results['products'] as $id => &$product) {+ $language = [];++ if ($product['language_id'] != $this->options['default_language_id']) {+ $language = ['language' => $this->options['language']];+ }++ if (isset($product['images'])) {+ $product['images'] = json_decode($product['images'], true);++ foreach ($product['images'] as &$image) {+ $image['image'] = Images::image($image['image'], 'product', $this->options['image_size']);+ }+ }++ if (isset($product['image']) && $product['image']) {+ $product['image'] = Images::image($product['image'], 'product', $this->options['image_size']);+ //$product['images'][] = ['image' => Images::image($product['image'], 'product')];+ }++ //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_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']);+ $product['price_formatted'] = $currency->format($product['price']);+ }+ }++ list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);++ return $results;+ }+}diff --git a/app/controller/cart/compare.php b/app/controller/cart/compare.phpindex 873ae41..a7f3513 100644--- a/app/controller/cart/compare.php+++ b/app/controller/cart/compare.php@@ -22,13 +22,103 @@namespace Vvveb\Controller\Cart;+use \Vvveb\Sql\AttributeSQL;+use \Vvveb\Sql\ProductSQL;use Vvveb\Controller\Base;+use function Vvveb\session as sess;+use Vvveb\System\Cart\Currency;+use Vvveb\System\Cart\Tax;+use Vvveb\System\Images;+use function Vvveb\url;class Compare extends Base {function index() {+ $product_id = $compare = sess('compare'); //[18, 19, 17, 16];+ $results = [];+ $names = [];+ $specs = [];++ if ($product_id) {+ $names = [];++ $prod = new ProductSQL();+ $results = $prod->getAll(['product_id' => $product_id] + $this->global);++ $category = new AttributeSQL();+ $attributes = $category->getAll(['product_id' => $product_id] + $this->global);++ if (isset($attributes['attribute'])) {+ foreach ($attributes['attribute'] as $attr) {+ $attrs[$attr['product_id']][$attr['attribute_id']] = $attr['value'];+ $names[$attr['attribute_id']] = $attr['name'];+ }+ }++ if ($results && isset($results['products'])) {+ $tax = Tax::getInstance($this->global);+ $currency = Currency::getInstance($this->global);++ foreach ($results['products'] as $id => &$product) {+ if (isset($product['image']) && $product['image']) {+ $product['image'] = Images::image($product['image'], 'product', 'thumb');+ }++ $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']];+ $product['url'] = url('product/product/index', $url);+ $product['add_cart_url'] = url('cart/cart/add', ['product_id' => $product['product_id']]);+ $product['remove_url'] = url('cart/compare/remove', ['product_id' => $product['product_id']]);+ $product['buy_url'] = url('checkout/checkout/index', ['product_id' => $product['product_id']]);++ $product['price_tax'] = $tax->addTaxes($product['price'], $product['tax_type_id']);+ $product['price_tax_formatted'] = $currency->format($product['price_tax']);+ $product['price_formatted'] = $currency->format($product['price']);+ }++ $specs = [];++ foreach ($names as $attribute_id => $name) {+ foreach ($results['products'] as $prod) {+ $id = $prod['product_id'];+ $specs[$attribute_id][$id] = $attrs[$id][$attribute_id] ?? '-';+ }+ }+ }+ }++ $this->view->products = $results;+ $this->view->names = $names;+ $this->view->specs = $specs;+ }++ private function action($action) {+ $productId = (int)($this->request->request['product_id'] ?? false);++ if ($productId) {+ $compare = sess('compare');++ switch ($action) {+ case 'add':+ $compare[$productId] = $productId;++ break;++ case 'remove':+ unset($compare[$productId]);++ break;+ }++ sess(['compare' => $compare]);+ }++ $this->index();}function add() {- $productId = $this->request->request['product_id'];+ return $this->action('add');+ }++ function remove() {+ return $this->action('remove');}}diff --git a/app/template/cart/compare.tpl b/app/template/cart/compare.tplnew file mode 100644index 0000000..cf73573--- /dev/null+++ b/app/template/cart/compare.tpl@@ -0,0 +1,70 @@+import(common.tpl)++[data-v-page] [data-v-compare-*]|innerText = $this->compare['@@__data-v-compare-(*)__@@']++@compare-product = [data-v-products] [data-v-product]++@compare-product|deleteAllButFirstChild++@compare-product|before = <?php++$products = $this->products['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 $key => $product) {+?>++ //@compare-product [data-v-product-name] = $product['name']+ //@compare-product [data-v-product-content] = $product['content']+ //@compare-product [data-v-product-amount] = <?php echo $product['amount'];?>++ @compare-product|data-product_id = $product['product_id']+ @compare-product|data-key = $key++ @compare-product img[data-v-product-image]|src = $product['image']++ //catch all data attributes+ @compare-product [data-v-product-*]|innerText = $product['@@__data-v-product-(*)__@@']+ @compare-product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']+ @compare-product img[data-v-product-*]|src = $product['@@__data-v-product-(*)__@@']+ @compare-product input[data-v-product-*]|value = $product['@@__data-v-product-(*)__@@']++@compare-product|after = <?php }?>+++[data-v-specs]|deleteAllButFirstChild++[data-v-specs]|before = <?php+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => 'product_spec_value_id'] : false;+$specs = empty($this->specs) ? $_default : $this->specs;+$index = 0;+$name = current($this->names);+if($specs) {+ foreach ($specs as $values) {?>++ [data-v-specs-name] = $name++[data-v-specs]|after = <?php+ $index++;+ $name = next($this->names);+ }+}+?>++@compare-spec = [data-v-specs] [data-v-spec]+@compare-spec|deleteAllButFirstChild++@compare-spec|before = <?php+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => 'product_spec_value_id'] : false;+$values = empty($values) ? $_default : $values;++if($values) {+ foreach ($values as $value) { ?>++ @compare-spec = $value+++@compare-spec|after = <?php }+}+?>\ No newline at end of file