public function _merge_order($to_merge_order_id, $data) { $transaction_id = $data['transaction_id']; $to_merge_order = $this->order_model->get_order($to_merge_order_id); $currency = $data['currency']; $gross = $data['gross']; $fee = $data['fee']; $shippingamt = $data['shippingamt']; $item_title_str = $data['item_title_str']; $item_id_str = $data['item_id_str']; $sku_str = $data['sku_str']; $qty_str = $data['qty_str']; $to_merged_item_ids = explode(',', $to_merge_order->item_id_str); $transaction_ids = array(); foreach ($to_merged_item_ids as $item_id) { $transaction_ids[] = $to_merge_order->transaction_id; } $item_ids = explode(',', $item_id_str); foreach ($item_ids as $item_id) { $transaction_ids[] = $transaction_id; } // starting merging if ($to_merge_order->currency == $currency) { $new_gross = $to_merge_order->gross + $gross; $new_fee = $to_merge_order->fee + $fee; $new_shippingamt = $to_merge_order->shippingamt + $shippingamt; } else { $tmp_rmb = calc_currency($currency, $gross); $new_gross = $to_merge_order->gross + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb)); $tmp_rmb = calc_currency($currency, $fee); $new_fee = $to_merge_order->fee + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb)); $tmp_rmb = calc_currency($currency, $shippingamt); $new_shippingamt = $to_merge_order->shippingamt + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb)); } $new_net = $new_gross - $new_fee; $new_title = $to_merge_order->item_title_str . ITEM_TITLE_SEP . $item_title_str; $new_id = $to_merge_order->item_id_str . ',' . $item_id_str; $new_sku_str = $to_merge_order->sku_str . ',' . $sku_str; $new_amount = $to_merge_order->qty_str . ',' . $qty_str; $sys_remark = $to_merge_order->sys_remark . ', ' . sprintf(lang('merge_log'), get_current_time(), $transaction_id); $data = array('gross' => $new_gross, 'fee' => $new_fee, 'net' => $new_net, 'item_title_str' => $new_title, 'item_id_str' => $new_id, 'sku_str' => $new_sku_str, 'qty_str' => $new_amount, 'sys_remark' => $sys_remark, 'is_merged' => 1, 'shippingamt' => $new_shippingamt); $sku_price = 0; $sku_weight = 0; $tmp_i = 0; $tmp_skus = explode(',', $new_sku_str); $tmp_qties = explode(',', $new_amount); foreach ($tmp_skus as $tmp_sku) { $tmp_qty = $tmp_qties[$tmp_i]; $product = $this->product_model->fetch_product_by_sku($tmp_sku); $sku_price += $product->price * $tmp_qty; $sku_weight += $product->total_weight * $tmp_qty; $tmp_i++; } $order_data = array('item_id_str' => $new_id, 'gross' => $new_gross, 'net' => $new_net, 'currency' => $currency, 'transaction_ids' => $transaction_ids, 'shipping_code' => $to_merge_order->is_register, 'price' => $sku_price, 'shipping_weight' => $sku_weight, 'country' => $to_merge_order->country); $profit = $this->_calculate_profit_rate($order_data); $data['profit_rate'] = $profit['profit_rate']; $data['shipping_cost'] = $profit['shipping_cost']; $data['product_cost_all'] = $profit['product_cost']; $data['trade_fee'] = $profit['trade_fee']; $data['listing_fee'] = $profit['listing_fee']; // order role $order_role = $this->_get_order_role($data['sku_str'], $to_merge_order->to_email); $data['stock_user_id'] = $order_role['stock_user_id']; $data['purchaser_id_str'] = $order_role['purchaser_id_str']; $data['developer_id'] = $order_role['developer_id']; $data['saler_id'] = $order_role['saler_id']; $data['tester_id'] = $order_role['tester_id']; // promote shipping code from P to PT if in need. if ($to_merge_order->is_register == 'P' || 1 == 1) { $args = array('gross_usd' => to_usd($currency, $new_gross)); //$tmp_shipping_code = regular_shipping_code($args); $item_info = array('item_qties' => explode(',', $new_amount), 'item_codes' => explode(',', $new_sku_str), 'item_ids' => explode(',', $new_id), 'ship_to_country' => $to_merge_order->country, 'gross' => $new_gross, 'gross_usd' => $this->order_model->to_usd($currency, $new_gross)); $tmp_shipping_code = get_register($item_info, '', $currency, array($transaction_id, $to_merge_order->transaction_id)); if ($to_merge_order->is_register != $tmp_shipping_code) { $data['is_register'] = $tmp_shipping_code; $data['item_no'] = change_item_register($to_merge_order->item_no, $to_merge_order->is_register, $tmp_shipping_code); } } $this->order_model->update_order_information($to_merge_order_id, $data); $this->paypal_model->save_merged_list(array('order_id' => $to_merge_order_id, 'transaction_id' => $transaction_id, 'item_title_str' => $item_title_str, 'item_id_str' => $item_id_str, 'buyer_id' => $to_merge_order->buyer_id, 'buyer_name' => $to_merge_order->name)); return TRUE; }
private function _parse_email_template($order, $sender_name = 'Mallerp') { $view = 'local/english/template/email/order_shipped_notification'; $item_titles = explode(',', $order->item_title_str); $skus = explode(',', $order->sku_str); $qties = explode(',', $order->qty_str); $item_list_entries = array(); $i = 0; foreach ($item_titles as $item_title) { $sku = ''; $qty = ''; if (isset($skus[$i])) { $sku = $skus[$i]; } if (isset($qties[$i])) { $qty = $qties[$i]; } $item_list_entries[] = array('item_name' => $item_title, 'sku' => $sku, 'qty' => $qty); $i++; } $address = append_if_not_empty($order->country, '<br/>') . append_if_not_empty($order->state_province, '<br/>') . append_if_not_empty($order->town_city, '<br/>') . append_if_not_empty($order->address_line_1, '<br/>') . append_if_not_empty($order->address_line_2, '<br/>') . $order->name . '<br/>' . $order->zip_code; $shipping_method = shipping_method($order->is_register); $usd = to_usd($order->currency, $order->gross); $data = array('buyer_name' => $order->name, 'item_no' => $order->item_no, 'shipped_date' => $order->ship_confirm_date, 'item_list_entries' => $item_list_entries, 'weight' => $order->ship_weight, 'shipping_address' => $address, 'track_number' => empty($order->track_number) ? 'None' : $order->track_number, 'track_url' => $shipping_method->check_url, 'shipping_method' => $shipping_method->name_en, 'email' => $order->to_email, 'sender_name' => $sender_name, 'usd' => $usd); return $this->parser->parse($view, $data, TRUE); }