1. Osclass Forum
  2. Other
  3. Search on publish date and after 14 days email user about op...

Search on publish date and after 14 days email user about options

Started by smos, October 13, 2021, 6:05 pm

smos

Again i am having an issue with one off my plugins and all help is welcome...

The plugin sends an email to user to inform them about options they have to update the listing to premium.

At this moment the mail gets send immediate after posting a new listing with function in folder/index.php

email_status($item['pk_i_id']);

Whats needed is to  create new function, that will retrieve listings created 14 days ago, loop them and call function  email_status($item['pk_i_id']);  into daily cron hook. 
I am wondering if this can be changed....

It seems logic to me that a possible update on the listing is then and not after posting a new just added one.
Someone here with this skills to fix my problem? I think it is not easy so i am willing to pay for this.

Regards,
Marc


  • << Last edit: October 14, 2021, 5:17 pm by smos >>
  • Quote

smos

 No one here that is able to help?

calinbehtuk

I think that you need to ask the question to the developer of that plugin. He knows the plugin and how is build.

smos

The problem is that he doesn't know himself on how to retrieve listings that are created 14 days ago :-)

What i actually need is from table t_item the dt_expiration date minus 14 days. Do yo think it is possible to count 14 day off?

I am trying with:

Code: [Select]
​function item_expire_date($item_id = null) {
 
    $item_id = ($item_id < 1 ) ? ((osc_item_id() > 0) ? osc_item_id() : null)) : $item_id;
    $dao = new DAO();
    $table = 't_item;
    $dao->dao->select('*');
    $dao->dao->where('item_id', $item_id);
    $dao->dao->from(DB_TABLE_PREFIX . $table);
    $result = $dao->dao->get();
    if (!$result->row()) {
        return NULL;
    }
    $date = $result->row();

    return $date['expiration_date'];
}

//listings that Expire, should be notified 14 days previous to expiration date
  function  item_expire_date() {
  $today = date('Ymd', strtotime(' -14 days', time()));

    ModelBO::newInstance()->getItem( $item['pk_i_id'], 0, 0, Params::getParam('bo_mgr_status') );

    if($status_email == 1) {
      email_status($item['pk_i_id']);
    }
  }


  • << Last edit: October 16, 2021, 12:03 pm by smos >>
  • Quote

smos

Still trying but again no luck after days......

Now last try was in modelBO:

Code: [Select]

Code: [Select]
​  public function get_dates14days_old($item_id, $today)  {
    $result = $this->dao->query('SELECT pk_i_id as $item_id, dt_pub_date as $today
    FROM '.$this->getTable_Item().' WHERE dt_pub_date = \'' . date('Y-m-d'(" -3 days ") .'\'
'));

    $aSet= array(
      'pk_i_id' => $item_id,
      'dt_pub_date' => $today );

    if( !$result) { return array(); }
    $result = $result->result();
    return $result->dao->get( $result->getTable_Item(),$aSet);
  }


My index.php looks for this function and should send an email .

Code in index.php is

Code: [Select]
​function get_dates14days_old() {
  $data = ModelBO::newInstance()->get_dates14days_old($item_id, $today);

  if(is_array($data) && count($data) > 0) {
    foreach($data as $d) {
    $item_id = Item::newInstance()->findByPrimaryKey($d['pk_i_id']);

      email_status($item_id['pk_i_id']);
      osc_add_hook('hook_email_bo_mgr_email_status','$item_id');

    }
  }

And nothing happens.... It seems like it doesn't look for items at all...... 
Help please?

  • << Last edit: October 24, 2021, 5:37 pm by smos >>
  • Quote

calinbehtuk

Your cron is working? In what context do you use that function? The function is triggered by?

smos

Cron works so that's not the problem. With this function I want to search for dates in database for items posted 14 days ago. There is an email in my email templates that should be sent when an item was posted 14 days ago to notify people that they can change their status.
The original function in model does this but the problem is that it sends the mail immediately after posting.

Original code in same index file is:


Code: [Select]

function bo_mgr_form_post($item) {
  $status_email = osc_get_preference('bo_mgr_status_email', 'plugin-bo_mgr') <> '' ?
osc_get_preference('bo_mgr_status_email', 'plugin-bo_mgr') : 1;
  $detail = ModelBO::newInstance()->getItem( $item['pk_i_id'] );

  if(Params::getParam('bo_mgr_status') <> '') {
    $status = ModelLS::newInstance()->getStatus( $status_id );
  }

  if(isset($detail['pk_i_id'])) {
    ModelBO::newInstance()->updateItem( $item['pk_i_id'], $detail['republish_times'],
$detail['form_used'], Params::getParam('bo_mgr_passwrd'),
Params::getParam('bo_mgr_mobile'), Params::getParam('bo_mgr_status'),
Params::getParam('bo_mgr_autorepublish') );

    //if status is "Sold" status, set item to expired
    if($status['status_sold'] == 1) {
      $today = date('Y-m-d', strtotime(' -1 day', time()));
      ModelLS::newInstance()->itemToExpired($item['pk_i_id'], $today);
    }
  } else {

    ModelBO::newInstance()->addItem( $item['pk_i_id'], 0, 0,
Params::getParam('bo_mgr_passwrd'), Params::getParam('bo_mgr_mobile'),
Params::getParam('bo_mgr_status'), Params::getParam('bo_mgr_autorepublish') );
    if($status_email == 1) {
    email_status($item['pk_i_id']);
    }


calinbehtuk

Sorry but I don't understand your code, it allot of code there that make no sense for me. You should ask for help from the developer of that plugin.

  • << Last edit: October 26, 2021, 6:49 pm by calinbehtuk >>
  • Quote

smos

@Calinbehtuk


Thank you for your reply.

But i do not need all this plugin code.

I only want to look for items that are posted 14 days ago in dt_items on pk_i_id, s_contact_email and dt_pub_date so i can send them the  bo_mgr_email_status email witch is already prepared in email templates.

With cron i can call the file daily then.



  • << Last edit: October 26, 2021, 6:37 pm by smos >>
  • Quote

calinbehtuk

Is not so simple, how you think.

You can get the items but every time the cron is running you will get all the items again and again. So this is not a solution. You will send the same message to the same users every time the cron is running.


This is more complicated than you imagine. Just to take the items that are passing 14 days from the published date is not enough.


Code: [Select]
​$date = date('Y-m-d H:i:s');
$days = 14;
$mSearch = new Search(false);
$mSearch->addItemConditions(sprintf("%st_item.dt_pub_date + INTERVAL '$days' DAY < '$date'", DB_TABLE_PREFIX));
$aItems = $mSearch->doSearch();
$iTotalItems = $mSearch->count();
if ($iTotalItems > 0) {
    foreach ($aItems as $item) {
        //some code here
    }
}


Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.