public function send($vars = array(), $member_data = FALSE, $entry_data = array()) { $where = array(); $settings = $this->get_settings(); $channel = $this->channel_data->get_channel_by_name($settings->channel_name); if ($channel->num_rows() == 0) { return; } if ($settings->omit_expired == 'true') { $where['OR expiration_date'] = array(0, '>= ' . time()); } if (empty($settings->days_to_send)) { $settings->days_to_send = FALSE; } $limit = FALSE; if (isset($settings->limit) && !empty($settings->limit)) { $limit = $settings->limit; } $channel = $channel->row(); $where['postmaster_store_report_products_sold.date'] = array('IS NULL', 'or <=' . date('Y-m-d 00:00:00', strtotime('-1 day'))); $entries = $this->channel_data->get_channel_entries($channel->channel_id, array('select' => 'postmaster_store_report_products_sold.*', 'where' => $where, 'left join' => array('postmaster_store_report_products_sold' => 'channel_data.entry_id = postmaster_store_report_products_sold.entry_id'), 'limit' => $limit)); foreach ($entries->result() as $entry) { $status = 'new'; if (!empty($settings->status)) { $status = $settings->status; } if ($this->_should_send($entry->entry_id, $settings->days_to_send)) { $vars = $this->_get_entry_stats($entry->entry_id, $status); $member = $this->channel_data->get_member($entry->author_id)->row_array(); $this->_insert_or_update($entry->entry_id, array('entry_id' => $entry->entry_id, 'date' => date('Y-m-d 00:00:00', time()), 'day_of_week' => date('l', time()), 'qty' => $vars['qty'], 'total' => $vars['total'], 'total_orders' => $vars['total_orders'])); $valid = TRUE; if (isset($settings->email_field) && !empty($settings->email_field)) { if (isset($entry->{$settings->email_field})) { $valid = $this->_validate_email(trim($entry->{$settings->email_field})); } else { $valid = FALSE; } } if ($valid) { parent::send($vars, $member, $entry); } } } }
public function send() { $settings = $this->get_settings(); $channel_names = $this->trim_array(explode(',', $settings->channel)); $channels = array(); foreach ($channel_names as $channel_name) { $channel = $this->EE->channel_data->get_channel_by_name($channel_name); if ($channel->num_rows() > 0) { $channels[] = $channel->row('channel_id'); } } $stasuses = array(); $threshold = strtotime($settings->threshold, $this->EE->localize->now); $diff = $this->EE->localize->now - $threshold; $where = array('expiration_date >' => $this->EE->localize->now); if ($diff >= 0) { $where['expiration_date <='] = $this->EE->localize->now + $diff; } else { $where['expiration_date <='] = $this->EE->localize->now - $diff; } if (!empty($settings->status)) { $where['status'] = $this->trim_array(explode(',', $settings->status), 'or '); } if (!empty($settings->channel)) { $where['channel_titles.channel_id'] = $this->trim_array($channels, 'or '); } $entries = $this->EE->channel_data->get_entries(array('select' => 'postmaster_expired_entries_emails.entry_id IS NOT NULL as \'has_sent\'', 'where' => $where, 'having' => array('has_sent !=' => 1), 'left join' => array('postmaster_expired_entries_emails' => 'channel_titles.entry_id = postmaster_expired_entries_emails.entry_id'))); foreach ($entries->result() as $entry) { $this->notification = $this->EE->postmaster_lib->append($this->notification, 'entry', $entry); $parse_vars = array(); $member = $this->EE->channel_data->get_member($entry->author_id); $response = parent::send($parse_vars, $member->row(), $entry); $data = array('entry_id' => $entry->entry_id); if (!$this->_existing_entry($entry->entry_id)) { $this->_insert_entry($entry->entry_id, $data); } else { $this->_update_entry($entry->entry_id, $data); } } }
public function send() { $response = FALSE; $entries = $this->channel_data->get('cartthrob_cart', array('left join' => array('postmaster_cartthrob_emails' => 'cartthrob_cart.id = postmaster_cartthrob_emails.cart_id'))); if ($entries->num_rows() > 0) { $entry = $entries->row(); $intervals = $this->settings->cartthrob_abandoned_cart->email_intervals; if ($entries) { $this->EE->load->library('encrypt'); $cart = $this->_unserialize($entry->cart); $this->EE->load->add_package_path(PATH_THIRD . 'cartthrob'); $this->EE->load->model('cart_model'); $data = $this->EE->cart_model->read_cart($entry->id); include_once PATH_THIRD . 'cartthrob/cartthrob/Cartthrob.php'; $this->EE->cartthrob = Cartthrob_core::instance('ee', array('cart' => $data)); $sent = json_decode($entry->emails_sent); if (!is_array($sent)) { $sent = array(); } foreach ($intervals as $index => $interval) { $time = new Postmaster_time($this->EE->localize->now, $interval); $interval_string = json_encode($interval); $items = $this->EE->cartthrob->cart->items(); if (count($items) > 0 && $time->has_time_past($entry->timestamp) && !in_array($interval_string, $sent)) { $parse_vars = array(); foreach ($items as $index => $item) { $parse_vars['items'][$index] = array('product_id' => $item->product_id(), 'row_id' => $item->row_id(), 'in_stock' => $item->in_stock(), 'item_options' => array($item->item_options()), 'price' => $item->price(), 'tax' => $item->tax(), 'weight' => $item->weight(), 'shipping' => $item->shipping(), 'meta' => array($item->meta())); if (isset($parse_vars['items'][$index]['meta'][0]['subscription_options'])) { $parse_vars['items'][$index]['meta'][0]['subscription_options'] = array($parse_vars['items'][$index]['meta'][0]['subscription_options']); } } $parse_vars['customer_info'] = array($this->EE->cartthrob->cart->customer_info()); $parse_vars = array_merge($parse_vars, array('subtotal' => $this->EE->cartthrob->cart->subtotal(), 'total' => $this->EE->cartthrob->cart->total(), 'shipping' => $this->EE->cartthrob->cart->shipping(), 'tax' => $this->EE->cartthrob->cart->tax(), 'discount' => $this->EE->cartthrob->cart->discount(), 'item_tax' => $this->EE->cartthrob->cart->item_tax(), 'subtotal_with_tax' => $this->EE->cartthrob->cart->subtotal_with_tax(), 'shipping_tax' => $this->EE->cartthrob->cart->shipping_tax(), 'shipping_plus_tax' => $this->EE->cartthrob->cart->shipping_plus_tax(), 'discount_tax' => $this->EE->cartthrob->cart->discount_tax(), 'weight' => $this->EE->cartthrob->cart->weight(), 'product_ids' => implode($this->EE->cartthrob->cart->product_ids(), '|'), 'shippable_subtotal' => $this->EE->cartthrob->cart->shippable_subtotal(), 'shippable_weight' => $this->EE->cartthrob->cart->shippable_weight())); $response = parent::send($parse_vars); $sent[] = $interval_string; $data = array('emails_sent' => json_encode($sent)); if (!$this->_existing_entry($entry->id)) { $this->_insert_entry($entry->id, $data); } else { $this->_update_entry($entry->id, $data); } break; } } } } return $response; }