Create customers in admin & assign categories to users

Open to all! Ask other shopowners for help.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Create customers in admin & assign categories to users

Post by ecartz »

Code: Select all

public function listen_infoBox($parameters) {
  $parameters['contents'][] = ['text' => 'Private Category' . '<br>' . (new Tickable('private', ['value' => '1', 'class' => 'custom-control-input', 'id' => 'private'], 'checkbox'))->tick($GLOBALS['cInfo']->private)];
    
  }
Note that you probably want this in some kind of if statement, because as is, it would show in every infobox on the catalog page. Presumably that's not what you want.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Create customers in admin & assign categories to users

Post by burt »

Code: Select all

function listen_infoBox($parameters) {
    $parameters['contents'][] = ['class' => '',
                                 'text'  => '<div class="custom-control custom-switch">' . (new Tickable('private', ['value' => $GLOBALS['cInfo']->private, 'class' => 'custom-control-input', 'id' => 'private'], 'checkbox'))->tick($GLOBALS['cInfo']->private) . '<label for="private" class="custom-control-label text-muted"><small>Private Category</small></label></div>'];
  }
The tickbox needs the relevant bootstrap HTML surrounding it..
I am not here to build for you.
I am here to build with you. Let's help each other.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Create customers in admin & assign categories to users

Post by LeeFoster »

That's got it showing, now to do all the update stuff.

One thing though, and it's minor, is there any way to change the location the tick box appears?
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Create customers in admin & assign categories to users

Post by LeeFoster »

Almost there with this, last piece of the puzzle is setting the category to private, I have the checkbox but it's not updating the database.

This is my code -

Code: Select all

public function listen_infoBox($parameters) {
		 
		 if(isset($_GET['action']) && $_GET['action'] == 'edit_category'){
  $parameters['contents'][] = ['text' => 'Private Category'];
  $parameters['contents'][] = ['class' => '',
                                 'text'  => '<div class="custom-control custom-switch">' . (new Tickable('private', ['value' => $GLOBALS['cInfo']->private, 'class' => 'custom-control-input', 'id' => 'private'], 'checkbox'))->tick($GLOBALS['cInfo']->private) . '<label for="private" class="custom-control-label text-muted"></label></div>'];
		 }
  }
    

  public function listen_productActionSave() {
	  $private = $_POST['private'];
	  $sql_data = [
            'private' => (int)$private,
            'last_modified' => NOW(),
          ];
    
	 $GLOBALS['db']->perform('categories', $sql_data, 'update', "categories_id = " . (int)$_GET['cID']); 
  }
I am 99% certain it's the way I'm dealing with the $_POST however my brain just can't comprehend what I'm doing wrong. Updating the last_modified column does go through.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Create customers in admin & assign categories to users

Post by ecartz »

You are editing the category. Why are you trying to save the value in the product action? You'd want listen_updateCategory. And possibly listen_insertCategory but that would require more changes to the infoBox listener.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Create customers in admin & assign categories to users

Post by LeeFoster »

ecartz wrote: Tue Jun 28, 2022 10:59 am You are editing the category. Why are you trying to save the value in the product action? You'd want listen_updateCategory. And possibly listen_insertCategory but that would require more changes to the infoBox listener.
Get what you're saying but it seems to work for updating the last_modified column, in addition this is what I got from the admin comments hook, that one uses updateProductAction.

Changed listen_productActionSave to listen_updateCategory and still encountering the same issue.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Create customers in admin & assign categories to users

Post by ecartz »

I don't think that your code is working for the last_modified either. Note that update_category already updates the last_modified column. Looking at update category suggests

Code: Select all

	 $GLOBALS['db']->perform('categories', $sql_data, 'update', "categories_id = " . (int)$_POST['categories_id']);
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Create customers in admin & assign categories to users

Post by ecartz »

Or actually, toss it entirely and do

Code: Select all

public function listen_updateCategoryPrep() {
  if (isset($_POST['private'])) {
    $GLOBALS['sql_data']['private'] = Text::input($_POST['private']);
  }
}
That section's hooked between the initialization and the perform.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Create customers in admin & assign categories to users

Post by LeeFoster »

ecartz wrote: Tue Jun 28, 2022 12:28 pm I don't think that your code is working for the last_modified either. Note that update_category already updates the last_modified column. Looking at update category suggests

Code: Select all

	 $GLOBALS['db']->perform('categories', $sql_data, 'update', "categories_id = " . (int)$_POST['categories_id']);
Yeah, I think you might be right there
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Create customers in admin & assign categories to users

Post by LeeFoster »

ecartz wrote: Tue Jun 28, 2022 12:34 pm Or actually, toss it entirely and do

Code: Select all

public function listen_updateCategoryPrep() {
  $GLOBALS['sql_data']['private'] = Text::input($_POST['private']);
}
That section's hooked between the initialization and the perform.
Does Text::input work for a checkbox?


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply