public function saveShippingMethods() { global $order; $shipping = new shipping(); $order->shippingmethods = array(); // if they didn't fill out anything if (empty($this->params['methods'])) { expValidator::failAndReturnToForm(gt("You did not pick any shipping options"), $this->params); } // if they don't check all the radio buttons if (count($this->params['methods']) < count($this->params['calcs'])) { expValidator::failAndReturnToForm(gt("You must select a shipping options for all of your packages."), $this->params); } foreach ($this->params['methods'] as $id => $method) { $cost = $this->params['cost'][$method]; $title = $this->params['title'][$method]; $shippingmethod = new shippingmethod($id); $shippingmethod->update(array('option' => $method, 'option_title' => $title, 'shipping_cost' => $cost, 'shippingcalculator_id' => $this->params['calcs'][$id])); $order->shippingmethods[] = $shippingmethod->id; } 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; }