public function showReceipt($attrs) { $account = null; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['ouid'])) { if (CART66_PRO && isset($_POST['account'])) { $acctData = Cart66Common::postVal('account'); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] New Account Data: " . print_r($acctData, true)); $account = new Cart66Account(); $account->firstName = $acctData['first_name']; $account->lastName = $acctData['last_name']; $account->email = $acctData['email']; $account->username = $acctData['username']; $account->password = md5($acctData['password']); $errors = $account->validate(); $jqErrors = $account->getJqErrors(); if ($acctData['password'] != $acctData['password2']) { $errors[] = __("Passwords do not match", "cart66"); $jqErrors[] = 'account-password'; $jqErrors[] = 'account-password2'; } if (count($errors) == 0) { // Attach account to order $order = new Cart66Order(); $ouid = Cart66Common::postVal('ouid'); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Trying to load order with OUID: {$ouid}"); if ($order->loadByOuid($ouid)) { // Make sure the order can be loaded, then save the account $account->save(); // Attach membership to account and account to the order if ($mp = $order->getMembershipProduct()) { $account->attachMembershipProduct($mp, $account->firstName, $account->lastName); $order->account_id = $account->id; $order->save(); $account->clear(); } } } else { $attrs['errors'] = $errors; $attrs['jqErrors'] = $jqErrors; } } } $attrs['account'] = $account; $view = Cart66Common::getView('views/receipt.php', $attrs, true, true); return $view; }
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); }