Osclass Support Forums

Osclass plugin support => Backoffice Manager Plugin => Topic started by: mwindey on August 24, 2021, 01:56:26 PM

Title: Is it possible to send mail 14days after publishing instead of instantly.
Post by: mwindey on August 24, 2021, 01:56:26 PM
I am wondering if this can be changed....
When a user is publishing a new listing an email is sent to inform about status change possibility to user (if checked in back office)
isn't it possible to send an email only after the listing has already been posted for 14 days?
It seems to me that a possible change to the listing is then and not after posting a new just added one.
No comments on plugin that is great... Only wondering  :)
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: MB Themes on August 24, 2021, 03:56:25 PM
Can you add example of that mail?
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: mwindey on August 24, 2021, 04:58:42 PM
@Frosticek

It is not about the mail itself but it is send when adding a new listing. Isn't it possible to change in code to check that after 14 days or so the mail is send then?

mailing is this:
Hello {CONTACT_NAME}!

We would like to inform you that you can change the status of your ad: {ITEM_TITLE} (#{ITEM_ID}) at any time.

Is your item still active, pending or already sold? Then you can change the status when you edit your listing or by simply clicking on the following links:

{STATUS_LIST}

{PASSWORD_TEXT}

Thank you for entrusting us with your ads. Regards,
{WEB_TITLE}
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: MB Themes on August 24, 2021, 07:31:18 PM
@mwindey
Thanks will check it out.
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: mwindey on August 24, 2021, 08:13:49 PM
Thanks for taking this seriously... Greatly appreciated ... i am not able to do it myself  :) :)
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: MB Themes on August 25, 2021, 11:34:58 AM
@mwindey
Basically is not such simple.
You must first remove this in index.php:
Code: [Select]
      email_status($item['pk_i_id']);

and then create new function, that will retrieve listings created 14 days ago, loop them and call above ^^ function to send mails on them.
Then this function must be added into daily cron hook.
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: mwindey on October 17, 2021, 11:10:30 AM
I am trying to put the code in modelBO and this doesn't give any errors for now although i think the code is not correct:

Code: [Select]
  public function get_pub_date( $item_id , $pub_date) {
    $pk_i_id = (osc_item_id);
    $this->dao->select(dt_pub_date);
    $this->dao->from( $this->getTable_item() );
    $this->dao->where(('$pk_i_id = osc_item_id()'));
    $this->dao->where(('$pub_date = dt_pub_date()'));                   
    $result = $dao->dao->get();
        if( !$result ) {
       return array();
    } return $result->row();
   }
}
Then i created a file in same folder model called pub.php with following code:
Code: [Select]
<?php
if(!defined('ABS_PATH')) {
  
define('ABS_PATH'dirname(dirname(dirname(dirname(__FILE__)))) . '/');
}
include 
'model/ModelBO.php';
include 
'model/email.php';
include 
'./dev/functions.php';

      function 
get_pub_date($pk_i_id$pub_date) {
      
$pk_i_id osc_item_id();
      
$item['pk_i_id'];
      
$pub_date date('Ymd'strtotime(' -14 days'time())); 
      
ModelBO::newInstance()->get_pub_date($pub_date());
      
ModelBO::newInstance()->getItem$item['pk_i_id'], 00Params::getParam('bo_mgr_status') );

      if(
$status_email == 1) {
      
email_status($item['pk_i_id']); 
    }
      foreach(
$items as $item) {
        
osc_run_hook('hook_email_bo_mgr_email_status'$item);
      }
    }
?>
Afterwards i can call the file with cron daily but till now no luck :-(  Anyone ??? all help appreciated ;-)
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: MB Themes on October 17, 2021, 08:33:36 PM
@mwindey
It looks quite wrong, messy and is not clear which function does what.
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: mwindey on October 19, 2021, 02:32:07 PM
It was only a test to see if it works.... I am trying all kinds of possibilities to achieve what i need.
The mail has to be send 14days after publishing a new listing because it is annoying for advertiser that if you put an item for sale you instantly receive an email on how to change status.... After 14 days is more logical because then you can start saying to advertiser that if the item isn't sold yet they can use promotional offers on your site to sell more easily and faster.
For a programmer this probably takes 15 min off time ...... For me 3days till now :-)

Next tryout is this in ModelBO:
Code: [Select]
  public function date_range($pk_i_id, $first, $last, $step = '+14 day', $output_format = 'd/m/Y') {
    $dao = new DAO();
    $table = 't_item';
    $dao->dao->select('dt_expiration_date');
    $dao->dao->where('pk_i_id', $pk_i_id);
    $dao->dao->from(DB_TABLE_PREFIX . $table);
    $result = $dao->dao->get();
    $dates = array();
    $current = strtotime($first);
    $last = strtotime($last);

    while( $current <= $last ) {

        $dates[] = date($output_format, $current);
        $current = strtotime($step, $current);
    }

    return $dates;
}

  }
Title: Re: Is it possible to send mail 14days after publishing instead of instantly.
Post by: MB Themes on October 19, 2021, 08:49:35 PM
@mwindey
Wrong wrong wrong.

First you need into model add function that will retrieve all listings posted 14 days ago.
Code: [Select]
public function items_14days_old() {
  $this->dao->select('pk_i_id');
  $this->dao->from(DB_TABLE_PREFIX.'t_item i');
  $this->dao->where('date(dt_pub_date) = \'' . date('Y-m-d', strtotime('-14 days')) .'\'');

  $result = $this->dao->get();
 
  if($result == false) {
    return array();
  }

  return $result->result();
}

Then you want to loop over these items and send email, ideally added somewhere to index.php:
Code: [Select]
function osc_send_emails_14days_items() {
  $data = ModelBO::newInstance()->items_14days_old();

  if(is_array($data) && count($data) > 0) {
    foreach($data as $d) {
      $item = Item::newInstance()->findByPrimaryKey($d['pk_i_id']);
      email_status($d['pk_i_id']);
      osc_run_hook('hook_email_bo_mgr_email_status', $item);
    }
  }
}

This is just pattern, if you will not be able to complete it using this, do not waste your time :)