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; }
<?php if (!defined('CARTTHROB_PATH')) { Cartthrob_core::core_error('No direct script access allowed'); } class Cartthrob_shipping_by_location_quantity_threshold_w_options extends Cartthrob_shipping { public $title = 'Cartthrob_shipping_by_location_quantity_threshold_w_options'; public $classname = __CLASS__; public $note = 'quantity_threshold_overview'; public $settings = array(array('name' => 'set_shipping_cost_by', 'short_name' => 'mode', 'default' => 'rate', 'type' => 'radio', 'options' => array('price' => 'rate_amount', 'rate' => 'rate_amount_times_cart_total')), array('name' => 'primary_location_field', 'short_name' => 'location_field', 'type' => 'select', 'default' => 'country_code', 'options' => array('zip' => 'zip', 'state' => 'state', 'region' => 'Region', 'country_code' => 'settings_country_code', 'shipping_zip' => 'shipping_zip', 'shipping_state' => 'shipping_state', 'shipping_region' => 'shipping_region', 'shipping_country_code' => 'settings_shipping_country_code')), array('name' => 'backup_location_field', 'short_name' => 'backup_location_field', 'type' => 'select', 'default' => 'country_code', 'options' => array('zip' => 'zip', 'state' => 'state', 'region' => 'Region', 'country_code' => 'settings_country_code', 'shipping_zip' => 'shipping_zip', 'shipping_state' => 'shipping_state', 'shipping_region' => 'shipping_region', 'shipping_country_code' => 'settings_shipping_country_code')), array('name' => 'thresholds', 'short_name' => 'thresholds', 'type' => 'matrix', 'settings' => array(array('name' => 'location_threshold', 'short_name' => 'location', 'type' => 'text'), array('name' => 'rate', 'short_name' => 'default_rate', 'note' => 'rate_example', 'type' => 'text'), array('name' => 'Next Day', 'short_name' => 'next_day', 'type' => 'text'), array('name' => 'Next Day 10am', 'short_name' => 'next_day_10', 'type' => 'text'), array('name' => 'Next Day noon', 'short_name' => 'next_day_12', 'type' => 'text'), array('name' => 'Sat', 'short_name' => 'sat', 'type' => 'text'), array('name' => 'Samples', 'short_name' => 'samples_rate', 'type' => 'text'), array('name' => 'weight_threshold', 'short_name' => 'threshold', 'note' => 'weight_threshold_example', 'type' => 'text')))); public $rates = array(); public $rate_titles = array(); public $default_shipping_option = "default_rate"; public $cost = 0; public $default_rates = array('default_rate' => 0, 'next_day' => 0, 'next_day_10' => 0, 'next_day_12' => 0, 'sat' => 0, 'samples_rate' => 1); public function initialize() { // @TODO language $this->rate_titles = array('default_rate' => 'Standard Delivery', 'next_day' => 'Next Day', 'next_day_10' => 'Next Day 10am', 'next_day_12' => 'Next Day 12pm', 'sat' => 'Saturday', 'samples_rate' => 'Samples'); if ($this->core->cart->count() <= 0 || $this->core->cart->shippable_subtotal() <= 0) { return 0; } $this->shipping_option = $this->core->cart->shipping_info('shipping_option') ? $this->core->cart->shipping_info('shipping_option') : $this->default_shipping_option(); switch ($this->shipping_option) { case "Standard Delivery": $rate = "default_rate"; break; case "Next Day": $rate = "next_day"; break;