This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

mwindey

  • *****
  • 475 posts
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  :)

*

MB Themes

Can you add example of that mail?
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
@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}

*

MB Themes

@mwindey
Thanks will check it out.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
Thanks for taking this seriously... Greatly appreciated ... i am not able to do it myself  :) :)

*

MB Themes

@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.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
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 ;-)
« Last Edit: October 17, 2021, 05:58:10 PM by mwindey »

*

MB Themes

@mwindey
It looks quite wrong, messy and is not clear which function does what.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
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;
}

  }
« Last Edit: October 19, 2021, 02:35:05 PM by mwindey »

Marked as best answer by mwindey on October 20, 2021, 02:13:42 PM
*

MB Themes

@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 :)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots