function smarty_function_ecomconfig($params, &$smarty) { $ecc = new ecomconfig(); $retval = $ecc->getConfig($params['var']); if (empty($retval)) { return $params['default']; } else { if ($params['unescape']) { $retval = stripcslashes($retval); } return $retval; } }
public function edit() { if (isset($this->params['id'])) { $record = new address(intval($this->params['id'])); } else { $record = null; } $config = ecomconfig::getConfig('address_allow_admins_all'); assign_to_template(array('record' => $record, 'admin_config' => $config)); }
public function getRates($order) { $a = $order->total; //get the rates for ($i = 0; $i < @count($this->configdata['from']); $i++) { // We need to check if it is not the last in the array since we don't have a 'to' value in the last element if (count($this->configdata['from']) != $i + 1) { if (expUtil::isNumberGreaterThanOrEqualTo($a, $this->configdata['from'][$i]) && expUtil::isNumberLessThanOrEqualTo($a, $this->configdata['to'][$i])) { foreach ($this->shippingspeeds as $item) { $c[] = @$this->configdata[str_replace(' ', '_', $item->speed)][$i]; } break; } } else { if ($a >= floatval($this->configdata['from'][$i])) { foreach ($this->shippingspeeds as $item) { $c[] = @$this->configdata[str_replace(' ', '_', $item->speed)][$i]; } break; } } } //if certain states, add $$ from config $currentMethod = $order->getCurrentShippingMethod(); //third created shipping method //Get the config and parse to get the states/regions only $upcharge = ecomconfig::getConfig('upcharge'); $stateUpcharge = ecomconfig::splitConfigUpCharge($upcharge, 'region'); //2 - alaska //21 - hawaii //52 - PuertoRico // $stateUpcharge = array('2','21','52'); $rates = array(); if (!empty($c)) { for ($i = 0; $i < count($c); $i++) { if (array_key_exists($currentMethod->state, $stateUpcharge)) { $c[$i] += $stateUpcharge[$currentMethod->state]; // $c[$i] += $stateUpcharge[$currentMethod->state]; Commented this though i'm not sure if this is done intentionally } if ($i > 9) { $rates[$i + 1] = array('id' => 0 . ($i + 1), 'title' => @$this->shippingspeeds[$i]->speed, 'cost' => $c[$i]); } else { $rates[0 . ($i + 1)] = array('id' => 0 . ($i + 1), 'title' => @$this->shippingspeeds[$i]->speed, 'cost' => $c[$i]); } } } if (!count($rates)) { $rates['01'] = array('id' => '01', 'title' => "Table Based Shipping is Currently NOT Configured", 'cost' => 0); } return $rates; }
public function getInvoiceNumber() { global $db; $sin = ecomconfig::getConfig('starting_invoice_number'); //$invoice_num = $db->max('orders', 'invoice_id') + 1; //start by locking the table to prevent another session from starting this same //function before we are done with it. Other sessions will wait until we're done, which //should be just a few milliseconds. $db->lockTable("orders_next_invoice_id"); //get the next id record $invoice_num = $db->max('orders_next_invoice_id', 'next_invoice_id'); //if it's not set or botched, then reset to the starting invoice number if (empty($invoice_num) || $invoice_num < $sin) { $invoice_num = $sin; //insert the table with the next available number $obj->id = 1; $obj->next_invoice_id = $invoice_num + 1; $db->insertObject($obj, 'orders_next_invoice_id'); } else { //update the table with the next available number $obj->id = 1; $obj->next_invoice_id = $invoice_num + 1; $db->updateObject($obj, 'orders_next_invoice_id'); } //unlock the table and return. $db->unlockTables(); return $invoice_num; }
public function update() { $product_types = ecomconfig::getConfig('product_types'); foreach ($product_types as $key => $value) { $this->params["{$value}s"] = listbuildercontrol::parseData($this->params, "{$value}s_list"); } $curcat = new storeCategory($this->params); $children = $curcat->getChildren(); foreach ($children as $key => $child) { $chldcat = new storeCategory($child->id); $chldcat->is_active = $this->params['is_active']; $chldcat->save(); } foreach ($product_types as $key => $value) { $type = $value . 's'; $product_type = new $type(); $product_type->saveCategories($this->params["{$type}"], $curcat->id, $type); } parent::update(); }
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 emailCustomer() { //eDebug($this->params,true); global $db, $template, $user; if (empty($this->params['id'])) { expHistory::back(); } // get the order $order = new order($this->params['id']); // Save the message for future use if that is what the user wanted. if (!empty($this->params['save_message'])) { $message->body = $this->params['email_message']; $db->insertObject($message, 'order_status_messages'); } $email_addys[] = explode(',', $this->params['to_addresses']); //$order->billingmethod[0]->email; //eDebug($email_addy,true); if (!empty($email_addys[0])) { assign_to_template(array('message' => $this->params['email_message'])); $html = $template->render(); if ($this->params['include_invoice']) { $html .= '<br><hr><br>'; $html .= renderAction(array('controller' => 'order', 'action' => 'show', 'view' => 'email_invoice', 'id' => $this->params['id'], 'printerfriendly' => '1', 'no_output' => 'true')); } else { $html .= ecomconfig::getConfig('footer'); } //eDebug($html,true); if (isset($this->params['from_address'])) { if ($this->params['from_address'] == 'other') { $from = $this->params['other_from_address']; } else { $from = $this->params['from_address']; } } else { $from = ecomconfig::getConfig('from_address'); } if (isset($this->params['email_subject'])) { $email_subject = $this->params['email_subject']; } else { $email_subject = 'Message from ' . ecomconfig::getConfig('storename') . ' about your order (#' . $order->invoice_id . ')'; } $mail = new expMail(); //FIXME Unless you need each mail sent separately, you can now set 'to'=>$email_addys and let expMail send a single email to all addresses foreach ($email_addys as $email_addy) { $mail->quickSend(array('html_message' => $html, 'text_message' => str_replace("<br>", "\r\n", $template->render()), 'to' => $email_addy, 'from' => $from, 'subject' => $email_subject)); } $emailed_to = implode(',', $email_addys); $note = new expSimpleNote(); $note->body = "<strong>[action]: Emailed message to " . $emailed_to . ":</strong><br><br>" . $this->params['email_message']; $note->approved = 1; $note->name = $user->firstname . " " . $user->lastname; $note->email = $user->email; $note->save(); $note->refresh(); $noteObj->expsimplenote_id = $note->id; $noteObj->content_id = $order->id; $noteObj->content_type = 'order'; $db->insertObject($noteObj, 'content_expSimpleNote'); //eDebug($note,true); } else { flash('error', gt('The email address was NOT sent. An email address count not be found for this customer')); expHistory::back(); } flash('message', gt('Email sent.')); expHistory::back(); }