public function form() { \CI::form_validation()->set_rules('to_email', 'lang:recipient_email', 'trim|required'); \CI::form_validation()->set_rules('to_name', 'lang:recipient_name', 'trim|required'); \CI::form_validation()->set_rules('from', 'lang:sender_name', 'trim|required'); \CI::form_validation()->set_rules('personal_message', 'lang:personal_message', 'trim'); \CI::form_validation()->set_rules('beginning_amount', 'lang:amount', 'trim|required|numeric'); $data['page_title'] = lang('add_gift_card'); if (\CI::form_validation()->run() == FALSE) { $this->view('gift_card_form', $data); } else { $save['code'] = generate_code(); // from the string helper $save['to_email'] = \CI::input()->post('to_email'); $save['to_name'] = \CI::input()->post('to_name'); $save['from'] = \CI::input()->post('from'); $save['personal_message'] = \CI::input()->post('personal_message'); $save['beginning_amount'] = \CI::input()->post('beginning_amount'); \CI::GiftCards()->saveCard($save); if (\CI::input()->post('sendNotification')) { \GoCart\Emails::giftCardNotification($save); } \CI::session()->set_flashdata('message', lang('message_saved_gift_card')); redirect('admin/gift-cards'); } }
function submitOrder($transaction = false) { foreach ($this->items as $item) { if ($item->type == 'gift card') { //touch giftcard \CI::GiftCards()->updateAmountUsed($item->description, $item->total_price); continue; } elseif ($item->type == 'coupon') { //touch coupon \CI::Coupons()->touchCoupon($item->description); continue; } elseif ($item->type == 'product') { //update inventory if ($item->track_stock) { \CI::Products()->touchInventory($item->product_id, $item->quantity); } //if this is a giftcard purchase, generate it and send it where it needs to go. if ($item->is_giftcard) { //process giftcard $options = CI::Orders()->getItemOptions(GC::getCart()->id); $giftCard = []; foreach ($options[$item->id] as $option) { if ($option->option_name == 'gift_card_amount') { $giftCard[$option->option_name] = $option->price; } else { $giftCard[$option->option_name] = $option->value; } } $giftCard['code'] = generate_code(); $giftCard['activated'] = 1; //save the card \CI::GiftCards()->saveCard($giftCard); //send the gift card notification \GoCart\Emails::giftCardNotification($giftCard); } } } if (!$transaction) { $transaction = $this->transaction(); } //add transaction info to the order $this->cart->order_number = $transaction->order_number; $this->cart->transaction_id = $transaction->id; $this->cart->status = config_item('order_status'); $this->cart->ordered_on = date('Y-m-d H:i:s'); $orderNumber = $this->cart->order_number; $this->saveCart(); //refresh the cart $this->getCart(true); //get the order as it would be on the order complete page $order = \CI::Orders()->getOrder($orderNumber); //send the cart email \GoCart\Emails::Order($order); //return the order number return $orderNumber; }