public function special_discount($data, $chk = false) { $redshopMail = new redshopMail(); $orderdata = $this->getTable('order_detail'); $orderdata->load($this->_id); $order_functions = new order_functions(); $OrderItems = $order_functions->getOrderItemDetail($this->_id); if (!$orderdata->special_discount) { $orderdata->special_discount = 0; } if (!$orderdata->special_discount_amount) { $orderdata->special_discount_amount = 0; } if ($data['special_discount'] == $orderdata->special_discount && $chk != true) { return false; } $special_discount = $data['special_discount']; $subtotal = 0; $subtotal_excl_vat = 0; for ($i = 0; $i < count($OrderItems); $i++) { if ($order_item_id != $OrderItems[$i]->order_item_id) { $subtotal_excl_vat = $subtotal_excl_vat + $OrderItems[$i]->product_item_price_excl_vat * $OrderItems[$i]->product_quantity; $subtotal = $subtotal + $OrderItems[$i]->product_item_price * $OrderItems[$i]->product_quantity; } } $discount_price = $subtotal * $special_discount / 100; $orderdata->special_discount = $special_discount; $orderdata->special_discount_amount = $discount_price; $order_total = $subtotal + $orderdata->order_shipping - $discount_price - $orderdata->order_discount; $orderdata->order_total = $order_total; $orderdata->mdate = time(); if (!$orderdata->store()) { return false; } if (ECONOMIC_INTEGRATION == 1) { $economic = new economic(); $invoiceHandle = $economic->renewInvoiceInEconomic($orderdata); } // Send mail from template $redshopMail->sendOrderSpecialDiscountMail($this->_id); return true; }