コード例 #1
0
 public function findLatestProductId($ids)
 {
     global $wpdb;
     $output = false;
     if (is_array($ids)) {
         $sql = 'SELECT id from ' . Cart66Common::getTableName('orders') . " WHERE account_id = '" . $this->account_id . "'";
         $orders = $wpdb->get_col($sql);
         if (count($orders) > 0) {
             $orderIds = implode($orders, ',');
             $sql = 'SELECT product_id from ' . Cart66Common::getTableName('order_items') . " WHERE `order_id` IN ({$orderIds}) ORDER BY id desc";
             $products = $wpdb->get_results($sql);
             if (count($products) > 0) {
                 foreach ($products as $product) {
                     $productIds[] = $product->product_id;
                     if (in_array($product->product_id, $ids)) {
                         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] order item id: {$product->product_id} found in list of subscription products matching feature level and subscription name.");
                         $output = $product->product_id;
                         break;
                     }
                 }
             }
         }
     }
     return $output;
 }
コード例 #2
0
 public static function resendEmailFromLog($id)
 {
     $resendEmail = false;
     global $wpdb;
     $tableName = Cart66Common::getTableName('email_log');
     $sql = "SELECT * from {$tableName} where id = {$id}";
     $results = $wpdb->get_results($sql);
     if ($results) {
         foreach ($results as $r) {
             $resendEmail = Cart66Notifications::mail($r->to_email, $r->subject, $r->body, $r->headers);
             $email = new Cart66EmailLog();
             $email_data = array('from_email' => $r->from_email, 'from_name' => $r->from_name, 'to_email' => $r->to_email, 'to_name' => $r->to_name, 'head' => array('headers' => $r->headers), 'subject' => $r->subject, 'msg' => $r->body, 'attachments' => $r->attachments, 'order_id' => $r->order_id);
             if (!$resendEmail) {
                 if (Cart66Setting::getValue('log_resent_emails')) {
                     $email->saveEmailLog($email_data, $r->email_type, $r->copy, 'RESEND FAILED');
                 }
             } else {
                 if (Cart66Setting::getValue('log_resent_emails')) {
                     $email->saveEmailLog($email_data, $r->email_type, $r->copy, 'RESEND SUCCESSFUL');
                 }
             }
         }
     }
     return $resendEmail;
 }
コード例 #3
0
ファイル: Cart66Log.php プロジェクト: rbredow/allyzabbacart
 public static function getCartSettings()
 {
     global $wpdb;
     $out = "\n=====================\nCART SETTINGS\n=====================\n\n";
     $cartTable = Cart66Common::getTableName('cart_settings');
     $sql = "SELECT * from {$cartTable} order by `key`";
     $results = $wpdb->get_results($sql, OBJECT);
     foreach ($results as $row) {
         $out .= $row->key . ' = ' . $row->value . "\n";
     }
     return $out;
 }
コード例 #4
0
 /**
  * Only save shipping methods if the carrier code combo does not exist.
  */
 public function save()
 {
     $save = true;
     $shippingMethods = Cart66Common::getTableName('shipping_methods');
     if (!empty($this->carrier) && !empty($this->code)) {
         $sql = "SELECT id from {$shippingMethods} where carrier=%s and code=%s";
         $sql = $this->_db->prepare($sql, $this->carrier, $this->code);
         $id = $this->_db->get_var($sql);
         $save = $id === NULL;
     }
     if ($save) {
         parent::save();
     }
 }
コード例 #5
0
 public static function exportOrders($startDate, $endDate)
 {
     global $wpdb;
     $start = date('Y-m-d 00:00:00', strtotime($startDate));
     $end = date('Y-m-d 00:00:00', strtotime($endDate . ' + 1 day'));
     $orders = Cart66Common::getTableName('orders');
     $items = Cart66Common::getTableName('order_items');
     $orderHeaders = array('id' => __('Order ID', 'cart66'), 'trans_id' => __('Order Number', 'cart66'), 'ordered_on' => __('Date', 'cart66'), 'bill_first_name' => __('Billing First Name', 'cart66'), 'bill_last_name' => __('Billing Last Name', 'cart66'), 'bill_address' => __('Billing Address', 'cart66'), 'bill_address2' => __('Billing Address 2', 'cart66'), 'bill_city' => __('Billing City', 'cart66'), 'bill_state' => __('Billing State', 'cart66'), 'bill_country' => __('Billing Country', 'cart66'), 'bill_zip' => __('Billing Zip Code', 'cart66'), 'ship_first_name' => __('Shipping First Name', 'cart66'), 'ship_last_name' => __('Shipping Last Name', 'cart66'), 'ship_address' => __('Shipping Address', 'cart66'), 'ship_address2' => __('Shipping Address 2', 'cart66'), 'ship_city' => __('Shipping City', 'cart66'), 'ship_state' => __('Shipping State', 'cart66'), 'ship_country' => __('Shipping Country', 'cart66'), 'ship_zip' => __('Shipping Zip Code', 'cart66'), 'phone' => __('Phone', 'cart66'), 'email' => __('Email', 'cart66'), 'coupon' => __('Coupon', 'cart66'), 'discount_amount' => __('Discount Amount', 'cart66'), 'shipping' => __('Shipping Cost', 'cart66'), 'subtotal' => __('Subtotal', 'cart66'), 'tax' => __('Tax', 'cart66'), 'total' => __('Total', 'cart66'), 'ip' => __('IP Address', 'cart66'), 'shipping_method' => __('Delivery Method', 'cart66'), 'status' => __('Order Status', 'cart66'));
     $orderColHeaders = implode(',', $orderHeaders);
     $orderColSql = implode(',', array_keys($orderHeaders));
     $out = $orderColHeaders . ",Form Data,Item Number,Description,Quantity,Product Price,Form ID\n";
     $sql = "SELECT {$orderColSql} from {$orders} where ordered_on >= %s AND ordered_on < %s AND status != %s order by ordered_on";
     $sql = $wpdb->prepare($sql, $start, $end, 'checkout_pending');
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] SQL: {$sql}");
     $selectedOrders = $wpdb->get_results($sql, ARRAY_A);
     foreach ($selectedOrders as $o) {
         $itemRowPrefix = '"' . $o['id'] . '","' . $o['trans_id'] . '",' . str_repeat(',', count($o) - 3);
         $orderId = $o['id'];
         $sql = "SELECT form_entry_ids, item_number, description, quantity, product_price FROM {$items} where order_id = {$orderId}";
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Item query: {$sql}");
         $selectedItems = $wpdb->get_results($sql, ARRAY_A);
         $out .= '"' . implode('","', $o) . '"';
         $printItemRowPrefix = false;
         if (!empty($selectedItems)) {
             foreach ($selectedItems as $i) {
                 if ($printItemRowPrefix) {
                     $out .= $itemRowPrefix;
                 }
                 if ($i['form_entry_ids'] && CART66_PRO) {
                     $i['form_id'] = $i['form_entry_ids'];
                     $GReader = new Cart66GravityReader();
                     $i['form_entry_ids'] = $GReader->displayGravityForm($i['form_entry_ids'], true);
                     $i['form_entry_ids'] = str_replace("\"", "''", $i['form_entry_ids']);
                 }
                 $i['description'] = str_replace(",", " -", $i['description']);
                 $out .= ',"' . implode('","', $i) . '"';
                 $out .= "\n";
                 $printItemRowPrefix = true;
             }
         } else {
             $out .= "\n";
         }
     }
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Report\n{$out}");
     return $out;
 }
コード例 #6
0
 /**
  * Hide pages that the logged in user may not access
  */
 public static function hideSubscriptionPages($featureLevel, $activeAccount = false)
 {
     global $wpdb;
     $hiddenPages = array();
     $posts = Cart66Common::getTableName('posts', '');
     $meta = Cart66Common::getTableName('postmeta', '');
     $sql = "SELECT post_id, meta_value from {$meta} where meta_key='_cart66_subscription'";
     $results = $wpdb->get_results($sql);
     if (count($results)) {
         foreach ($results as $m) {
             $requiredFeatureLevels = explode(',', $m->meta_value);
             if (!in_array($featureLevel, $requiredFeatureLevels) || !$activeAccount) {
                 $hiddenPages[] = $m->post_id;
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Excluding page: " . $m->post_id);
             }
         }
     }
     return $hiddenPages;
 }
コード例 #7
0
 protected static function _deleteMe()
 {
     global $wpdb;
     $tableName = Cart66Common::getTableName('sessions');
     $sql = "DELETE from {$tableName} where id = %d";
     $sql = $wpdb->prepare($sql, self::$_data['id']);
     $wpdb->query($sql);
 }
コード例 #8
0
 public function loadByEmail($email)
 {
     $itemsTable = Cart66Common::getTableName('accounts');
     $sql = "SELECT id from {$itemsTable} where email = '{$email}'";
     $id = $this->_db->get_var($sql);
     $this->load($id);
     return $this->id;
 }
コード例 #9
0
 public static function showReportData()
 {
     global $wpdb;
     $orders = Cart66Common::getTableName('orders');
     $reportData = array();
     $sql = "SELECT sum(`total`) from {$orders}";
     $lifetimeTotal = $wpdb->get_var($sql);
     $reportData[] = array("Total Sales", "total_sales", $lifetimeTotal);
     $sql = "SELECT count('id') from {$orders}";
     $totalOrders = $wpdb->get_var($sql);
     $reportData[] = array("Total Orders", "total_orders", $totalOrders);
     $sql = "SELECT ordered_on from {$orders} order by id asc LIMIT 1";
     $firstSaleDate = $wpdb->get_var($sql);
     $reportData[] = array("First Sale", "first_sale", $firstSaleDate);
     $sql = "SELECT ordered_on from {$orders} order by id desc LIMIT 1";
     $lastSaleDate = $wpdb->get_var($sql);
     $reportData[] = array("Last Sale", "last_sale", $lastSaleDate);
     $postTypes = get_post_types('', 'names');
     foreach ($postTypes as $postType) {
         if (!in_array($postType, array("post", "page", "attachment", "nav_menu_item", "revision"))) {
             $customPostTypes[] = $postType;
         }
     }
     $customPostTypes = empty($customPostTypes) ? "none" : implode(',', $customPostTypes);
     $reportData[] = array("Custom Post Types", "custom_post_types", $customPostTypes);
     $output = "First Sale: " . $firstSaleDate . "<br>";
     $output .= "Last Sale: " . $lastSaleDate . "<br>";
     $output .= "Total Orders: " . $totalOrders . "<br>";
     $output .= "Total Sales: " . $lifetimeTotal . "<br>";
     $output .= "Custom Post Types: " . $customPostTypes . "<br>";
     $output .= "WordPress Version: " . get_bloginfo("version") . "<br>";
     $output .= CART66_PRO ? "Cart66 Version: Pro " . Cart66Setting::getValue('version') . "<br>" : "Cart66 Version: " . Cart66Setting::getValue('version') . "<br>";
     $output .= "PHP Version: " . phpversion() . "<br>";
     //$output .= ": " . "" . "<br>";
     return $output;
 }
コード例 #10
0
ファイル: Cart66Order.php プロジェクト: rbredow/allyzabbacart
 public function deleteMe($resetInventory = false, $resetRedemptions = false)
 {
     if ($this->id > 0) {
         // Delete attached Gravity Forms if they exist
         $items = $this->getItems();
         foreach ($items as $item) {
             if (!empty($item->form_entry_ids)) {
                 $entryIds = explode(',', $item->form_entry_ids);
                 if (is_array($entryIds)) {
                     foreach ($entryIds as $entryId) {
                         RGFormsModel::delete_lead($entryId);
                     }
                 }
             }
         }
         if ($resetInventory && Cart66Setting::getValue('track_inventory')) {
             $this->resetInventoryForItems();
         }
         if ($resetRedemptions && $this->coupon != 'none') {
             $this->resetRedemptionsForCoupon();
         }
         // Delete order items
         $orderItems = Cart66Common::getTableName('order_items');
         $sql = "DELETE from {$orderItems} where order_id = {$this->id}";
         $this->_db->query($sql);
         // Delete the order
         $sql = "DELETE from {$this->_tableName} where id = {$this->id}";
         $this->_db->query($sql);
     }
 }
コード例 #11
0
 public function __construct($id = null)
 {
     $this->_tableName = Cart66Common::getTableName('order_fulfillment');
     parent::__construct($id);
 }
コード例 #12
0
ファイル: reports.php プロジェクト: rbredow/allyzabbacart
<?php 
if (CART66_PRO) {
    ?>
<h3 style="margin-top: 40px;"><?php 
    _e('Daily Income Totals', 'cart66');
    ?>
</h3>

<?php 
    global $wpdb;
    $data = array();
    for ($i = 0; $i < 42; $i++) {
        $dayStart = date('Y-m-d 00:00:00', strtotime('today -' . $i . ' days', Cart66Common::localTs()));
        $dayEnd = date('Y-m-d 00:00:00', strtotime("{$dayStart} +1 day", Cart66Common::localTs()));
        $orders = Cart66Common::getTableName('orders');
        $sql = "SELECT sum(`total`) from {$orders} where ordered_on > '{$dayStart}' AND ordered_on < '{$dayEnd}'";
        $dailyTotal = $wpdb->get_var($sql);
        $data['days'][$i] = date('m/d/Y', strtotime($dayStart, Cart66Common::localTs()));
        $data['totals'][$i] = $dailyTotal;
    }
    ?>
<table class="Cart66TableMed">
  <?php 
    for ($i = 0; $i < count($data['days']); $i++) {
        ?>
    <?php 
        if ($i % 7 == 0) {
            echo '<tr>';
        }
        ?>
コード例 #13
0
}
if (isset($_GET['duid'])) {
    $duid = $_GET['duid'];
    $product = new Cart66Product();
    if ($product->loadByDuid($duid)) {
        $okToDownload = true;
        if ($product->download_limit > 0) {
            // Check if download limit has been exceeded
            $order_item_id = $product->loadItemIdByDuid($duid);
            if ($product->countDownloadsForDuid($duid, $order_item_id) >= $product->download_limit) {
                $okToDownload = false;
            }
        }
        if ($okToDownload) {
            $data = array('duid' => $duid, 'downloaded_on' => date('Y-m-d H:i:s'), 'ip' => $_SERVER['REMOTE_ADDR'], 'order_item_id' => $product->loadItemIdByDuid($duid));
            $downloadsTable = Cart66Common::getTableName('downloads');
            $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>';
コード例 #14
0
 public static function promotionProductSearch()
 {
     global $wpdb;
     $search = Cart66Common::getVal('q');
     $product = new Cart66Product();
     $tableName = Cart66Common::getTableName('products');
     $products = $wpdb->get_results("SELECT id, name from {$tableName} WHERE name LIKE '%%%{$search}%%' ORDER BY id ASC LIMIT 10");
     $data = array();
     foreach ($products as $p) {
         $data[] = array('id' => $p->id, 'name' => $p->name);
     }
     echo json_encode($data);
     die;
 }
コード例 #15
0
 public function __construct($id = null)
 {
     $this->_tableName = Cart66Common::getTableName('pp_recurring_payments');
     parent::__construct($id);
 }
コード例 #16
0
 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;
 }
コード例 #17
0
 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;
     }
 }
コード例 #18
0
 public static function loadProductsOutsideOfClass($select = '*', $where = 'id > 0', $orderBy = 'name')
 {
     $tableName = Cart66Common::getTableName('products');
     $sql = "SELECT {$select}\n      from \n        {$tableName} \n      where\n        {$where}\n      order by\n        {$orderBy}\n    ";
     global $wpdb;
     $products = $wpdb->get_results($sql);
     return $products;
 }
コード例 #19
0
ファイル: debug.php プロジェクト: rbredow/allyzabbacart
?>
</span>
            </td>
          </tr>
          <tr valign="top">
            <th scope="row"><?php 
_e('Session Table Status', 'cart66');
?>
</th>
            <td>
              <?php 
global $wpdb;
$wpdb->query('CHECK TABLE `' . Cart66Common::getTableName('sessions') . '` QUICK');
if ($wpdb->last_result[0]->Msg_text != "OK" && isset($_GET['sessions']) && $_GET['sessions'] == 'repair') {
    $wpdb->query('REPAIR TABLE `' . Cart66Common::getTableName('sessions') . '`');
    $wpdb->query('CHECK TABLE `' . Cart66Common::getTableName('sessions') . '` QUICK');
}
echo Cart66Setting::validateDebugValue($wpdb->last_result[0]->Msg_text, __("OK", "cart66"));
if ($wpdb->last_result[0]->Msg_text != "OK") {
    ?>
                <a href="?page=cart66-settings&tab=debug_settings&sessions=repair" class="button-secondary"><?php 
    _e('Repair Table', 'cart66');
    ?>
</a>
              <?php 
}
?>
            </td>
          </tr>
        </tbody>
      </table>
コード例 #20
0
 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);
 }
コード例 #21
0
 public function updateMembershipProductIds()
 {
     global $wpdb;
     $output = false;
     // Check for subscriptions lacking a product id
     $sql = 'SELECT id from ' . Cart66Common::getTableName('account_subscriptions') . " WHERE product_id='0' OR product_id IS NULL";
     $needyAccountSubscriptions = $wpdb->get_results($sql);
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] " . count($needyAccountSubscriptions) . " accounts found that need to have a product id updated.");
     if (count($needyAccountSubscriptions) > 0) {
         // accounts needing product id have been found
         foreach ($needyAccountSubscriptions as $accountId) {
             $account = new Cart66AccountSubscription($accountId->id);
             $accountProductId = $account->getProductId();
             if ($accountProductId && !is_array($accountProductId)) {
                 $account->updateProductId($accountProductId);
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Adding Product id: {$accountProductId} to account id: {$accountId->id} ");
             } elseif (is_array($accountProductId)) {
                 $latestProductId = $account->findLatestProductId($accountProductId);
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Multiple products found for account {$accountId->id}");
                 if ($latestProductId) {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Latest membership product id found, id: {$latestProductId}");
                     $account->updateProductId($latestProductId);
                 }
             } else {
                 $output[] = "The subscription id:{$accountId->id} belonging to {$account->billing_first_name} {$account->billing_last_name} does not have a product ID associated with it. This will prevent notifications from being sent out. Please <a href='" . Cart66Common::replaceQueryString('page=cart66-accounts&accountId=' . $account->account_id) . "'>edit the account</a> and select a product ID.";
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] No products were found matching the feature level and subscription plan name of the account id: {$accountId->id}");
             }
         }
     }
     return $output;
 }
コード例 #22
0
 public function __construct($id = null)
 {
     $this->_tableName = Cart66Common::getTableName('shipping_rules');
     parent::__construct($id);
 }
コード例 #23
0
 public static function getSalesForMonth()
 {
     $thisMonth = Cart66Common::localTs();
     $year = date('Y', "{$thisMonth}");
     $month = date('n', "{$thisMonth}");
     $orders = Cart66Common::getTableName('orders');
     $orderItems = Cart66Common::getTableName('order_items');
     $products = Cart66Common::getTableName('products');
     $start = date('Y-m-d 00:00:00', strtotime($month . '/1/' . $year));
     $end = date('Y-m-d 00:00:00', strtotime($month . '/1/' . $year . ' +1 month'));
     $sql = "SELECT \n        oi.id, \n        oi.description, \n        oi.product_id, \n        oi.product_price, \n        o.ordered_on,\n        oi.quantity\n      from \n        {$products} as p,\n        {$orders} as o, \n        {$orderItems} as oi \n      where\n        oi.product_id = p.id and\n        oi.order_id = o.id and\n        o.ordered_on >= '{$start}' and \n        o.ordered_on < '{$end}'\n    ";
     global $wpdb;
     $results = $wpdb->get_results($sql);
     return $results;
 }
コード例 #24
0
 /**
  * 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
     }
 }
コード例 #25
0
 public static function getValue($key, $entities = false)
 {
     global $cart66Settings;
     if (isset($cart66Settings[$key])) {
         $value = $cart66Settings[$key];
     } else {
         global $wpdb;
         $settingsTable = Cart66Common::getTableName('cart_settings');
         $value = $wpdb->get_var("SELECT `value` from {$settingsTable} where `key`='{$key}'");
         $GLOBALS['cart66Settings'][$key] = $value;
     }
     if (!empty($value) && $entities) {
         $value = htmlentities($value, ENT_COMPAT, 'UTF-8');
     }
     return empty($value) ? false : $value;
 }
コード例 #26
0
 public function __construct($id = null)
 {
     $this->_tableName = Cart66Common::getTableName('products');
     parent::__construct($id);
 }
コード例 #27
0
        ?>
              <li>
                <label class="med" for="subscription-gravity_form_id"><?php 
        _e('Attach Gravity Form', 'cart66');
        ?>
:</label>
                <select name='subscription[gravity_form_id]' id="subscription-gravity_form_id">
                  <option value='0'><?php 
        _e('None', 'cart66');
        ?>
</option>
                  <?php 
        global $wpdb;
        $gfIdsInUse = Cart66GravityReader::getIdsInUse();
        $gfTitles = array();
        $forms = Cart66Common::getTableName('rg_form', '');
        $sql = "SELECT id, title from {$forms} where is_active=1 order by title";
        $results = $wpdb->get_results($sql);
        foreach ($results as $r) {
            $disabled = in_array($r->id, $gfIdsInUse) ? 'disabled="disabled"' : '';
            $gfTitles[$r->id] = $r->title;
            $selected = $data['subscription']->gravityFormId == $r->id ? 'selected="selected"' : '';
            echo "<option value='{$r->id}' {$selected} {$disabled}>{$r->title}</option>";
        }
        ?>
                </select>
                <span class="label_desc"><?php 
        _e('A Gravity Form may only be linked to one product', 'cart66');
        ?>
</span>
              </li>
コード例 #28
0
 /**
  * Return an array of Gravity Form ids that are linked to Cart66 products
  * 
  * @return array
  */
 public static function getIdsInUse()
 {
     global $wpdb;
     $products = Cart66Common::getTableName('products');
     $sql = "SELECT gravity_form_id as gfid from {$products} where gravity_form_id > 0";
     $ids = $wpdb->get_col($sql);
     return $ids;
 }