function removeDiscountFromCart($id = null, $redirect = true) { //eDebug($params); if ($id == null) { $id = $this->params['id']; } $od = new order_discounts($id); $od->delete(); flash('message', gt("The discount code has been removed from your cart")); if ($redirect == true) { //redirect_to(array('controller'=>'cart', 'action'=>'checkout')); expHistory::back(); } }
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; }