Forums / Contribution-Writing Guidelines / Plugin Manager (in Zen Cart 1.5.7+)

Plugin Manager (in Zen Cart 1.5.7+)

Views: 25,464

Results 21 to 29 of 29
16 Apr 2021, 6:44 PM
#21
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

Plugin Manager (in Zen Cart 1.5.7+)

swguy:

This would be amazingly confusing. If your plugin has front end and back end elements, just do it the old way for 1.5.7 and below.

Yes also probably more difficult. I'll stick to old way roll on 1.5.8.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

3 Sep 2021, 2:06 AM
#22
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: Plugin Manager (in Zen Cart 1.5.7+)

I am trying to put my admin program into the zc_plugin folder and have hit a 3 day snag trying to figure out how to proceed.

Fresh install of 1.5.7c
Ubuntu 20.04 LAMP stack
DisplayLogs module installed
My module partially installed
PHP 7.4

Using the DisplayLogs file structure as an example, I successfully registered my plugin in admin and proceeded with setting up the installer. I have been able to interact with modifying the db but have came to a screeching halt.

I need to retrieve the configuration_group_id to do my inserts into the configuration table. Here is what worked in 1.5.6c:

$setup_gID = $db->execute("select `configuration_group_id`
from " . TABLE_CONFIGURATION_GROUP . " 
where `configuration_group_title` = 'EZ-Feeds Settings' ");
if(isset($setup_gID->fields['configuration_group_id'])) {
  $gID_setup = $setup_gID->fields['configuration_group_id'];
}

Unfortunately, I have no experience with working with php classes. I have read tons of how to pages but nothing is sinking in or working for me.

I have tried various forms of this (from configuration.php):

$gID = (isset($_GET['gID'])) ? $_GET['gID'] : 1;
$_GET['gID'] = $gID;
$cfg_group = $db->Execute("SELECT configuration_group_title
                           FROM " . TABLE_CONFIGURATION_GROUP . "
                           WHERE configuration_group_id = " . (int)$gID);

It returned 1, instead of 31, in one of my attempts...so I tried various forms of this:

$gID_setup = 
"select `configuration_group_id` from " . TABLE_CONFIGURATION_GROUP . " 
where `configuration_group_title` = 'EZ-Feeds Settings' ";
$this->executeInstallerSql($gID_setup);

var_dump($this->gID_setup);
exit;

NULL was returned in one instance and bool(true) in another.

I am blurry eyed and exhausted from trying to figure it out.

I would appreciate some insight on how to proceed.

BTW...great addition zc_plugin! It is going to be a huge time saver for developers after we figure out the ins and outs of it.

3 Sep 2021, 4:43 AM
#23
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: Plugin Manager (in Zen Cart 1.5.7+)

mikeel100:

I need to retrieve the configuration_group_id to do my inserts into the configuration table. Here is what worked in 1.5.6c:

$setup_gID = $db->execute("select configuration_group_id
from " . TABLE_CONFIGURATION_GROUP . "
where configuration_group_title = 'EZ-Feeds Settings' ");
if(isset($setup_gID->fields['configuration_group_id'])) {
$gID_setup = $setup_gID->fields['configuration_group_id'];
}


if this worked in v156c, i see no reason why it would not work in v157.  perhaps i would do:

```php
//from
if(isset($setup_gID->fields['configuration_group_id'])) {
//to
if(!($setup_gID->EOF) {

Unfortunately, I have no experience with working with php classes. I have read tons of how to pages but nothing is sinking in or working for me.

I have tried various forms of this (from configuration.php):

$gID = (isset($_GET['gID'])) ? $_GET['gID'] : 1;
$_GET['gID'] = $gID;
$cfg_group = $db->Execute("SELECT configuration_group_title
FROM " . TABLE_CONFIGURATION_GROUP . "
WHERE configuration_group_id = " . (int)$gID);

> 
> It returned 1, instead of 31, in one of my attempts...

i am not sure what 'it' refers to.

this code has little to do with classes.  i would suggest studying a little more on php.  your first line creates a var named $gID.  if there is $_GET['gID'], $gID gets assigned that value, else it gets assigned 1.  the second line assigns the $_GET['gID'] var to what $gID is.  it makes no sense to me.

do you understand _GET vars?  i would suggest reading about them.  it is the way to pass data from a URL.  reassigning it makes no sense (to me) in this context.

> so I tried various forms of this:
> 
> ```
$gID_setup = 
"select `configuration_group_id` from " . TABLE_CONFIGURATION_GROUP . " 
where `configuration_group_title` = 'EZ-Feeds Settings' ";
$this->executeInstallerSql($gID_setup);

var_dump($this->gID_setup);
exit;

NULL was returned in one instance and bool(true) in another.

i normally use something called print_r as opposed to var_dump. but now we are into a class.... and executeInstallerSql will only return true or false. i have no idea what this might be: $this->gID_setup.

i agree that the zc_plugins is a GREAT addition to ZC. but the problems that you are having are more related to your understanding of php than anything special about ZC. IMO.

not sure that helps.... but keep trying!

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

3 Sep 2021, 9:10 PM
#24
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: Plugin Manager (in Zen Cart 1.5.7+)

Carl, the code used in 1.5.6c was not buried in an extended class like it is in 1.5.7c zc_plugins.

Have you successfully added an admin plugin to the new structure? I seriously doubt it by the way you failed to answer my question...thanks for responding though.

You would know what "it" is if you read the query...

Yes, I know what GET and POST are...they did not work in my 1.5.6 version...thus the long code.

I will restate it again as plain as I can...

Within an extended class (ScriptedInstaller.php), how do I retrieve the configuration_group_id from the configuration group table while working in the zc_plugin file structure?

Below, is from ScriptedInstaller.php located in zc_plugins>MyPlugin>version>installer...this file is provided with the ZC distribution in the DisplayLogs folder under zc_plugins. I simply copied it and used as the basis for adding my plugin.

use Zencart\PluginSupport\ScriptedInstaller as ScriptedInstallBase;

class ScriptedInstaller extends ScriptedInstallBase {
  protected function executeInstall() {


[B]HOW DO I RETURN THE configuration_group_id FROM THE configuration_group TABLE WITHIN THIS STRUCTURE?
$gID_setup = "select `configuration_group_id` from " . TABLE_CONFIGURATION_GROUP . " where `configuration_group_title` = 'EZ-Feeds Settings' ";
$this->executeInstallerSql($gID_setup); DO I HAVE TO MODIFY THIS executeInstallerSql FUNCTION? 
[/B]
.................

I will continue reading until I understand how to work with extended classes. I have been reading for 4 days now without figuring out how to get what I need.

I was simply looking for a little help...anyone else?

3 Sep 2021, 10:41 PM
#25
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: Plugin Manager (in Zen Cart 1.5.7+)

I figured out something that will work...had to dig backwards through the functions.

Outside of zc_plugins, $db->execute precedes sql calls...inside of zc_plugins, $this->dbConn->execute($sql) precedes sql calls.

$sql = "select `configuration_group_id` from " . TABLE_CONFIGURATION_GROUP . " where `configuration_group_title` = 'EZ-Feeds Settings' ";
$setup_gID = $this->dbConn->execute($sql); 

if(isset($setup_gID->fields['configuration_group_id'])) {
 $gID = $setup_gID->fields['configuration_group_id'];
}
3 Sep 2021, 11:49 PM
#26
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Plugin Manager (in Zen Cart 1.5.7+)

mikeel100:

I figured out something that will work...had to dig backwards through the functions.

Outside of zc_plugins, $db->execute precedes sql calls...inside of zc_plugins, $this->dbConn->execute($sql) precedes sql calls.

$sql = "select configuration_group_id from " . TABLE_CONFIGURATION_GROUP . " where configuration_group_title = 'EZ-Feeds Settings' ";
$setup_gID = $this->dbConn->execute($sql);

if(isset($setup_gID->fields['configuration_group_id'])) {
$gID = $setup_gID->fields['configuration_group_id'];
}

For "reverse" compatibility, could also use either:

global $db;
$db->Execute($sql);

or

$GLOBALS['db']->Execute($sql);

Otherwise, and to piggy back on the some of the previous discussion, the thing with $this->executeInstallerSql is that it returns only true or false upon completion... It does not return anything from the query (other than success/failure)...  That said and I still haven't tried it yet, but it may be possible to use MySQL temporary type variables within multiple queries to collect/use data without bringing the data back to the php space.

Also, to potentially feed back about why the assignment of $_GET might be done would be to actually ensure that the value is assigned for follow on use, even though it would be better to just use the newly created $gID and if for some reason a link needed to be generated with that information, then just add it in as part of the link generation.

To also reiterate a previous suggestion, this:

if(isset($setup_gID->fields['configuration_group_id'])) {
$gID = $setup_gID->fields['configuration_group_id'];
}

should instead be written:

if(!$setup_gID->EOF) {
$gID = $setup_gID->fields['configuration_group_id'];
}

There are of course a few things that will need to be considered after this:
May need to test if $gID is set or not before attempting to use the value or perhaps assign a default value (which is what the previous code attempted by setting it to 1 if it didn't exist...

But as far as use of $_GET['gID'] within the installer of the plugins, well, at this point in accessing the admin, gID is not set because one is not navigating through the configuration menu.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

4 Sep 2021, 4:17 AM
#27
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: Plugin Manager (in Zen Cart 1.5.7+)

mikeel100:

Have you successfully added an admin plugin to the new structure? I seriously doubt it by the way you failed to answer my question...thanks for responding though.

seriously doubt no more. my plugin making use of the new zc_plugin structure:

https://www.zen-cart.com/downloads.php?do=file&id=2279

zc_plugins getting uninstalled first reported by me:

https://github.com/zencart/zencart/issues/4014

a screenshot of one of my clients zc_plugins modules (most of which are not available for public download):

Attachment 19710

good luck resolving your issues and understanding extending classes. i would suggest not disparaging anyone on this board who makes a valiant attempt to help you with your problems.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

4 Sep 2021, 2:18 PM
#28
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: Plugin Manager (in Zen Cart 1.5.7+)

use Zencart\PluginSupport\ScriptedInstaller as ScriptedInstallBase;

class ScriptedInstaller extends ScriptedInstallBase
{
    protected function executeInstall()
    {
// you need the next line:
        global $db;

        $sql = "select `configuration_group_id` from " . TABLE_CONFIGURATION_GROUP . " 
where `configuration_group_title` = 'EZ-Feeds Settings' ";
        $gidQuery = $db->Execute($sql);
        if (!$gidQuery->EOF) {
            $yourNUMBER = $gidQuery->fields['configuration_group_id'];
        }

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

6 Sep 2021, 8:55 PM
#29
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: Plugin Manager (in Zen Cart 1.5.7+)

Thanks for all the replies and suggestions.

I ended up moving a protected function into the scripted installer from the plugin installer script...

  protected function executeEZFeedsSql($sql) {
    $this->dbConn->dieOnErrors = false;
    $data = $this->dbConn->Execute($sql);
    if ($this->dbConn->error_number !== 0) {
        $this->errorContainer->addError(0, $this->dbConn->error_text, true, PLUGIN_INSTALL_SQL_FAILURE);
        return false;
    }
    $this->dbConn->dieOnErrors = true;
    return $data;
  }

Then retrieving what I needed with:

$setup_gID = $this->executeEZFeedsSql($sql);
		if(isset($setup_gID->fields['configuration_group_id'])) {
			$gID = $setup_gID->fields['configuration_group_id'];
		}

My plugin is working fine now. It took several hours to figure out that I had to change my language file root folder path to point to the zc_plugins folder and I also had to move a few language file table, folder and file paths into the setup script.

I will use compare both of your comments against what I have implemented and change as suggested where needed.

Carl, sorry for being so short. I was tired and frustrated from the lack of an answer from your (long and mostly unnecessary (first response)...will take it with a grain of salt the next time.