public static function ordersPage() { if ($_SERVER['REQUEST_METHOD'] == 'GET' && Cart66Common::getVal('task') == 'view') { $order = new Cart66Order($_GET['id']); $view = Cart66Common::getView('admin/order-view.php', array('order' => $order)); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('task') == 'resend email receipt') { if (CART66_PRO && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($_POST['order_id']); $notify->sendAdvancedEmailReceipts(false); } else { $notify = new Cart66Notifications($_POST['order_id']); $notify->sendEmailReceipts(); } $order = new Cart66Order($_POST['order_id']); $view = Cart66Common::getView('admin/order-view.php', array('order' => $order, 'resend' => true)); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('task') == 'reset download amount') { $product = new Cart66Product(); $product->resetDownloadsForDuid($_POST['duid'], $_POST['order_item_id']); $order = new Cart66Order($_POST['order_id']); $view = Cart66Common::getView('admin/order-view.php', array('order' => $order)); } elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && Cart66Common::getVal('task') == 'delete') { $order = new Cart66Order($_GET['id']); $order->deleteMe(); $view = Cart66Common::getView('admin/orders.php'); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('remove') && Cart66Common::postVal('remove') != 'all') { $order = new Cart66Order($_GET['id']); Cart66AdvancedNotifications::removeTrackingNumber($order); $order = new Cart66Order($_GET['id']); $view = Cart66Common::getView('admin/order-view.php', array('order' => $order)); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('remove') == 'all') { $order = new Cart66Order($_GET['id']); $order->updateTracking(null); $order = new Cart66Order($_GET['id']); $view = Cart66Common::getView('admin/order-view.php', array('order' => $order)); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('task') == 'update order status') { $order = new Cart66Order($_POST['order_id']); //$order->updateStatus(Cart66Common::postVal('status')); //$order->updateNotes($_POST['notes']); $data = array('status' => Cart66Common::postVal('status'), 'notes' => Cart66Common::postVal('notes')); $order->setData($data); $order->save(); if (Cart66Common::postVal('send_email_status_update') && CART66_PRO) { Cart66AdvancedNotifications::addTrackingNumbers($order); $status = Cart66Common::postVal('status'); if (Cart66Setting::getValue('status_options') != null) { $notify = new Cart66AdvancedNotifications($_POST['order_id']); $notify->sendStatusUpdateEmail($status); } } elseif (CART66_PRO) { Cart66AdvancedNotifications::addTrackingNumbers($order); } $view = Cart66Common::getView('admin/orders.php'); //$order = new Cart66Order($_POST['order_id']); //$view = Cart66Common::getView('admin/order-view.php', array('order'=>$order)); } else { $view = Cart66Common::getView('admin/orders.php'); } echo $view; }
public static function ajaxOrderLookUp() { $redirect = true; $order = new Cart66Order(); $order->loadByOuid($_POST['ouid']); if (!Cart66Session::get('Cart66PendingOUID')) { Cart66Session::set('Cart66PendingOUID', $_POST['ouid']); } if (empty($order->id) || $order->status == 'checkout_pending') { $redirect = false; } echo json_encode($redirect); die; }
public function checkFulfillmentSettings($orderId) { $order = new Cart66Order($orderId); $data = array(); foreach ($order->getItems() as $item) { $data[] = $item->product_id; } $orderFulfillment = new Cart66OrderFulfillment(); $orderF = $orderFulfillment->getModels(); $notify = new Cart66AdvancedNotifications($orderId); foreach ($orderF as $of) { $products = array_filter(explode(',', $of->products)); if (array_intersect($data, $products) || empty($products)) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] THEY INTERSECT!"); $notify->sendOrderFulfillmentEmails($of->id); } } }
public function section_debug_settings() { $tab = 'debug-error_logging'; if (isset($_GET['cart66_curl_test']) && $_GET['cart66_curl_test'] == 'run' || isset($_POST['cart66-action']) && $_POST['cart66-action'] == 'clear log file') { $tab = 'debug-debug_data'; } elseif (isset($_POST['cart66-action']) && $_POST['cart66-action'] == 'check subscription reminders') { Cart66MembershipReminders::dailySubscriptionEmailReminderCheck(); $tab = 'debug-debug_data'; } elseif (isset($_POST['cart66-action']) && $_POST['cart66-action'] == 'check followup emails') { Cart66AdvancedNotifications::dailyFollowupEmailCheck(); $tab = 'debug-debug_data'; } elseif (isset($_POST['cart66-action']) && $_POST['cart66-action'] == 'prune pending orders') { $order = new Cart66Order(); $order->dailyPrunePendingPayPalOrders(); $tab = 'debug-debug_data'; } elseif (isset($_GET['sessions']) && $_GET['sessions'] == 'repair') { $tab = 'debug-session_settings'; } $data = array('tab' => $tab); echo Cart66Common::getView('admin/settings/debug.php', $data, false); }
$wpdb->insert($downloadsTable, $data, array('%s', '%s', '%s', '%s')); $setting = new Cart66Setting(); if (!empty($product->s3Bucket) && !empty($product->s3File)) { require_once CART66_PATH . '/models/Cart66AmazonS3.php'; $link = Cart66AmazonS3::prepareS3Url($product->s3Bucket, $product->s3File, '1 minute'); wp_redirect($link); exit; } else { $dir = Cart66Setting::getValue('product_folder'); $path = $dir . DIRECTORY_SEPARATOR . $product->download_path; Cart66Common::downloadFile($path); } exit; } else { echo '<p>' . __("You have exceeded the maximum number of downloads for this product", "cart66") . '.</p>'; $order = new Cart66Order(); $order->loadByDuid($_GET['duid']); if (empty($order->id)) { echo "<h2>This order is no longer in the system</h2>"; exit; } } } } if (!$ajaxRefresh) { if (Cart66Setting::getValue('enable_google_analytics') == 1 && !Cart66Setting::getValue('use_other_analytics_plugin')) { ?> <script type="text/javascript"> /* <![CDATA[ */ var _gaq = _gaq || []; _gaq.push(['_setAccount', '<?php
public static function ordersTable() { $columns = array('id', 'trans_id', 'bill_first_name', 'bill_last_name', 'total', 'ordered_on', 'shipping_method', 'status', 'email', 'notes', 'authorization', "concat_ws(' ', bill_first_name,bill_last_name)"); $indexColumn = "id"; $tableName = Cart66Common::getTableName('orders'); $where = self::dataTablesWhere($columns, 'status', 'checkout_pending', '!='); if ($where == "") { $where = "WHERE `status` != 'checkout_pending'"; } else { $where .= " AND `status` != 'checkout_pending'"; } $limit = self::dataTablesLimit() == '' ? null : self::dataTablesLimit(); $orderBy = self::dataTablesOrder($columns); $iTotal = self::totalRows($indexColumn, $tableName); $iFilteredTotal = self::filteredRows($indexColumn, $tableName, $where); $data = array(); $order = new Cart66Order(); $orders = $order->getOrderRows($where, $orderBy, $limit); foreach ($orders as $o) { $data[] = array($o->id, $o->trans_id, $o->bill_first_name, $o->bill_last_name, Cart66Common::currency($o->total), date(get_option('date_format'), strtotime($o->ordered_on)), $o->shipping_method, $o->status, $o->notes); } $array = array('sEcho' => $_GET['sEcho'], 'iTotalRecords' => $iTotal[0], 'iTotalDisplayRecords' => $iFilteredTotal[0], 'aaData' => $data); echo json_encode($array); die; }
public static function dailyFollowupEmailCheck() { if (Cart66Setting::getValue('enable_followup_emails') == '1') { Cart66Setting::setValue('daily_followup_last_checked', Cart66Common::localTs()); // Function that fires daily to send out followup emails. This will be triggered once a day at 3 AM. // If this function fires emails will be sent. $dayStart = date('Y-m-d 00:00:00', Cart66Common::localTs()); $dayEnd = date('Y-m-d 00:00:00', strtotime('+ 1 day', Cart66Common::localTs())); $total = Cart66Setting::getValue('followup_email_number') . ' ' . Cart66Setting::getValue('followup_email_time'); $start = date('Y-m-d H:i:s', strtotime('- ' . $total, strtotime($dayStart))); $end = date('Y-m-d H:i:s', strtotime('- ' . $total, strtotime($dayEnd))); $order = new Cart66Order(); $orders = $order->getModels("where ordered_on >= '{$start}' AND ordered_on < '{$end}'"); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Start: {$start} :: End: {$end}"); foreach ($orders as $o) { Cart66AdvancedNotifications::sendFollowupEmail($o->id); } } }
public function saveTcoOrder() { global $wpdb; // NEW Parse custom value $referrer = false; $ouid = $_POST['custom']; if (strpos($ouid, '|') !== false) { list($ouid, $referrer) = explode('|', $ouid); } $order = new Cart66Order(); $order->loadByOuid($ouid); if ($order->id > 0 && $order->status == 'checkout_pending' && $_POST['total'] == $order->total) { $statusOptions = Cart66Common::getOrderStatusOptions(); $status = $statusOptions[0]; $data = array('bill_first_name' => $_POST['first_name'], 'bill_last_name' => $_POST['last_name'], 'bill_address' => $_POST['street_address'], 'bill_address2' => $_POST['street_address2'], 'bill_city' => $_POST['city'], 'bill_state' => $_POST['state'], 'bill_zip' => $_POST['zip'], 'bill_country' => $_POST['country'], 'email' => $_POST['email'], 'trans_id' => $_POST['order_number'], 'ordered_on' => date('Y-m-d H:i:s', Cart66Common::localTs()), 'status' => $status); // Verify the first items in the IPN are for products managed by Cart66. It could be an IPN from some other type of transaction. $productsTable = Cart66Common::getTableName('products'); $orderItemsTable = Cart66Common::getTableName('order_items'); $sql = "SELECT id from {$productsTable} where item_number = '" . $_POST['li_0_product_id'] . "'"; $productId = $wpdb->get_var($sql); if (!$productId) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] about to throw an exception, this is not an IPN that should be managed by cart66 because the item number does not match up"); throw new Exception("This is not an IPN that should be managed by Cart66"); } $order->setData($data); $order->save(); $orderId = $order->id; // Handle email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($orderId); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) { $notify = new Cart66Notifications($orderId); $notify->sendEmailReceipts(); } // Process affiliate reward if necessary if ($referrer && CART66_PRO) { Cart66Common::awardCommission($order->id, $referrer); // End processing affiliate information if (isset($_COOKIE['ap_id']) && $_COOKIE['ap_id']) { setcookie('ap_id', $referrer, time() - 3600, "/"); unset($_COOKIE['ap_id']); } Cart66Session::drop('app_id'); } if (CART66_PRO) { // Begin iDevAffiliate Tracking if (CART66_PRO && ($url = Cart66Setting::getValue('idevaff_url'))) { require_once CART66_PATH . "/pro/idevaffiliate-award.php"; } // End iDevAffiliate Tracking } wp_redirect(remove_query_arg('listener', Cart66Common::getCurrentPageUrl())); exit; } }
public function getOrderId() { $order = new Cart66Order(); $orderId = $order->getOrderIdByAccountId($this->id); return $orderId; }
/** * Save a PayPal IPN order from a Website Payments Pro cart sale. * * @param array $pp Urldecoded array of IPN key value pairs */ public function saveOrder($pp) { global $wpdb; // NEW Parse custom value $referrer = false; $ouid = $pp['custom']; if (strpos($ouid, '|') !== false) { list($ouid, $referrer, $gfData) = explode('|', $ouid); } $order = new Cart66Order(); $order->loadByOuid($ouid); if ($order->id > 0 && $order->status == 'checkout_pending') { $hasDigital = false; // Calculate subtotal $subtotal = 0; $numCartItems = $pp['num_cart_items'] > 0 ? $pp['num_cart_items'] : 1; for ($i = 1; $i <= $numCartItems; $i++) { // PayPal in not consistent in the way it passes back the item amounts $amt = 0; if (isset($pp['mc_gross' . $i])) { $amt = $pp['mc_gross' . $i]; } elseif (isset($pp['mc_gross_' . $i])) { $amt = $pp['mc_gross_' . $i]; } $subtotal += $amt; } $statusOptions = Cart66Common::getOrderStatusOptions(); $status = $statusOptions[0]; // Parse Gravity Forms ids $gfIds = array(); if (!empty($gfData)) { $forms = explode(',', $gfData); foreach ($forms as $f) { list($itemId, $formEntryId) = explode(':', $f); $gfIds[$itemId] = $formEntryId; } } // Look for discount amount $discount = 0; if (isset($pp['discount'])) { $discount = $pp['discount']; } $data = array('bill_first_name' => $pp['first_name'], 'bill_last_name' => $pp['last_name'], 'bill_address' => $pp['address_street'], 'bill_city' => $pp['address_city'], 'bill_state' => $pp['address_state'], 'bill_zip' => $pp['address_zip'], 'bill_country' => $pp['address_country'], 'ship_first_name' => $pp['address_name'], 'ship_address' => $pp['address_street'], 'ship_city' => $pp['address_city'], 'ship_state' => $pp['address_state'], 'ship_zip' => $pp['address_zip'], 'ship_country' => $pp['address_country'], 'email' => $pp['payer_email'], 'phone' => $pp['contact_phone'], 'shipping' => $pp['mc_handling'], 'tax' => $pp['tax'], 'subtotal' => $subtotal, 'total' => $pp['mc_gross'], 'discount_amount' => $discount, 'trans_id' => $pp['txn_id'], 'ordered_on' => date('Y-m-d H:i:s', Cart66Common::localTs()), 'status' => $status); foreach ($data as $key => $value) { $data[$key] = is_null($value) ? '' : $value; } // Verify the first items in the IPN are for products managed by Cart66. It could be an IPN from some other type of transaction. $productsTable = Cart66Common::getTableName('products'); $orderItemsTable = Cart66Common::getTableName('order_items'); $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number1'] . "'"; $productId = $wpdb->get_var($sql); if (!$productId) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] about to throw an exception, this is not an IPN that should be managed by cart66 because the item number does not match up"); throw new Exception("This is not an IPN that should be managed by Cart66"); } // Look for the 100% coupons shipping item and move it back to a shipping costs rather than a product if ($data['shipping'] == 0) { for ($i = 1; $i <= $numCartItems; $i++) { $itemNumber = strtoupper($pp['item_number' . $i]); if ($itemNumber == 'SHIPPING') { $data['shipping'] = isset($pp['mc_gross_' . $i]) ? $pp['mc_gross_' . $i] : $pp['mc_gross' . $i]; } } } $order->setData($data); $order->save(); $orderId = $order->id; // Handle email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($orderId); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) { $notify = new Cart66Notifications($orderId); $notify->sendEmailReceipts(); } // Process affiliate reward if necessary if ($referrer && CART66_PRO) { Cart66Common::awardCommission($order->id, $referrer); // End processing affiliate information if (isset($_COOKIE['ap_id']) && $_COOKIE['ap_id']) { setcookie('ap_id', $referrer, time() - 3600, "/"); unset($_COOKIE['ap_id']); } Cart66Session::drop('app_id'); } if (CART66_PRO) { // Begin iDevAffiliate Tracking if (CART66_PRO && ($url = Cart66Setting::getValue('idevaff_url'))) { require_once CART66_PATH . "/pro/idevaffiliate-award.php"; } // End iDevAffiliate Tracking } } else { $orderTable = Cart66Common::getTableName('orders'); // Make sure the transaction id is not already in the database $sql = "SELECT count(*) as c from {$orderTable} where trans_id=%s"; $sql = $wpdb->prepare($sql, $pp['txn_id']); $count = $wpdb->get_var($sql); if ($count < 1) { $hasDigital = false; // Calculate subtotal $subtotal = 0; $numCartItems = $pp['num_cart_items'] > 0 ? $pp['num_cart_items'] : 1; for ($i = 1; $i <= $numCartItems; $i++) { // PayPal in not consistent in the way it passes back the item amounts $amt = 0; if (isset($pp['mc_gross' . $i])) { $amt = $pp['mc_gross' . $i]; } elseif (isset($pp['mc_gross_' . $i])) { $amt = $pp['mc_gross_' . $i]; } $subtotal += $amt; } $statusOptions = Cart66Common::getOrderStatusOptions(); $status = $statusOptions[0]; $ouid = md5($pp['txn_id'] . $pp['address_street']); // Parse custom value $referrer = false; $deliveryMethod = $pp['custom']; if (strpos($deliveryMethod, '|') !== false) { list($deliveryMethod, $referrer, $gfData, $coupon) = explode('|', $deliveryMethod); } // Parse Gravity Forms ids $gfIds = array(); if (!empty($gfData)) { $forms = explode(',', $gfData); foreach ($forms as $f) { list($itemId, $formEntryId) = explode(':', $f); $gfIds[$itemId] = $formEntryId; } } // Look for discount amount $discount = 0; if (isset($pp['discount'])) { $discount = $pp['discount']; } // Look for coupon code $coupon_code = "none"; if (isset($coupon) && $coupon != "") { $coupon_code = $coupon; } $data = array('bill_first_name' => $pp['first_name'], 'bill_last_name' => $pp['last_name'], 'bill_address' => $pp['address_street'], 'bill_city' => $pp['address_city'], 'bill_state' => $pp['address_state'], 'bill_zip' => $pp['address_zip'], 'bill_country' => $pp['address_country'], 'ship_first_name' => $pp['address_name'], 'ship_address' => $pp['address_street'], 'ship_city' => $pp['address_city'], 'ship_state' => $pp['address_state'], 'ship_zip' => $pp['address_zip'], 'ship_country' => $pp['address_country'], 'shipping_method' => $deliveryMethod, 'email' => $pp['payer_email'], 'phone' => $pp['contact_phone'], 'shipping' => $pp['mc_handling'], 'tax' => $pp['tax'], 'subtotal' => $subtotal, 'total' => $pp['mc_gross'], 'coupon' => $coupon_code, 'discount_amount' => $discount, 'trans_id' => $pp['txn_id'], 'ordered_on' => date('Y-m-d H:i:s', Cart66Common::localTs()), 'status' => $status, 'ouid' => $ouid); $data = Cart66Common::deNullArrayValues($data); // Verify the first items in the IPN are for products managed by Cart66. It could be an IPN from some other type of transaction. $productsTable = Cart66Common::getTableName('products'); $orderItemsTable = Cart66Common::getTableName('order_items'); $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number1'] . "'"; $productId = $wpdb->get_var($sql); if (!$productId) { throw new Exception("This is not an IPN that should be managed by Cart66"); } // Look for the 100% coupons shipping item and move it back to a shipping costs rather than a product if ($data['shipping'] == 0) { for ($i = 1; $i <= $numCartItems; $i++) { $itemNumber = strtoupper($pp['item_number' . $i]); if ($itemNumber == 'SHIPPING') { $data['shipping'] = isset($pp['mc_gross_' . $i]) ? $pp['mc_gross_' . $i] : $pp['mc_gross' . $i]; } } } $wpdb->insert($orderTable, $data); $orderId = $wpdb->insert_id; $product = new Cart66Product(); for ($i = 1; $i <= $numCartItems; $i++) { $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number' . $i] . "'"; $productId = $wpdb->get_var($sql); if ($productId > 0) { $product->load($productId); // Decrement inventory $info = $pp['item_name' . $i]; if (strpos($info, '(') > 0) { $info = strrchr($info, '('); $start = strpos($info, '('); $end = strpos($info, ')'); $length = $end - $start; $variation = substr($info, $start + 1, $length - 1); Cart66Common::log("PayPal Variation Information: {$variation}\n{$info}"); } $qty = $pp['quantity' . $i]; Cart66Product::decrementInventory($productId, $variation, $qty); if ($hasDigital == false) { $hasDigital = $product->isDigital(); } // PayPal is not consistent in the way it passes back the item amounts $amt = 0; if (isset($pp['mc_gross' . $i])) { $amt = $pp['mc_gross' . $i]; } elseif (isset($pp['mc_gross_' . $i])) { $amt = $pp['mc_gross_' . $i] / $pp['quantity' . $i]; } // Look for Gravity Form Entry ID $formEntryId = ''; if (is_array($gfIds) && !empty($gfIds) && isset($gfIds[$i])) { $formEntryId = $gfIds[$i]; if (class_exists('RGFormsModel')) { if ($lead = RGFormsModel::get_lead($formEntryId)) { $lead['status'] = 'active'; RGFormsModel::update_lead($lead); } } } $duid = md5($pp['txn_id'] . '-' . $orderId . '-' . $productId); $data = array('order_id' => $orderId, 'product_id' => $productId, 'item_number' => $pp['item_number' . $i], 'product_price' => $amt, 'description' => $pp['item_name' . $i], 'quantity' => $pp['quantity' . $i], 'duid' => $duid, 'form_entry_ids' => $formEntryId); $wpdb->insert($orderItemsTable, $data); } } // Handle email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($orderId); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) { $notify = new Cart66Notifications($orderId); $notify->sendEmailReceipts(); } $promotion = new Cart66Promotion(); $promotion->loadByCode($coupon_code); if ($promotion) { $promotion->updateRedemptions(); } // Process affiliate reward if necessary if ($referrer) { Cart66Common::awardCommission($orderId, $referrer); } } // end transaction id check } }
<?php global $wpdb; $order = new Cart66Order(); $status = ''; if (isset($_GET['status'])) { $status = $_GET['status']; } ?> <h2><?php _e('Cart66 Orders', 'cart66'); ?> </h2> <div class='wrap' style='margin-bottom:60px;'> <?php $setting = new Cart66Setting(); $stats = trim(Cart66Setting::getValue('status_options')); if (strlen($stats) >= 1) { $stats = explode(',', $stats); ?> <p style="float: left; clear: both; margin-top:0; padding-top: 0;"><?php _e('Filter Orders by Status', 'cart66'); ?> : <?php foreach ($stats as $s) { $s = trim(strtolower($s)); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Order status query: WHERE status='{$s}'"); $tmpRows = $order->getOrderRows("WHERE status='{$s}'", null, null, 'id');
public function saveMijirehOrder($order_number) { global $wpdb; // Make sure the order is not already in the database $orders_table = Cart66Common::getTableName('orders'); $sql = "select id from {$orders_table} where trans_id = %s"; $sql = $wpdb->prepare($sql, $order_number); $order_id = $wpdb->get_var($sql); if (!$order_id) { // Save the order $order = new Cart66Order(); $cloud_order = $this->pullOrder($order_number); $order_data = $this->buildOrderDataArray($cloud_order); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Order data: " . print_r($order_data, true)); $order_data = Cart66Common::deNullArrayValues($order_data); $order_id = $order->rawSave($order_data); // Save the order items $order_items_table = Cart66Common::getTableName('order_items'); foreach ($cloud_order['items'] as $key => $item) { $product = new Cart66Product(); $product->loadByItemNumber($item['sku']); $data = array('order_id' => $order_id, 'product_id' => $product->id, 'product_price' => $item['price'], 'item_number' => $item['sku'], 'description' => $item['name'], 'quantity' => $item['quantity'], 'duid' => md5($order_id . $item['sku'])); // Look for gravity forms data if (isset($cloud_order['meta_data'][$key]['gforms_' . $item['sku']])) { $data['form_entry_ids'] = $cloud_order['meta_data'][$key]['gforms_' . $item['sku']]; } $fIds = array(); if (isset($data['form_entry_ids'])) { $fIds = explode(',', $data['form_entry_ids']); if (is_array($fIds) && count($fIds)) { foreach ($fIds as $entryId) { if (class_exists('RGFormsModel')) { if ($lead = RGFormsModel::get_lead($entryId)) { $lead['status'] = 'active'; RGFormsModel::update_lead($lead); } } } } } $data = Cart66Common::deNullArrayValues($data); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Trying to save this order item:" . print_r($data, true)); $wpdb->insert($order_items_table, $data); $order_item_id = $wpdb->insert_id; // Decrement inventory after sale if (Cart66Setting::getValue('track_inventory') == 1) { $option_info = ''; if (isset($cloud_order['meta_data']['options_' . $item['sku']])) { $option_info = $cloud_order['meta_data']['options_' . $item['sku']]; } Cart66Product::decrementInventory($data['product_id'], $option_info, $data['quantity']); } // Look for membership product upgrades/extensions if (isset($cloud_order['meta_data']['account_id']) && is_numeric($cloud_order['meta_data']['account_id'])) { $order->load($order_id); $account_id = $cloud_order['meta_data']['account_id']; if ($mp = $order->getMembershipProduct()) { $account = new Cart66Account(); $account->load($account_id); $account->attachMembershipProduct($mp, $account->firstName, $account->lastName); $order->account_id = $account->id; $order->save(); } } } //update the number of redemptions for the promotion code. if (Cart66Session::get('Cart66Promotion')) { Cart66Session::get('Cart66Promotion')->updateRedemptions(); } // Send email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($order_id); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) { $notify = new Cart66Notifications($order_id); $notify->sendEmailReceipts(); } //Cart66Common::sendEmailReceipts($order_id); } // Redirect to receipt page $this->goToReceipt($order_id); }
public function storeOrder($orderInfo) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] orderinfo: " . print_r($orderInfo, true)); $order = new Cart66Order(); $pre_string = isset($orderInfo['status']) && $orderInfo['status'] == 'checkout_pending' ? 'CP-' : 'MT-'; $orderInfo['trans_id'] = empty($orderInfo['trans_id']) ? $pre_string . Cart66Common::getRandString() : $orderInfo['trans_id']; $orderInfo['ip'] = $_SERVER['REMOTE_ADDR']; if (Cart66Session::get('Cart66Promotion')) { $orderInfo['discount_amount'] = Cart66Session::get('Cart66Promotion')->getDiscountAmount(Cart66Session::get('Cart66Cart')); } else { $orderInfo['discount_amount'] = 0; } $order->setInfo($orderInfo); $order->setItems($this->getItems()); $orderId = $order->save(); //update the number of redemptions for the promotion code. if (Cart66Session::get('Cart66Promotion')) { Cart66Session::get('Cart66Promotion')->updateRedemptions(); } $orderInfo['id'] = $orderId; do_action('cart66_after_order_saved', $orderInfo); return $orderId; }
public static function cart66_statistics_widget() { function totalFromRange($start, $end) { global $wpdb; $tableName = Cart66Common::getTableName('orders'); $sql = "SELECT sum(total) as total from {$tableName} where ordered_on > '{$start}' AND ordered_on < '{$end}'"; $result = $wpdb->get_row($sql, ARRAY_A); $output = $result ? (double) $result['total'] : "N/A"; return $output; } // TODAY $yday = date('Y-m-d 00:00:00', strtotime('yesterday')); $dayStart = date('Y-m-d 00:00:00', strtotime('today')); $dayEnd = date('Y-m-d 00:00:00', strtotime('tomorrow')); $mdayStart = date('Y-m-01 00:00:00', strtotime('today')); $mdayEnd = date('Y-m-01 00:00:00', strtotime('next month')); $today_total = totalFromRange($dayStart, $dayEnd); $yesterday_total = totalFromRange($yday, $dayStart); $month_total = totalFromRange($mdayStart, $mdayEnd); $total_product_sales = Cart66DataTables::productsSearch(); $total_sales_amount = Cart66DataTables::totalSalesForMonth($total_product_sales); $daily_avg = ($month_total - $today_total) / date('j', strtotime('yesterday')); //number_format($month_total/date("j"),2); $total_days = date('t', strtotime('now')); $est_month = $total_days * $daily_avg; ?> <div class="cart66Tabbed"> <ul class="tabs"> <li class="t1"><a class="t1 tab" href="javascript:void(0)"><?php _e('Summary', 'cart66'); ?> </a></li> <li class="t2"><a class="t2 tab" href="javascript:void(0)"><?php _e('Today/Yesterday', 'cart66'); ?> </a></li> <li class="t3"><a class="t3 tab" href="javascript:void(0)"><?php echo date("F, Y", strtotime("now")); ?> </a></li> <li class="t4"><a class="t4 tab" href="javascript:void(0)"><?php _e('Daily Average', 'cart66'); ?> </a></li> <li class="t5"><a class="t5 tab" href="javascript:void(0)"><?php _e('Estimate', 'cart66'); ?> </a></li> </ul> <div class="loading"> <h2 class="center"><?php _e('loading...', 'cart66'); ?> </h2> </div> <div class="t1 pane"> <table id="statSummary" cellspacing="0" cellpadding="0"> <tfoot> <tr> <td> <?php _e('Last Updated', 'cart66'); ?> : </td> <td class="right"> <?php echo date(get_option('date_format'), Cart66Common::localTs()); ?> <?php echo date(get_option('time_format'), Cart66Common::localTs()); ?> </td> </tr> </tfoot> <tbody> <tr class="t4 tab summaryDetails"> <td> <?php echo date('F'); _e(' Daily Average', 'cart66'); ?> : </td> <td class="right"> <a class="t4 tab" href="javascript:void(0)"><?php echo Cart66Common::currency($daily_avg); ?> </a> </td> </tr> <tr class="t2 tab summaryDetails"> <td> <?php _e('Today\'s Total', 'cart66'); ?> : </td> <td class="right"> <a class="t2 tab" href="javascript:void(0)"><?php echo Cart66Common::currency($today_total); ?> </a> </td> </tr> <tr class="t2 tab summaryDetails"> <td> <?php _e('Yesterday\'s Total', 'cart66'); ?> : </td> <td class="right"> <a class="t2 tab" href="javascript:void(0)"><?php echo Cart66Common::currency($yesterday_total); ?> </a> </td> </tr> <tr class="t3 tab summaryDetails"> <td> <?php echo date("F", strtotime("now")); ?> <?php _e('Total', 'cart66'); ?> : </td> <td class="right"> <a class="t3 tab" href="javascript:void(0)"><?php echo Cart66Common::currency($month_total); ?> </a> </td> </tr> <tr class="t5 tab summaryDetails"> <td> <?php _e('Estimated', 'cart66'); ?> <?php echo date("F", strtotime('now')); ?> <?php _e('Total', 'cart66'); ?> : </td> <td class="right"> <a class="t5 tab" href="javascript:void(0)"><?php echo Cart66Common::currency($est_month); ?> </a> </td> </tr> </tbody> </table> </div> <div class="t2 pane"> <table id="dayStats" cellpadding="0" cellspacing="0"> <tr class="summaryDetails dayStats"> <td> <?php _e('Today\'s Total', 'cart66'); ?> : <strong><?php echo Cart66Common::currency($today_total); ?> </strong> </td> <td class="right"> <?php _e('Yesterday\'s Total', 'cart66'); ?> : <strong><?php echo Cart66Common::currency($yesterday_total); ?> </strong> </td> </tr> <tr> <td class="wideOrders" colspan="2"> <table width="100%" id="todaysOrders" cellpadding="0" cellspacing="0"> <thead> <tr> <th colspan="2" class="left"><?php _e('Today\'s Order Details', 'cart66'); ?> </th> <th class="right"><?php _e('Order Total', 'cart66'); ?> </th> </tr> </thead> <?php $Orders = new Cart66Order(); $todaysOrders = $Orders->getOrderRows(" WHERE ordered_on > '{$dayStart}' AND ordered_on < '{$dayEnd}' AND id>0", "order by ordered_on DESC"); if ($todaysOrders) { $i = 1; ?> <tbody> <?php foreach ($todaysOrders as $order) { ?> <tr> <td class="rowNumber"> <h2><?php echo $i; ?> </h2> </td> <td class="orderInformation"> <p><?php echo $order->bill_first_name . " " . $order->bill_last_name; ?> <br> <span class='orderDate'><?php echo Cart66Common::getElapsedTime($order->ordered_on); ?> </span> </p> </td> <td class='right'> <?php echo Cart66Common::currency($order->total); ?> </td> <?php $i++; ?> </tr> <?php } ?> </tbody> <?php } else { ?> <tfoot> <tr> <td colspan='3'> <h2 class="noOrders"><?php _e('No orders yet today', 'cart66'); ?> </h2> </td> </tr> </tfoot> <?php } ?> </table> </td> </tr> </table> </div> <div class="t3 pane"> <table id="productTable" cellpadding="0" cellspacing="0"> <tr> <thead> <tr> <th class="left"><?php _e('Product Name', 'cart66'); ?> </th> <th class="center"><?php _e('Sales', 'cart66'); ?> </th> <th class="right"><?php _e('Income', 'cart66'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="left"><strong><?php echo date("F, Y", strtotime('now')); ?> </strong></th> <?php if (isset($total_sales_amount['total_sales'])) { $totalSales = $total_sales_amount['total_sales']['total_quantity']; $totalAmount = $total_sales_amount['total_sales']['total_amount']; } else { $totalSales = '0'; $totalAmount = '0'; } ?> <th class="center"><strong><?php echo $totalSales; ?> </strong></th> <th class="right"><strong><?php echo Cart66Common::currency($totalAmount); ?> </strong></th> </tr> </tfoot> </tr> </table> </div> <div class="t4 pane"> <div> <table id="dailyAverage" cellpadding="0" cellspacing="0"> <?php $column = 0; for ($i = 6; $i > 0; $i--) { $tmonth_start = date('Y-m-01 00:00:00', strtotime("{$i} months ago")); $tmonth_end = date('Y-m-01 00:00:00', strtotime($i - 1 . " months ago")); $tmonth_total = totalFromRange($tmonth_start, $tmonth_end); $tmonth_days = date('t', strtotime("{$i} months ago")); ?> <?php if ($tmonth_total != "") { ?> <thead> <tr> <th class="left" colspan="2"> <?php echo date('F, Y', strtotime("{$i} months ago")); ?> </th> </tr> </thead> <tbody> <tr> <td><?php _e('Total Income', 'cart66'); ?> :</td> <td class="right"><strong><?php echo Cart66Common::currency($tmonth_total); ?> </strong></td> </tr> <tr> <td><?php _e('Daily Average', 'cart66'); ?> :</td> <td class="right"><strong><?php echo Cart66Common::currency($tmonth_total / $tmonth_days); ?> </strong></td> </tr> </tbody> <?php } } $ystart = date("Y-01-01 00:00:00"); $yend = date("Y-01-01 00:00:00", strtotime("next year")); $year_total = totalFromRange($ystart, $yend); $day_of_year = date('z'); ?> <thead> <tr> <th class="left" colspan="2">YTD - <?php echo date('Y'); ?> </th> </tr> </thead> <tbody> <tr> <td><?php _e('Total Income', 'cart66'); ?> :</td> <td class="right"><strong><?php echo Cart66Common::currency($year_total); ?> </strong></td> </tr> <tr> <td><?php _e('Daily Average', 'cart66'); ?> :</td> <td class="right"><strong><?php echo Cart66Common::currency($year_total / $day_of_year); ?> </strong></td> </tr> </tbody> </table> </div> </div> <div class="t5 pane"> <table id="estimatedSummary" cellspacing="0" cellpadding="0"> <tbody> <tr> <td> <?php _e('Today', 'cart66'); ?> : </td> <td class="right"> <?php echo date(get_option('date_format'), strtotime('now')); ?> </td> </tr> <tr> <td> <?php _e('Total Days in', 'cart66'); ?> <?php echo date("F", strtotime('now')); ?> : </td> <td class="right"> <?php echo $total_days; ?> </td> </tr> <tr> <td> <?php _e('Remaining Days in', 'cart66'); ?> <?php echo date("F", strtotime('now')); ?> : </td> <td class="right"> <?php echo $total_days - date('j', strtotime('now')); ?> </td> </tr> <tr> <td> <?php _e('Estimated Remaining Income', 'cart66'); ?> : </td> <td class="right"> <?php echo Cart66Common::currency(($total_days - date('j', strtotime('now'))) * $daily_avg); ?> </td> </tr> </tbody> </table> </div> </div> <script type="text/javascript"> (function($){ $(document).ready(function(){ /* API method to get paging information */ $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) { return { "iStart": oSettings._iDisplayStart, "iEnd": oSettings.fnDisplayEnd(), "iLength": oSettings._iDisplayLength, "iTotal": oSettings.fnRecordsTotal(), "iFilteredTotal": oSettings.fnRecordsDisplay(), "iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ), "iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength ) }; } /* Bootstrap style pagination control */ $.extend( $.fn.dataTableExt.oPagination, { "bootstrap": { "fnInit": function( oSettings, nPaging, fnDraw ) { var oLang = oSettings.oLanguage.oPaginate; var fnClickHandler = function ( e ) { e.preventDefault(); if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) { fnDraw( oSettings ); } }; $(nPaging).addClass('pagination').append( '<ul>'+ '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+ '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+ '</ul>' ); var els = $('a', nPaging); $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler ); $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler ); }, "fnUpdate": function ( oSettings, fnDraw ) { var iListLength = 5; var oPaging = oSettings.oInstance.fnPagingInfo(); var an = oSettings.aanFeatures.p; var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2); if ( oPaging.iTotalPages < iListLength) { iStart = 1; iEnd = oPaging.iTotalPages; } else if ( oPaging.iPage <= iHalf ) { iStart = 1; iEnd = iListLength; } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) { iStart = oPaging.iTotalPages - iListLength + 1; iEnd = oPaging.iTotalPages; } else { iStart = oPaging.iPage - iHalf + 1; iEnd = iStart + iListLength - 1; } for ( i=0, iLen=an.length ; i<iLen ; i++ ) { // Remove the middle elements $('li:gt(0)', an[i]).filter(':not(:last)').remove(); // Add the new list items and their event handlers for ( j=iStart ; j<=iEnd ; j++ ) { sClass = (j==oPaging.iPage+1) ? 'class="active"' : ''; $('<li '+sClass+'><a href="#">'+j+'</a></li>') .insertBefore( $('li:last', an[i])[0] ) .bind('click', function (e) { e.preventDefault(); oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength; fnDraw( oSettings ); } ); } // Add / remove disabled classes from the static elements if ( oPaging.iPage === 0 ) { $('li:first', an[i]).addClass('disabled'); } else { $('li:first', an[i]).removeClass('disabled'); } if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) { $('li:last', an[i]).addClass('disabled'); } else { $('li:last', an[i]).removeClass('disabled'); } } } } } ); $('#productTable').dataTable({ "bProcessing": true, "bServerSide": true, "bPagination": true, "bLengthChange": false, "iDisplayLength": 6, "sPaginationType": "bootstrap", "sAjaxSource": ajaxurl + "?action=dashboard_products_table", "aoColumns": [ { "sClass": "left" }, { "sClass": "center" }, { "sClass": "right" }, ], "oLanguage": { "sZeroRecords": "<?php _e('No matching Products found', 'cart66'); ?> ", "sSearch": "<?php _e('Search', 'cart66'); ?> :", "sInfo": "<?php _e('Showing', 'cart66'); ?> _START_ <?php _e('to', 'cart66'); ?> _END_ <?php _e('of', 'cart66'); ?> _TOTAL_ <?php _e('entries', 'cart66'); ?> ", "sInfoEmpty": "<?php _e('Showing 0 to 0 of 0 entries', 'cart66'); ?> ", "oPaginate": { "sNext": "<?php _e('Next', 'cart66'); ?> ", "sPrevious": "<?php _e('Previous', 'cart66'); ?> ", "sLast": "<?php _e('Last', 'cart66'); ?> ", "sFirst": "<?php _e('First', 'cart66'); ?> " }, "sInfoFiltered": "(<?php _e('filtered from', 'cart66'); ?> _MAX_ <?php _e('total entries', 'cart66'); ?> )", "sLengthMenu": "<?php _e('Show', 'cart66'); ?> _MENU_ <?php _e('entries', 'cart66'); ?> ", "sLoadingRecords": "<?php _e('Loading', 'cart66'); ?> ...", "sProcessing": "<?php _e('Processing', 'cart66'); ?> ..." } }); }) })(jQuery); </script> <script type="text/javascript"> (function($){ $(document).ready(function() { // setting the tabs in the sidebar hide and show, setting the current tab $('div.pane').hide(); $('div.t1').show(); $('div.loading').hide(); $('div.cart66Tabbed ul.tabs li.t1 a').addClass('tab-current'); // SIDEBAR TABS $('div.cart66Tabbed ul li a, div.t1 a, div.t1 tr.summaryDetails').click(function(){ if($(this).hasClass('tab')) { var thisClass = this.className.slice(0,2); $('div.pane').hide(); $('div.' + thisClass).fadeIn(300); $('div.cart66Tabbed ul.tabs li a').removeClass('tab-current'); $('div.cart66Tabbed ul.tabs li a.' + thisClass).addClass('tab-current'); } }); }); })(jQuery); </script><?php }
public function dailyPrunePendingPayPalOrders() { Cart66Setting::setValue('daily_prune_pending_orders_last_checked', Cart66Common::localTs()); $o = new Cart66Order(); $dayStart = date('Y-m-d 00:00:00', strtotime('48 hours ago', Cart66Common::localTs())); $dayEnd = date('Y-m-d 00:00:00', strtotime('24 hours ago', Cart66Common::localTs())); $orders = $o->getOrderRows("WHERE status in ('paypal_pending','checkout_pending') AND ordered_on >= '{$dayStart}' AND ordered_on < '{$dayEnd}'"); foreach ($orders as $order) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] yes, i am to delete an order or more: " . $order->id); $o->load($order->id); $o->deleteMe(true, true); } }
public function cart66Affiliate($attrs) { $content = ''; if (isset($_GET['ouid']) && isset($attrs['display'])) { $order = new Cart66Order(); $order->loadByOuid($_GET['ouid']); //if($order->viewed == 0) { $content = $order->{$attrs}['display']; //} } return $content; }
public static function awardCommission($orderId, $referrer) { global $wpdb; if (!empty($referrer)) { $order = new Cart66Order($orderId); if ($order->id > 0) { $subtractAmount = 0; $discount = $order->discountAmount; $order_items = array(); foreach ($order->getItems() as $item) { $order_items[] = $item->item_number; $price = $item->product_price * $item->quantity; if ($price > $discount) { $subtractAmount = $discount; $discount = 0; } else { $subtractAmount = $price; $discount = $discount - $price; } if ($subtractAmount > 0) { $price = $price - $subtractAmount; } // Transaction if for commission is the id in th order items table $txn_id = $order->trans_id; $sale_amount = $price; $item_id = $item->item_number; $buyer_email = $order->email; if (function_exists('wp_aff_award_commission')) { // Make sure commission has not already been granted for this transaction $aff_sales_table = $wpdb->prefix . "affiliates_sales_tbl"; $txnCount = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$aff_sales_table} where txn_id = %s", $txn_id)); if ($txnCount < 1) { wp_aff_award_commission($referrer, $sale_amount, $txn_id, $item_id, $buyer_email); } } } // valid order id // Transaction if for commission is the id in th order items table $txn_id = $order->trans_id; $sale_amount = $order->total - ($order->shipping + $order->tax); // set eligible amount to total sans shipping $item_id = implode(',', $order_items); $buyer_email = $order->email; // Affiliate Royale Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "]\n Running wafp_award_commission\n\n referrer {$referrer}\n\n sale_amount {$sale_amount}\n\n txn_id {$txn_id}\n\n item_id {$item_id}\n\n buyer_email {$buyer_email}"); do_action('wafp_award_commission', $referrer, $sale_amount, $txn_id, $item_id, $buyer_email); } } }