Example #1
0
 public function save()
 {
     global $db;
     $obj->id = $this->id;
     $obj->optiongroup_master_id = $this->optiongroup_master_id;
     $obj->product_id = $this->product_id;
     $obj->title = $this->title;
     $obj->allow_multiple = $this->allow_multiple;
     $obj->required = $this->required;
     $obj->rank = $this->rank;
     eDebug($obj->rank);
     if (empty($obj->rank)) {
         $obj->rank = $db->max('optiongroup', 'rank', null, "product_id=" . $this->product_id) + 1;
     }
     eDebug($obj->rank);
     if (empty($obj->id)) {
         $this->id = $db->insertObject($obj, 'optiongroup');
     } else {
         $db->updateObject($obj, 'optiongroup');
     }
 }
Example #2
0
 public static function sortByVolume($a, $b)
 {
     eDebug($a);
     return $a->volume > $b->volume ? -1 : 1;
 }
Example #3
0
/**
 * Smarty {edebug} function plugin
 *
 * Type:     function<br>
 * Name:     edebug<br>
 * Purpose:  dump a variable
 *
 * @param         $params
 * @param \Smarty $smarty
 */
function smarty_function_edebug($params, &$smarty)
{
    echo eDebug($params['var']);
}
Example #4
0
 function process_external_addresses()
 {
     global $db;
     set_time_limit(0);
     //$file = new expFile($this->params['expFile']['batch_process_upload'][0]);
     eDebug($this->params);
     //        eDebug($_FILES,true);
     if (!empty($_FILES['address_csv']['error'])) {
         flash('error', gt('There was an error uploading your file.  Please try again.'));
         redirect_to(array('controller' => 'store', 'action' => 'import_external_addresses'));
     }
     $file->path = $_FILES['address_csv']['tmp_name'];
     echo "Validating file...<br/>";
     //replace tabs with commas
     /*if($this->params['type_of_address'][0] == 'am')
       {
           $checkhandle = fopen($file->path, "w");
           $oldFile = file_get_contents($file->path);
           $newFile = str_ireplace(chr(9),',',$oldFile);
           fwrite($checkhandle,$newFile);
           fclose($checkhandle);
       }*/
     $checkhandle = fopen($file->path, "r");
     if ($this->params['type_of_address'][0] == 'am') {
         $checkdata = fgetcsv($checkhandle, 10000, "\t");
         $fieldCount = count($checkdata);
     } else {
         $checkdata = fgetcsv($checkhandle, 10000, ",");
         $fieldCount = count($checkdata);
     }
     $count = 1;
     if ($this->params['type_of_address'][0] == 'am') {
         while (($checkdata = fgetcsv($checkhandle, 10000, "\t")) !== FALSE) {
             $count++;
             //eDebug($checkdata);
             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;
             }
         }
     } else {
         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/>Importing....<br/><br/>";
     //exit();
     $handle = fopen($file->path, "r");
     $data = fgetcsv($handle, 10000, ",");
     //eDebug($data);
     $dataset = array();
     //mc=1, nt=2, amm=3
     if ($this->params['type_of_address'][0] == 'mc') {
         //militaryclothing
         $db->delete('external_addresses', 'source=1');
     } else {
         if ($this->params['type_of_address'][0] == 'nt') {
             //nametapes
             $db->delete('external_addresses', 'source=2');
         } else {
             if ($this->params['type_of_address'][0] == 'am') {
                 //amazon
                 $db->delete('external_addresses', 'source=3');
             }
         }
     }
     if ($this->params['type_of_address'][0] == 'am') {
         while (($data = fgetcsv($handle, 10000, "\t")) !== FALSE) {
             //eDebug($data,true);
             $extAddy = new external_address();
             //eDebug($data);
             $extAddy->source = 3;
             $extAddy->user_id = 0;
             $name = explode(' ', $data[15]);
             $extAddy->firstname = $name[0];
             if (isset($name[3])) {
                 $extAddy->firstname .= ' ' . $name[1];
                 $extAddy->middlename = $name[2];
                 $extAddy->lastname = $name[3];
             } else {
                 if (isset($name[2])) {
                     $extAddy->middlename = $name[1];
                     $extAddy->lastname = $name[2];
                 } else {
                     $extAddy->lastname = $name[1];
                 }
             }
             $extAddy->organization = $data[15];
             $extAddy->address1 = $data[16];
             $extAddy->address2 = $data[17];
             $extAddy->city = $data[19];
             $state = new geoRegion();
             $state = $state->findBy('code', trim($data[20]));
             if (empty($state->id)) {
                 $state = new geoRegion();
                 $state = $state->findBy('name', trim($data[20]));
             }
             $extAddy->state = $state->id;
             $extAddy->zip = str_ireplace("'", '', $data[21]);
             $extAddy->phone = $data[6];
             $extAddy->email = $data[4];
             //eDebug($extAddy);
             $extAddy->save();
         }
     } else {
         while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
             eDebug($data);
             $extAddy = new external_address();
             if ($this->params['type_of_address'][0] == 'mc') {
                 $extAddy->source = 1;
                 $extAddy->user_id = 0;
                 $name = explode(' ', $data[3]);
                 $extAddy->firstname = $name[0];
                 if (isset($name[2])) {
                     $extAddy->middlename = $name[1];
                     $extAddy->lastname = $name[2];
                 } else {
                     $extAddy->lastname = $name[1];
                 }
                 $extAddy->organization = $data[4];
                 $extAddy->address1 = $data[5];
                 $extAddy->address2 = $data[6];
                 $extAddy->city = $data[7];
                 $state = new geoRegion();
                 $state = $state->findBy('code', $data[8]);
                 $extAddy->state = $state->id;
                 $extAddy->zip = str_ireplace("'", '', $data[9]);
                 $extAddy->phone = $data[20];
                 $extAddy->email = $data[21];
                 //eDebug($extAddy);
                 $extAddy->save();
                 //Check if the shipping add is same as the billing add
                 if ($data[5] != $data[14]) {
                     $extAddy = new external_address();
                     $extAddy->source = 1;
                     $extAddy->user_id = 0;
                     $name = explode(' ', $data[12]);
                     $extAddy->firstname = $name[0];
                     if (isset($name[2])) {
                         $extAddy->middlename = $name[1];
                         $extAddy->lastname = $name[2];
                     } else {
                         $extAddy->lastname = $name[1];
                     }
                     $extAddy->organization = $data[13];
                     $extAddy->address1 = $data[14];
                     $extAddy->address2 = $data[15];
                     $extAddy->city = $data[16];
                     $state = new geoRegion();
                     $state = $state->findBy('code', $data[17]);
                     $extAddy->state = $state->id;
                     $extAddy->zip = str_ireplace("'", '', $data[18]);
                     $extAddy->phone = $data[20];
                     $extAddy->email = $data[21];
                     // eDebug($extAddy, true);
                     $extAddy->save();
                 }
             }
             if ($this->params['type_of_address'][0] == 'nt') {
                 //eDebug($data,true);
                 $extAddy->source = 2;
                 $extAddy->user_id = 0;
                 $extAddy->firstname = $data[16];
                 $extAddy->lastname = $data[17];
                 $extAddy->organization = $data[15];
                 $extAddy->address1 = $data[18];
                 $extAddy->address2 = $data[19];
                 $extAddy->city = $data[20];
                 $state = new geoRegion();
                 $state = $state->findBy('code', $data[21]);
                 $extAddy->state = $state->id;
                 $extAddy->zip = str_ireplace("'", '', $data[22]);
                 $extAddy->phone = $data[23];
                 $extAddy->email = $data[13];
                 //eDebug($extAddy);
                 $extAddy->save();
             }
         }
     }
     echo "Done!";
 }
Example #5
0
 /**
  * test() - Does the mail system seem to be working correctly?
  *   This is useless for the Native mail system
  *
  * @todo Update this section to use more error checking
  */
 public function test()
 {
     try {
         $this->transport->start();
         echo "<h2>Mail Server Test Complete!</h2>We Connected to the Mail Server";
     } catch (Swift_TransportException $e) {
         echo "<h2>Mail Server Test Failed!</h2>";
         eDebug($e->getMessage());
     }
 }
Example #6
0
/**
 * dumps the passed variable to a log, but only if in development mode
 * @param  $var the variable to log
 * @param string $type the type of entry to record
 * @param string $path the pathname for the log file
 * @param string $minlevel
 * @return void
 */
function eLog($var, $type = '', $path = '', $minlevel = '0')
{
    if ($type == '') {
        $type = "INFO";
    }
    if ($path == '') {
        $path = BASE . 'tmp/exponent.log';
    }
    if (DEVELOPMENT >= $minlevel) {
        if (is_writable($path) || !file_exists($path)) {
            if (!($log = fopen($path, "ab"))) {
                eDebug(gt("Error opening log file for writing."));
            } else {
                if (fwrite($log, $type . ": " . $var . "\r\n") === FALSE) {
                    eDebug(gt("Error writing to log file") . " (" . $path . ").");
                }
                fclose($log);
            }
        } else {
            eDebug(gt("Log file" . " (" . $path) . " " . gt("not writable."));
        }
    }
}
Example #7
0
 public function __construct()
 {
     global $order, $user;
     if (empty($order->id)) {
         return false;
     }
     $existing_shippingmethods = $order->getShippingMethods();
     $this->available_calculators = $this->listAvailableCalculators();
     $this->selectable_calculators = $this->selectableCalculators();
     if (count($existing_shippingmethods) == 1) {
         if ($order->forcedShipping()) {
             $this->shippingmethod = $order->getForcedShippingMethod();
             $this->forced_shipping = true;
         } else {
             $this->shippingmethod = $order->getCurrentShippingMethod();
         }
         // if this shippingmethod doesn't have an address assigned to it, lets check and see if this
         // user has set one up yet and default to that if so
         //if (empty($this->shippingmethod->addresses_id) && $user->isLoggedIn()) {
         if ($user->id != 0) {
             $address = new address();
             $addy = $address->find('first', 'user_id=' . $user->id . '  AND is_shipping=1');
             if (empty($addy->id)) {
                 $addy = $address->find('first', 'user_id=' . $user->id);
             }
             if (!empty($addy->id)) {
                 $this->shippingmethod->setAddress($addy);
             }
         }
         $this->address = new address($this->shippingmethod->addresses_id);
         $number_of_calculators = count($this->available_calculators);
         if ($number_of_calculators == 1 || empty($this->shippingmethod->shippingcalculator_id)) {
             $calcid = key($this->available_calculators);
             if ($this->shippingmethod->shippingcalculator_id != $calcid) {
                 $this->shippingmethod->update(array('shippingcalculator_id' => $calcid));
             }
         }
         if (!empty($this->available_calculators) && !empty($this->shippingmethod->shippingcalculator_id)) {
             if (isset($this->available_calculators[$this->shippingmethod->shippingcalculator_id])) {
                 $calcname = $this->available_calculators[$this->shippingmethod->shippingcalculator_id];
             } else {
                 //recently reconfigured/disabled shipping calc that was already set in the object, so default to the first one available
                 $key = array_shift(array_keys($this->available_calculators));
                 $calcname = $this->available_calculators[$key];
                 $this->shippingmethod->shippingcalculator_id = $key;
             }
             $this->calculator = new $calcname($this->shippingmethod->shippingcalculator_id);
         } else {
             $this->calculator = null;
         }
         $this->getRates();
     } else {
         eDebug($this);
         eDebug($order);
         eDebug("Error in shipping constuctor.", true);
         //NO split shipping for now
         /*$this->splitshipping = true;
           $this->splitmethods = array();
           foreach ($existing_shippingmethods as $smid) {
               $method = new shippingmethod($smid);
               if ($method->requiresShipping()) {
                   $this->splitmethods[$method->id] = $method;
                   $this->splitmethods[$method->id]->orderitem = $order->getOrderitemsByShippingmethod($method->id);
               }
               
           } */
     }
 }
Example #8
0
 function add_order_item()
 {
     eDebug($this->params);
     $product = new product($this->params['product_id']);
     $paramsArray = array('orderid' => $this->params['orderid']);
     assign_to_template(array('product' => $product, 'params' => $paramsArray));
 }
Example #9
0
 /**
  * Add a log entry.
  */
 public function add($entry)
 {
     eDebug($entry);
 }
Example #10
0
 function status_export()
 {
     global $db;
     //eDebug($this->params);
     //$sql = "SELECT * INTO OUTFILE '" . BASE . "tmp/export.csv' FIELDS TERMINATED BY ','  FROM exponent_product WHERE 1 LIMIT 10";
     //is | parent_id | SKU |WAREHOUSE LOCATION | Title | Vendor/Manufacturer | Product Status | Notes
     $out = '"id","parent_id","model","warehouse_location","title","vendor","product_status","notes"' . chr(13) . chr(10);
     if (isset($this->params['applytoall']) && $this->params['applytoall'] == 1) {
         $sql = expSession::get('product_export_query');
         //eDebug($sql);
         //expSession::set('product_export_query','');
         $prods = $db->selectArraysBySql($sql);
         //eDebug($prods);
     } else {
         foreach ($this->params['act-upon'] as $prod) {
             $prods[] = array('id' => $prod);
         }
     }
     $stats = new product_status();
     $stats = $stats->find('all');
     $statuses = array();
     foreach ($stats as $stat) {
         $statuses[$stat->id] = $stat->title;
     }
     eDebug($statuses);
     set_time_limit(0);
     $baseProd = new product();
     //$p = new product($pid['id'], false, false);
     //id | parent_id | SKU |WAREHOUSE LOCATION | Title | Vendor/Manufacturer | Product Status | Notes
     foreach ($prods as $pid) {
         $except = array('crosssellItem', 'optiongroup', 'childProduct');
         $p = $baseProd->find('first', 'id=' . $pid['id'], null, null, null, true, true, $except, true);
         /*if(count($p->expSimpleNote))
           {
               eDebug($p,true);
           }
           else
           {
               continue;
           }*/
         $out .= $this->outputField($p->id);
         $out .= $this->outputField($p->parent_id);
         $out .= $this->outputField($p->model);
         $out .= $this->outputField($p->warehouse_location);
         $out .= $this->outputField($p->title);
         $out .= $this->outputField($p->company->title);
         $out .= $this->outputField($statuses[$p->product_status_id]);
         $noteString = '';
         foreach ($p->expSimpleNote as $note) {
             $noteString .= "(" . $note->name . " - " . date('M d Y H:i A', $note->created_at) . ") " . $note->body . "||";
         }
         $out .= $this->outputField($noteString, '') . chr(13) . chr(10);
         $cps = $baseProd->find('all', 'parent_id=' . $p->id, null, null, null, true, true, $except, true);
         foreach ($cps as $cp) {
             $out .= $this->outputField($cp->id);
             $out .= $this->outputField($cp->parent_id);
             $out .= $this->outputField($cp->model);
             $out .= $this->outputField($cp->warehouse_location);
             $out .= $this->outputField($cp->title);
             $out .= $this->outputField($cp->company->title);
             $out .= $this->outputField($statuses[$cp->product_status_id]);
             $noteString = '';
             foreach ($cp->expSimpleNote as $note) {
                 $noteString .= "(" . $note->name . " - " . date('M d Y H:i A', $note->created_at) . ") " . $note->body . "||";
             }
             $out .= $this->outputField($noteString, '') . chr(13) . chr(10);
         }
     }
     //eDebug($out,true);
     $outFile = 'tmp/product_export_' . time() . '.csv';
     $outHandle = fopen(BASE . $outFile, 'w');
     fwrite($outHandle, $out);
     fclose($outHandle);
     echo "<br/><br/>Download the file here: <a href='" . PATH_RELATIVE . $outFile . "'>Product Export</a>";
     /*eDebug(BASE . "tmp/export.csv");
       $db->sql($sql);
       eDebug($db->error());*/
     /*OPTIONALLY ENCLOSED BY '" . '"' . 
       "' ESCAPED BY '\\'
       LINES TERMINATED BY '" . '\\n' .
       "' */
 }
Example #11
0
     }
 } else {
     //store ranks frome the depth we're moving from.  Used to re-rank the level depth the moving section is moving from.
     $oldRank = $moveSec->rank;
     $oldParent = $moveSec->parent;
     //select all children of the target sections parent with a rank higher than it's own
     $moveNextSiblings = $db->selectObjects("section", "parent=" . $targSec->parent . " AND rank>" . $targSec->rank . " ORDER BY rank");
     //update moving sections rank and parent
     $moveSec->rank = $targSec->rank + 1;
     $moveSec->parent = $targSec->parent;
     eDebug($targSec);
     eDebug($moveSec);
     //$rerank=$moveSec->rank+1;
     foreach ($moveNextSiblings as $value) {
         $value->rank = $value->rank + 1;
         eDebug($value);
         $db->updateObject($value, 'section');
     }
     $db->updateObject($moveSec, 'section');
     //handle re-ranking of previous parent
     $oldSiblings = $db->selectObjects("section", "parent=" . $oldParent . " AND rank>" . $oldRank . " ORDER BY rank");
     $rerank = 0;
     foreach ($oldSiblings as $value) {
         if ($value->id != $moveSec->id) {
             $value->rank = $rerank;
             $db->updateObject($value, 'section');
             $rerank++;
         }
     }
     if ($oldParent != $moveSec->parent) {
         //we need to re-rank the children of the parent that the miving section has just left
 function export()
 {
     eDebug($this->params);
 }