Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zen4All committed Jan 9, 2020
2 parents f2ed39f + aae4543 commit 0905151
Show file tree
Hide file tree
Showing 64 changed files with 5,966 additions and 1,513 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,4 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg
/nbproject/
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}

$autoLoadConfig[999][] = array(
'autoType' => 'init_script',
'loadFile' => 'init_compare_products.php'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}

$module_constant = 'COMPARE_PRODUCTS_VERSION';
$module_installer_directory = DIR_FS_ADMIN . 'includes/installers/compare_products';
$module_name = 'Compare Products';
$zencart_com_plugin_id = 1273;

$configuration_group_id = '';
if (defined($module_constant)) {
$current_version = constant($module_constant);
} else {
$current_version = '0.0.0';
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION_GROUP . " (configuration_group_title, configuration_group_description, sort_order, visible)
VALUES ('" . $module_name . "', '" . $module_name . " Settings', 1, 1);");
$configuration_group_id = $db->Insert_ID();

$db->Execute("UPDATE " . TABLE_CONFIGURATION_GROUP . "
SET sort_order = " . $configuration_group_id . "
WHERE configuration_group_id = " . $configuration_group_id . ";");

$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, set_function)
VALUES ('Version', '" . $module_constant . "', '0.0.0', 'Version installed:', " . $configuration_group_id . ", 0, NOW(), NOW(), 'trim(');");
}
if ($configuration_group_id == '') {
$config = $db->Execute("SELECT configuration_group_id
FROM " . TABLE_CONFIGURATION . "
WHERE configuration_key= '" . $module_constant . "'");
$configuration_group_id = $config->fields['configuration_group_id'];
}

$installers = scandir($module_installer_directory, 1);

$newest_version = $installers[0];
$newest_version = substr($newest_version, 0, -4);

sort($installers);
if (version_compare($newest_version, $current_version) > 0) {
foreach ($installers as $installer) {
if (version_compare($newest_version, substr($installer, 0, -4)) >= 0 && version_compare($current_version, substr($installer, 0, -4)) < 0) {
include($module_installer_directory . '/' . $installer);
$current_version = str_replace('_', '.', substr($installer, 0, -4));
$db->Execute("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = '" . $current_version . "'
WHERE configuration_key = '" . $module_constant . "'
LIMIT 1;");
$messageStack->add("Installed " . $module_name . " v" . $current_version, 'success');
}
}
}

// Version Checking
$module_file_for_version_check = ($module_file_for_version_check != '') ? DIR_FS_ADMIN . $module_file_for_version_check : '';
if ($zencart_com_plugin_id != 0 && $module_file_for_version_check != '' && $_SERVER["PHP_SELF"] == $module_file_for_version_check) {
$new_version_details = plugin_version_check_for_updates($zencart_com_plugin_id, $current_version);
if ($_GET['gID'] == $configuration_group_id && $new_version_details != false) {
$messageStack->add("Version " . $new_version_details['latest_plugin_version'] . " of " . $new_version_details['title'] . ' is available at <a href="' . $new_version_details['link'] . '" target="_blank">[Details]</a>', 'caution');
}
}

if (!function_exists('plugin_version_check_for_updates')) {

function plugin_version_check_for_updates($plugin_file_id = 0, $version_string_to_compare = '', $strict_zc_version_compare = false)
{

if ($plugin_file_id === 0) {
return false;
}

if (false === ENABLE_PLUGIN_VERSION_CHECKING) {
return false;
}

$new_version_available = false;
$versionServer = new VersionServer();
$data = json_decode($versionServer->getPluginVersion($plugin_file_id), true);

if (null === $data || isset($data['error'])) {
if (!empty(LOG_PLUGIN_VERSIONCHECK_FAILURES)) {
error_log('CURL error checking plugin versions: ' . print_r($data['error'], true));
}
return false;
}

if (!is_array($data)) {
$data = json_decode($data, true);
}

if (strcmp($data[0]['latest_plugin_version'], $version_string_to_compare) > 0) {
$new_version_available = true;
}

// check whether present ZC version is compatible with the latest available plugin version
if (!defined('PLUGIN_VERSION_CHECK_MATCHING_OVERRIDE') || empty(PLUGIN_VERSION_CHECK_MATCHING_OVERRIDE)) {
$zc_version = PROJECT_VERSION_MAJOR . '.' . preg_replace('/[^0-9.]/', '', PROJECT_VERSION_MINOR);
if ($strict_zc_version_compare) {
$zc_version = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR;
}
if (!in_array('v' . $zc_version, $data[0]['zcversions'], false)) {
$new_version_available = false;
}
}

return $new_version_available ? $data[0] : false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
$admin_page = 'configCompareProducts';
// delete configuration menu
$db->Execute("DELETE FROM " . TABLE_ADMIN_PAGES . " WHERE page_key = '" . $admin_page . "' LIMIT 1;");
// add configuration menu
if (!zen_page_key_exists($admin_page)) {
if ((int)$configuration_group_id > 0) {
zen_register_admin_page($admin_page,
'BOX_CONFIGURATION_COMPARE_PRODUCTS',
'FILENAME_CONFIGURATION',
'gID=' . $configuration_group_id,
'configuration',
'Y',
$configuration_group_id);

$messageStack->add('Enabled MODULE Configuration Menu.', 'success');
}
}


global $sniffer;
if (!$sniffer->field_exists(TABLE_CONFIGURATION, 'COMPARE_VALUE_COUNT')) {
$db->Execute("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_key = 'COMPARE_PRODUCTS_VALUE_COUNT',
configuration_group_id = " . $configuration_group_id . ",
sort_order = 2
WHERE configuration_key = 'COMPARE_VALUE_COUNT'");
}
if (!$sniffer->field_exists(TABLE_CONFIGURATION, 'COMPARE_DESCRIPTION')) {
$db->Execute("UPDATE " . TABLE_CONFIGURATION . "
SET configuration_key = 'COMPARE_PRODUCTS_DESCRIPTION',
configuration_group_id = " . $configuration_group_id . ",
sort_order = 3
WHERE configuration_key = 'COMPARE_DESCRIPTION'");
}

$db->Execute("INSERT IGNORE INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function)
VALUES ('Enable Product Compare', 'COMAPRE_STATUS', 'false', 'If true, the Compare buttons will be shown in the shop at the selected pages (depending on the settings below).', " . $configuration_group_id . ", 1, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),'),
('Max Products to Compare', 'COMPARE_PRODUCTS_VALUE_COUNT', '4', 'The number of products to compare at one time.', " . $configuration_group_id . ", 2, now(), ''),
('Display Product Description', 'COMPARE_PRODUCTS_DESCRIPTION', '150', 'Do you want to display the Product Description?<br /><br />0= OFF<br />150= Suggested Length, or enter the maximum number of characters to display', " . $configuration_group_id . ", 3, now(), ''),
('Enable Product Compare on Product Listing', 'COMAPRE_STATUS_PRODUCT_LISTING', 'false', 'If true, the Compare buttons will be shown on the Product Listing pages.', " . $configuration_group_id . ", 4, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),'),
('Product Compare', 'DEFINE_COMPARE_STATUS', '1', 'Enable the Product Compare Link/Text?<br />0= Link ON, Define Text OFF<br />1= Link ON, Define Text ON<br />2= Link OFF, Define Text ON<br />3= Link OFF, Define Text OFF', '25', '84', now(), 'zen_cfg_select_option(array(\'0\', \'1\', \'2\', \'3\'),');");
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
$db->Execute("INSERT IGNORE INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function)
VALUES ('Enable Product Compare on Product Featured Listing', 'COMPARE_PRODUCTS_FEATURED_STATUS', 'false', 'If true, the Compare buttons will be shown on the Product Featured Listing pages.', " . $configuration_group_id . ", 5, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),'),
('Enable Product Compare on Product New Listing', 'COMPARE_PRODUCTS_NEW_STATUS', 'false', 'If true, the Compare buttons will be shown on the Product New Listing pages.', " . $configuration_group_id . ", 6, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),'),
('Enable Product Compare on Product All Listing', 'COMPARE_PRODUCTS_ALL_STATUS', 'false', 'If true, the Compare buttons will be shown on the Product All Listing pages.', " . $configuration_group_id . ", 7, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),'),
('Enable Product Compare on Product Details Page', 'COMPARE_PRODUCTS_DETAIL_STATUS', 'false', 'If true, the Compare buttons will be shown on the Product Details Page.', " . $configuration_group_id . ", 8, now(), 'zen_cfg_select_option(array(\'true\', \'false\'),');");
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

define('BOX_CONFIGURATION_COMPARE_PRODUCTS', 'Compare Products Settings');
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}

// ----
// Initialize the plugin's observer ...
//
$autoLoadConfig[200][] = array(
'autoType' => 'class',
'loadFile' => 'observers/CompareProductsObserver.php'
);
$autoLoadConfig[200][] = array(
'autoType' => 'classInstantiate',
'className' => 'CompareProductsObserver',
'objectName' => 'compareProductsObserver'
);
107 changes: 107 additions & 0 deletions 1_Installation_files/includes/classes/ajax/zcAjaxCompareProducts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* Compare Products
*
* @copyright Portions Copyright 2003-2020 Zen Cart Development Team
* @copyright Copyright 2020 Zen4All
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/
class zcAjaxCompareProducts extends base {

var $selected;
var $compare_array;
var $comp_images;
var $compare_warning;
var $comp_value_count;

// add new products selected
public function addProduct()
{
$compareProductsArray = (isset($_SESSION['compareProducts']) ? $_SESSION['compareProducts'] : '');
$selected = (int)$_POST['compare_id'];
$compare_array = array();
$compare_warning = '';
$comp_value_count = ($compareProductsArray != '' ? count($compareProductsArray) : 0);

include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/compare.php');

if ($comp_value_count < COMPARE_PRODUCTS_VALUE_COUNT) {
$compare_array[] = $selected;
if ($compareProductsArray != '') {
foreach ($compareProductsArray as $compareProduct) {
if ($compareProduct != $selected) {
$compare_array[] = $compareProduct;
}
}
}
$_SESSION['compareProducts'] = array_unique($compare_array);
} else {
$compare_warning = '<div id="compareWarning">' . COMPARE_WARNING_START . COMPARE_PRODUCTS_VALUE_COUNT . COMPARE_WARNING_END . '</div>';
}
$result = $this->getProducts($_SESSION['compareProducts']);

$button = '<button type="button" id="buttonCompareSelectProductId_' . $selected . '" onclick="compare(\'' . $selected . '\',\'removeProduct\');"><i class="fa fa-minus"></i> ' . COMPARE_DEFAULT . '</button>';

return([
'data' => $result,
'button' => $button
]);
}

// remove products
public function removeProduct()
{
$selected = (int)$_POST['compare_id'];
$newCompareArray = [];
if (isset($_SESSION['compareProducts']) && $_SESSION['compareProducts'] != '') {
foreach ($_SESSION['compareProducts'] as $value) {
if ($value != $selected) {
$newCompareArray[] = $value;
}
}
}
if (!empty($newCompareArray)) {
$_SESSION['compareProducts'] = $newCompareArray;
} else {
$_SESSION['compareProducts'] = '';
}

$button = '<button type="button" id="buttonCompareSelectProductId_' . $selected . '" onclick="compare(\'' . $selected . '\',\'addProduct\');"><i class="fa fa-plus"></i> ' . COMPARE_DEFAULT . '</button>';

$result = $this->getProducts($_SESSION['compareProducts']);
return([
'data' => $result,
'button' => $button
]);
}

private function getProducts($compareList)
{
global $db;
$comp_images = '';
// return new value for the session
if (!empty($compareList)) {
foreach ($compareList as $value) {
$product_comp_image = $db->Execute("SELECT p.products_id, p.master_categories_id, pd.products_name, p.products_image
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON pd.products_id = p.products_id
WHERE p.products_id = " . (int)$value);
$comp_images .= '<div class="compareAdded">';
$comp_images .= '<a href="' . zen_href_link(zen_get_info_page($product_comp_image->fields['products_id']), 'cPath=' . (zen_get_generated_category_path_rev($product_comp_image->fields['master_categories_id'])) . '&products_id=' . $product_comp_image->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $product_comp_image->fields['products_image'], $product_comp_image->fields['products_name'], '', '35', 'class="listingProductImage"') . '</a>';
$comp_images .= '<div>';
$comp_images .= '<button type="button" onclick="compare(\'' . $product_comp_image->fields['products_id'] . '\', \'removeProduct\')" title="remove" class="btn btn-default btn-xs">' . COMPARE_REMOVE . '</button>';
$comp_images .= '</div>';
$comp_images .= '</div>';
}
}

// return HTML view of found products
if (!empty($comp_images)) {
$data = '<div id="compareMainWrapper"><div class="compareAdded compareButton">' . '<a href="' . zen_href_link('compare') . '" title="compare">' . '<span class="cssButton">' . COMPARE_DEFAULT . '</span></a></div>' . $comp_images . '</div>';
}
return $data;
}

}
Loading

0 comments on commit 0905151

Please sign in to comment.