function leaveMessage() { if (!empty($this->params['shippingmessageid'])) { $sm = new shippingmethod($this->params['shippingmessageid']); if ($this->params['nosave'] == false) { $sm->to = empty($this->params['shpmessageto']) ? null : $this->params['shpmessageto']; $sm->from = empty($this->params['shpmessagefrom']) ? null : $this->params['shpmessagefrom']; $sm->message = empty($this->params['shpmessage']) ? null : $this->params['shpmessage']; $sm->save(); } } $ar = new expAjaxReply(200, 'ok', $sm, array('controller' => 'cart', 'action' => 'checkout')); $ar->send(); }
public function getShippingMethods() { global $db; $ids = $db->selectColumn('orderitems', 'shippingmethods_id', 'shippingmethods_id!=0 AND orders_id=' . $this->id, null, true); //if we have no order items, then we'll set a 'default' shipping method to the order if (empty($ids)) { if (isset($this->shippingmethod->id)) { $ids = array($this->shippingmethod->id); } else { $sm = new shippingmethod(); //(eDebug($db->selectValue('shippingcalculator','id','is_default=1'),true)); $sm->shippingcalculator_id = $db->selectValue('shippingcalculator', 'id', 'is_default=1'); $sm->save(); //$this->setActiveShippingMethod($sm); $this->shippingmethods_id = $sm->id; $this->save(); $this->refresh(); $ids = array($sm->id); } } return $ids; }
function process_orders() { /* Testing */ /*echo "Here?"; $inv = 30234; $req = 'a29f9shsgh32hsf80s7'; $amt = 101.00; for($count=1;$count<=25;$count+=2) { $data[2] = $inv + $count; $amt += $count*$count; $successSet[$count]['message'] = "Sucessfully imported row " . $count . ", order: " . $data[2] . "<br/>"; $successSet[$count]['order_id'] = $data[2]; $successSet[$count]['amount'] = $amt; $successSet[$count]['request_id'] = $req; $successSet[$count]['reference_id'] = $req; $successSet[$count]['authorization_code'] = $req; $successSet[$count]['shipping_tracking_number'] = '1ZNF453937547'; $successSet[$count]['carrier'] = 'UPS'; } for($count=2;$count<=25;$count+=2) { $data[2] = $inv + $count; $amt += $count*$count; $errorSet[$count]['error_code'] = '42'; $errorSet[$count]['message'] = "No go for some odd reason. Try again."; $errorSet[$count]['order_id'] = $data[2]; $errorSet[$count]['amount'] = $amt; } assign_to_template(array('errorSet'=>$errorSet, 'successSet'=>$successSet)); return;*/ ########### global $db; $template = get_template_for_action(new orderController(), 'setStatus', $this->loc); //eDebug($_FILES); //eDebug($this->params,true); set_time_limit(0); //$file = new expFile($this->params['expFile']['batch_process_upload'][0]); if (!empty($_FILES['batch_upload_file']['error'])) { flash('error', gt('There was an error uploading your file. Please try again.')); redirect_to(array('controller' => 'store', 'action' => 'batch_process')); } $file->path = $_FILES['batch_upload_file']['tmp_name']; echo "Validating file...<br/>"; $checkhandle = fopen($file->path, "r"); $checkdata = fgetcsv($checkhandle, 10000, ","); $fieldCount = count($checkdata); $count = 1; while (($checkdata = fgetcsv($checkhandle, 10000, ",")) !== FALSE) { $count++; if (count($checkdata) != $fieldCount) { echo "Line " . $count . " of your CSV import file does not contain the correct number of columns.<br/>"; echo "Found " . $fieldCount . " header fields, but only " . count($checkdata) . " field in row " . $count . " Please check your file and try again."; exit; } } fclose($checkhandle); echo "<br/>CSV File passed validation...<br/><br/>Detecting carrier type....<br/>"; //exit(); $handle = fopen($file->path, "r"); $data = fgetcsv($handle, 10000, ","); //eDebug($data); $dataset = array(); $carrier = ''; if (trim($data[0]) == 'ShipmentInformationShipmentID') { echo "Detected UPS file...<br/>"; $carrier = "UPS"; $carrierTrackingLink = "http://wwwapps.ups.com/etracking/tracking.cgi?TypeOfInquiryNumber=T&InquiryNumber1="; } elseif (trim($data[0]) == 'PIC') { echo "Detected United States Post Service file...<br/>"; $carrier = "USPS"; $carrierTrackingLink = "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum="; } //eDebug($carrier); $count = 1; $errorSet = array(); $successSet = array(); $oo = new order(); while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) { $count++; $originalOrderId = $data[2]; $data[2] = intval($data[2]); $order = null; $bm = null; $transactionState = null; //check for valid order number - if not present or not order, fail and continue with next record if (isset($data[2]) && !empty($data[2])) { $order = $oo->findBy('invoice_id', $data[2]); if (empty($order->id)) { $errorSet[$count]['message'] = $originalOrderId . " is not a valid order in this system."; $errorSet[$count]['order_id'] = $originalOrderId; continue; } } else { $errorSet[$count]['message'] = "Row " . $count . " has no order number."; $errorSet[$count]['order_id'] = "N/A"; continue; } /*we have a valid order, so let's see what we can do: */ //set status of order to var $currentStat = $order->order_status; //eDebug($currentStat,true); //-- check the order for a closed status - if so, do NOT process or set shipping if ($currentStat->treat_as_closed == true) { $errorSet[$count]['message'] = "This is currently a closed order. Not processing."; $errorSet[$count]['order_id'] = $data[2]; continue; } //ok, if we made it here we have a valid order that is "open" //we'll try to capture the transaction if it's in an authorized state, but set shipping regardless if (isset($order->billingmethod[0])) { $bm = $order->billingmethod[0]; $transactionState = $bm->transaction_state; } else { $bm = null; $transactionState = ''; } if ($transactionState == 'authorized') { //eDebug($order,true); $calc = $bm->billingcalculator->calculator; $calc->config = $bm->billingcalculator->config; if (method_exists($calc, 'delayed_capture')) { //$result = $calc->delayed_capture($bm,$bm->billing_cost); $result = $calc->delayed_capture($bm, $order->grand_total); if ($result->errorCode == 0) { //we've succeeded. transaction already created and billing info updated. //just need to set the order shipping info, check and see if we send user an email, and set statuses. //shipping info: $successSet[$count]['order_id'] = $data[2]; $successSet[$count]['message'] = "Sucessfully captured order " . $data[2] . " and set shipping information."; $successSet[$count]['amount'] = $order->grand_total; $successSet[$count]['request_id'] = $result->request_id; $successSet[$count]['reference_id'] = $result->PNREF; $successSet[$count]['authorization_code'] = $result->AUTHCODE; $successSet[$count]['shipping_tracking_number'] = $data[0]; $successSet[$count]['carrier'] = $carrier; } else { //failed capture, so we report the error but still set the shipping information //because it's already out the door //$failMessage = "Attempted to delay capture order " . $data[2] . " and it failed with the following error: " . $result->errorCode . " - " .$result->message; //if the user seelected to set a different status for failed orders, set it here. /*if(isset($this->params['order_status_fail'][0]) && $this->params['order_status_fail'][0] > -1) { $change = new order_status_changes(); // save the changes $change->from_status_id = $order->order_status_id; //$change->comment = $this->params['comment']; $change->to_status_id = $this->params['order_status_fail'][0]; $change->orders_id = $order->id; $change->save(); // update the status of the order $order->order_status_id = $this->params['order_status_fail'][0]; $order->save(); }*/ $errorSet[$count]['error_code'] = $result->errorCode; $errorSet[$count]['message'] = "Capture failed: " . $result->message . "<br/>Setting shipping information."; $errorSet[$count]['order_id'] = $data[2]; $errorSet[$count]['amount'] = $order->grand_total; $errorSet[$count]['shipping_tracking_number'] = $data[0]; $errorSet[$count]['carrier'] = $carrier; //continue; } } else { //dont suppose we do anything here, as it may be set to approved manually //$errorSet[$count] = "Order " . $data[2] . " does not use a billing method with delayed capture ability."; $successSet[$count]['message'] = 'No capture processing available for order:' . $data[2] . '. Setting shipping information.'; $successSet[$count]['order_id'] = $data[2]; $successSet[$count]['amount'] = $order->grand_total; $successSet[$count]['shipping_tracking_number'] = $data[0]; $successSet[$count]['carrier'] = $carrier; } } else { $successSet[$count]['message'] = 'No processing necessary for order:' . $data[2] . '. Setting shipping information.'; $successSet[$count]['order_id'] = $data[2]; $successSet[$count]['amount'] = $order->grand_total; $successSet[$count]['shipping_tracking_number'] = $data[0]; $successSet[$count]['carrier'] = $carrier; } $order->shipped = time(); $order->shipping_tracking_number = $data[0]; $order->save(); $s = array_pop($order->shippingmethods); $sm = new shippingmethod($s->id); $sm->carrier = $carrier; $sm->save(); //statuses and email if (isset($this->params['order_status_success'][0]) && $this->params['order_status_success'][0] > -1) { $change = new order_status_changes(); // save the changes $change->from_status_id = $order->order_status_id; //$change->comment = $this->params['comment']; $change->to_status_id = $this->params['order_status_success'][0]; $change->orders_id = $order->id; $change->save(); // update the status of the order $order->order_status_id = $this->params['order_status_success'][0]; $order->save(); // email the user if we need to if (!empty($this->params['email_customer'])) { $email_addy = $order->billingmethod[0]->email; if (!empty($email_addy)) { $from_status = $db->selectValue('order_status', 'title', 'id=' . $change->from_status_id); $to_status = $db->selectValue('order_status', 'title', 'id=' . $change->to_status_id); $template->assign(array('comment' => $change->comment, 'to_status' => $to_status, 'from_status' => $from_status, 'order' => $order, 'date' => date("F j, Y, g:i a"), 'storename' => ecomconfig::getConfig('storename'), 'include_shipping' => true, 'tracking_link' => $carrierTrackingLink . $order->shipping_tracking_number, 'carrier' => $carrier)); $html = $template->render(); $html .= ecomconfig::getConfig('footer'); try { $mail = new expMail(); $mail->quickSend(array('html_message' => $html, 'text_message' => str_replace("<br>", "\r\n", $template->render()), 'to' => $email_addy, 'from' => ecomconfig::getConfig('from_address'), 'subject' => 'Your Order Has Been Shipped (#' . $order->invoice_id . ') - ' . ecomconfig::getConfig('storename'))); } catch (Exception $e) { //do nothing for now eDebug("Email error:"); eDebug($e); } } //else { // $errorSet[$count]['message'] .= "<br/>Order " . $data[2] . " was captured successfully, however the email notification was not successful."; //} } } //eDebug($product); } assign_to_template(array('errorSet' => $errorSet, 'successSet' => $successSet)); }
function save_order_item() { $oi = new orderitem($this->params['id']); //eDebug($this->params); /*eDebug($oi); eDebug(expUnserialize($oi->options)); eDebug(expUnserialize($oi->user_input_fields),true);*/ $oi->products_price = $this->params['products_price']; $oi->quantity = $this->params['quantity']; $oi->products_name = $this->params['products_name']; if ($oi->product->parent_id != 0) { $oi->product = new product($oi->product->parent_id, true, false); } else { //reattach the product so we get the optoin fields and such $oi->product = new product($oi->product->id, true, false); } //eDebug($oi->product,true); foreach ($oi->product->optiongroup as $og) { $isOptionEmpty = true; if (!empty($this->params['options'][$og->id])) { foreach ($this->params['options'][$og->id] as $opt) { if (!empty($opt)) { $isOptionEmpty = false; } } } if (!$isOptionEmpty) { foreach ($this->params['options'][$og->id] as $opt_id) { $selected_option = new option($opt_id); $cost = $selected_option->modtype == '$' ? $selected_option->amount : $this->getBasePrice() * ($selected_option->amount * 0.01); $cost = $selected_option->updown == '+' ? $cost : $cost * -1; $options[] = array($selected_option->id, $selected_option->title, $selected_option->modtype, $selected_option->updown, $selected_option->amount); } } } eDebug($this->params); //eDebug($oi,true); $user_input_info = array(); //check user input fields //$this->user_input_fields = expUnserialize($this->user_input_fields); //eDebug($this,true); foreach ($oi->product->user_input_fields as $uifkey => $uif) { /*if ($uif['is_required'] || (!$uif['is_required'] && strlen($params['user_input_fields'][$uifkey]) > 0)) { if (strlen($params['user_input_fields'][$uifkey]) < $uif['min_length']) { //flash('error', 'test'); //redirect_to(array('controller'=>cart, 'action'=>'displayForm', 'form'=>'addToCart', 'product_id'=>$this->id, 'product_type'=>$this->product_type)); $params['error'] .= $uif['name'].' field has a minimum requirement of ' . $uif['min_length'] . ' characters.<br/>'; }else if (strlen($params['user_input_fields'][$uifkey]) > $uif['max_length'] && $uif['max_length'] > 0) { //flash('error', ); //redirect_to(array('controller'=>cart, 'action'=>'displayForm', 'form'=>'addToCart', 'product_id'=>$this->id, 'product_type'=>$this->product_type)); $params['error'] .= $uif['name'].' field has a maximum requirement of ' . $uif['max_length'] . ' characters.<br/>'; } }*/ $user_input_info[] = array($uif['name'] => $this->params['user_input_fields'][$uifkey]); } //eDebug($options); //eDebug($user_input_info,true); $oi->options = serialize($options); $oi->user_input_fields = serialize($user_input_info); //eDebug($oi); $oi->save(); $oi->refresh(); //eDebug($oi,true); $order = new order($oi->orders_id); $order->calculateGrandTotal(); $s = array_pop($order->shippingmethods); eDebug($s); $sm = new shippingmethod($s->id); $shippingCalc = new shippingcalculator($sm->shippingcalculator_id); $calcName = $shippingCalc->calculator_name; $calculator = new $calcName($shippingCalc->id); $pricelist = $calculator->getRates($order); foreach ($pricelist as $rate) { if ($rate['id'] == $sm->option) { $sm->shipping_cost = $rate['cost']; break; } } $sm->save(); $order->refresh(); $order->calculateGrandTotal(); $order->save(); flashAndFlow('message', 'Order item updated and order totals recalculated.'); redirect_to(array('controller' => 'order', 'action' => 'show', 'id' => $this->params['orderid'])); }