function createaddress() { global $db, $user; if ($user->isLoggedIn()) { // save the address, make it default if it is the users first one $address = new address(); $count = $address->find('count', 'user_id=' . $user->id); if ($count == 0) { $this->params['is_default'] = 1; } $this->params['user_id'] = $user->id; $address->update($this->params); // set the billing/shipping method if (isset($this->params['addresstype'])) { if ($this->params['addresstype'] == 'shipping') { $shipping = new shipping(); $shipping->shippingmethod->setAddress($address); } elseif ($this->params['addresstype'] == 'billing') { $billing = new billing(); $billing->billingmethod->setAddress($address); } } } redirect_to(array('controller' => 'cart', 'action' => 'checkout')); }
public function getForcedShippingMethod() { global $db, $user; $forced_calc = ''; $forced_method = ''; foreach ($this->orderitem as $item) { if (!empty($item->product->required_shipping_method)) { $method = new shippingmethod($item->shippingmethods_id); $forced_calc = $item->product->required_shipping_calculator_id; $forced_method = $item->product->required_shipping_method; $this->forced_shipping = true; $this->product_forcing_shipping = $item->product; $this->forcing_shipping_reason = $item->product->title; break; } } #FJD - TODOD: this will require some more work; eg. combining a free shipping discount code with a #product in the cart that is also forcing shipping. He coupon could require the lowest shipping #method, but the product could require overnight or a high-end shipping, so we need to account for this //check discounts requiring forced shipping if ($forced_calc == '') { $o = new order_discounts(); $ods = $o->find('all', 'orders_id=' . $this->id); foreach ($ods as $od) { if ($od->requiresForcedShipping()) { $method = new shippingmethod($this->orderitem[0]->shippingmethods_id); $forced_calc = $od->getRequiredShippingCalculatorId(); $forced_method = $od->getRequiredShippingMethod(); $this->forced_shipping = true; $this->forcing_shipping_reason = gt('The discount code you are using'); break; } } } ################### // 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($method->addresses_id) && $user->isLoggedIn()) { $address = new address(); $addy = $address->find('first', 'user_id=' . $user->id . ' AND is_default=1'); if (!empty($addy->id)) { $method->setAddress($addy); } } $calcname = $db->selectValue('shippingcalculator', 'calculator_name', 'id=' . $forced_calc); $calculator = new $calcname($forced_calc); $rates = $calculator->getRates($this); $rate = $rates[$forced_method]; $method->update(array('option' => $forced_method, 'option_title' => $rate['title'], 'shipping_cost' => $rate['cost'], 'shippingcalculator_id' => $forced_calc)); return $method; }
public function __construct($id = null) { global $user; // if an ID is passed in we'll look up the cart from the database...it means this is // probably a completed order an admin is looking at it via the order admin interface. //if (empty($id)) { // global $order; //} else { //$order = new order($id); //} /* // check for this users billing method object. If it hasn't been created yet then lets do it now. if (empty($order->billingmethod)) { $order->billingmethod[0] = new billingmethod(); $order->billingmethod[0]->update(array('orders_id'=>$order->id)); } */ //if (empty($order->billingmethod[0]->addresses_id) && $user->isLoggedIn()) { //if ($user->isLoggedIn()) { if ($id == null) { // since this is a new billingmethod object, lets initialize it with the users billing address. global $order; $address = new address(); //FJD $defaultaddy = $address->find('first', 'user_id='.$user->id.' AND is_default=1'); if (empty($order->billingmethod)) { $order->billingmethod[0] = new billingmethod(); $order->billingmethod[0]->update(array('orders_id' => @$order->id)); // @ added to ditch notice when ecom is off } $billingAddy = $address->find('first', 'user_id=' . $user->id . ' AND is_billing=1'); $order->billingmethod[0]->setAddress($billingAddy); } else { $order = new order($id); if (empty($order->id)) { return false; } } //} $this->address = new address($order->billingmethod[0]->addresses_id); //$this->address = new address($order->billingmethod[0]->id); $this->available_calculators = billing::listAvailableCalculators(); $this->selectable_calculators = $this->selectableCalculators(); $this->calculator_views = $this->getCalcViews(); // if there is only one available calculator we'll force it on the user // also if the user hasn't selected a calculator yet well set it to a default. $number_of_calculators = count($this->available_calculators); if ($number_of_calculators == 1 || empty($order->billingmethod[0]->billingcalculator_id)) { reset($this->available_calculators); $calcid = key($this->available_calculators); $order->billingmethod[0]->update(array('billingcalculator_id' => $calcid)); } if ($number_of_calculators > 0) { $calcname = $this->available_calculators[$order->billingmethod[0]->billingcalculator_id]; $this->calculator = new $calcname($order->billingmethod[0]->billingcalculator_id); } else { $this->calculator = null; } $this->billingmethod = $order->billingmethod[0]; $options = unserialize($this->billingmethod->billing_options); $this->info = empty($this->calculator->id) ? '' : $this->calculator->userView($options); foreach ($this->available_calculators as $key => $item) { $calc = new $item($key); $this->form[$key] = $calc->userForm(); } // eDebug($this->form, true); }
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); } } */ } }
public function viewuser() { $u = new user($this->params['id']); $address = new address(); $billings = $address->find('all', 'user_id=' . $u->id . ' AND is_billing = 1'); $shippings = $address->find('all', 'user_id=' . $u->id . ' AND is_shipping = 1'); // build out a SQL query that gets all the data we need and is sortable. $sql = 'SELECT o.*, b.firstname as firstname, b.billing_cost as total, b.middlename as middlename, b.lastname as lastname, os.title as status, ot.title as order_type '; $sql .= 'FROM ' . DB_TABLE_PREFIX . '_orders o, ' . DB_TABLE_PREFIX . '_billingmethods b, '; $sql .= DB_TABLE_PREFIX . '_order_status os, '; $sql .= DB_TABLE_PREFIX . '_order_type ot '; $sql .= 'WHERE o.id = b.orders_id AND o.order_status_id = os.id AND o.order_type_id = ot.id AND o.purchased > 0 AND user_id =' . $u->id; $limit = empty($this->config['limit']) ? 50 : $this->config['limit']; //eDebug($sql, true); $orders = new expPaginator(array('controller' => $this->params['controller'], 'action' => $this->params['action'], 'sql' => $sql, 'order' => 'purchased', 'dir' => 'DESC', 'limit' => $limit, 'columns' => array('Order #' => 'invoice_id', 'Total' => 'total', 'Date Purchased' => 'purchased', 'Type' => 'order_type_id', 'Status' => 'order_status_id', 'Ref' => 'orig_referrer'))); assign_to_template(array('u' => $u, 'billings' => $billings, 'shippings' => $shippings, 'orders' => $orders)); }
function postProcess($order, $params) { //check order types and create new user if necessary global $db, $user; $ot = new order_type($order->order_type_id); if ($ot->creates_new_user == true) { $addy = new address($order->billingmethod[0]->addresses_id); $newUser = new user(); $newUser->username = $addy->email . time(); //make a unique username $password = md5(time() . rand(50, 00)); //generate random password $newUser->setPassword($password, $password); $newUser->email = $addy->email; $newUser->firstname = $addy->firstname; $newUser->lastname = $addy->lastname; $newUser->is_system_user = false; $newUser->save(true); $newUser->refresh(); $addy->user_id = $newUser->id; $addy->is_default = true; $addy->save(); $order->user_id = $newUser->id; $order->save(); if ($order->orderitem[0]->shippingmethod->addresses_id != $addy->id) { $addy = new address($order->orderitem[0]->shippingmethod->addresses_id); $addy->user_id = $newUser->id; $addy->is_default = false; $addy->save(); } //make sure current user is good to go $defAddy = $addy->find('first', 'user_id=' . $user->id); $obj->id = $defAddy->id; $db->setUniqueFlag($obj, 'addresses', 'is_default', 'user_id=' . $user->id); $db->setUniqueFlag($obj, 'addresses', 'is_shipping', 'user_id=' . $user->id); $db->setUniqueFlag($obj, 'addresses', 'is_billing', 'user_id=' . $user->id); } return true; }