MyShortlist end NS PRO

9 months 3 weeks ago #7 by Frank
Replied by Frank on topic MyShortlist and NS PRO
I am creating mailing lists (NS Pro) with users clicking on "add my favoritre" (My-shortlist).
The id in the #__nspro_lists table (mailinglist id) will be the ID of the item.
This my problem.
I don't need the values of the entire $selected_list but the single id

In helper.php part of my code is:
public function saveNewsletter() {
   
    if ($this->save_method != '1') {
      setcookie($cprefix.'myshortlist', $this->listAsString($selected_list), time()+60*60*24*365, '/');
    }
    if ((!$this->user->guest) && ($this->save_method != '0')) {
      $db = JFactory::getDBO();
      $db->setQuery('SELECT * FROM `#__nspro_subs`'.
                    ' WHERE `userid`="'.$this->user->id.'"');
      if ($db->loadResult()) {
        $db->setQuery('UPDATE `#__nspro_subs` SET `mailing_list` = "'.$item->aid.'"'.   // $item->aid is my problem?
                      ' WHERE `userid` = "'.$this->user->id.'"');
      }
      else {
        $db->setQuery('INSERT INTO `#__nspro_subs` (`userid`, `name`, `email`, `mailing_list`)'.
                      ' VALUES ("'.$this->user->id.'", "'.$this->user->name.'",'.
                              ' "'.$this->user->email.'", "'.$item->aid.'")');	  
      }
      $db->execute();
    }
  }


$item->aid is my problem?

Please Log in or Create an account to join the conversation.

9 months 3 weeks ago #8 by Christopher Mavros
Replied by Christopher Mavros on topic MyShortlist and NS PRO
I lost you somewhere. I'm not sure I completely understand what you are trying to achieve, but here's what I can tell you:
1. If you edit the helper.php of MyShortlist, unfortunately, you won't be able to receive updates, because they will overwrite what you have done. If you definitely need to do that, you may write your code in an external file in the same directory (like custom-helper.php) and then write the saveNewsletter function like
  public function saveNewsletter() {
    include('custom-helper.php');
    // For a static function
    CustomHelper::saveNewsletter();

    // For a non-static function
    $custom_helper = new customHelper();
    $custom_helper->saveNewsletter();
  }

2. You can easily get the item A-ID (which used to mean article ID at the beginning) by using the helper's getAID function.

3. The NS Pro subs table mailing_lists column is not normalized. Each subscriber can only have a single row, with all their mailing list IDs in the mailing_lists column as a comma separated list, like so: 1,2,3

Let me know if I can help any further.

Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!

Please Log in or Create an account to join the conversation.

Moderators: Christopher Mavros