public function getTotal(DiscountModel $discount) { $total = $this->base->addToPrice(0); foreach ($this->toppings as $topping) { $total += $discount->addToPrice($topping); } foreach ($this->cheeseCollection as $cheese) { $total += $discount->addToPrice($cheese); } return $total; }
public function createAction() { // Creamos una nueva categoria $discount = new DiscountModel(); $isValidDiscount = isset($this->_params['fechainicio']) && !empty($this->_params['fechainicio']) && isset($this->_params['fechafin']) && !empty($this->_params['fechafin']) && isset($this->_params['porcentaje']) && !empty($this->_params['porcentaje']); try { if ($isValidDiscount) { $discount->save(array("fechainicio" => $this->_params['fechainicio'], "fechafin" => $this->_params['fechafin'], "porcentaje" => $this->_params['porcentaje'])); return $discount->toArray(); } throw new Exception("Los parametros no son correctos", 1); } catch (Exception $e) { throw new Exception($e->getMessage(), 1); } }
private function saveOrder($jsonArray = null) { if (is_array($jsonArray) && isset($jsonArray['usr']) && isset($jsonArray['cart'])) { $order = new OrderModel(); $usr = $jsonArray['usr']; $cart = $jsonArray['cart']; // echo '<pre>';print_R($cart);die; // add checks here before saving order $order->setBfname($usr['fname']); $order->setBlname($usr['lname']); $order->setBemail($usr['email']); $order->setBaddressl1($usr['addr1']); $order->setBaddressl2($usr['addr2']); $order->setBaddressl3($usr['addr3']); $order->setBcity($usr['city']); $order->setBcountry($usr['country']); $order->setBstate($usr['state']); $order->setBzipcode($usr['zipcode']); $order->setInserttime(date("Y-m-d H:i:s")); $order->setSfname($usr['sfname']); $order->setSlname($usr['slname']); $order->setSemail($usr['semail']); $order->setSaddressl1($usr['saddr1']); $order->setSaddressl2($usr['saddr2']); $order->setSaddressl3($usr['saddr3']); $order->setScity($usr['scity']); $order->setScountry($usr['scountry']); $order->setSstate($usr['sstate']); $order->setStatus("pending"); $order->setSubtotal($cart['subTotal']); $order->setSzipcode($usr['szipcode']); $order->setDiscount($cart['discount']); $order->setTotal($cart['total']); $order->setQty($cart['qty']); $order->setOrder_type(strtoupper($usr['ordertype'])); $order->setUserid(Session::getInstance()->getSess("userid")); $order->insert(); if ($order->isSuccess() == 1) { $oid = $order->getOrderid(); foreach ($cart['items'] as $k => $itm) { $item = new OrderProdsModel(); $item->setOid($oid); $item->setTid($itm['template']); $item->setPid($itm['product']); $item->setPrice($itm['price']); $item->setQty($itm['qty']); $item->setTotal($itm['total']); $item->insert(); $this->moveTemplate($itm['template']); // converts file urls from temp dir to final destination dir } if ($cart['disId'] != 0) { $du = new DiscountUserModel(); $du->setDiscountId($cart['disId']); $du->setUserId(Session::getInstance()->getSess("userid")); $du->insert(); if ($cart['discountFor'] == 1) { $dis = new DiscountModel(); $dis->setDiscountid($cart['disId']); $dis->setStatus(1); $dis->update_status(); } } if ($usr['ordertype'] == 'cod') { $this->cod_order($oid, $usr, $cart['total']); } $oc = new OrderController(); ob_start(); $oc->printinvoice($oid); $html = ob_get_clean(); if ($usr['ordertype'] != 'payment') { Session::getInstance()->setMessage("Order accepted.", "green"); Session::getInstance()->removeSess('cart'); } mail($usr['email'], "Order Confirmation", $html, "Content-type: text/html; charset=iso-8859-1 \r\nFrom: noreply@snooky.com\r\n"); echo $oid; } else { Session::getInstance()->setMessage("Problem in accepting order, please try again.", "red"); echo "failed"; } } }