public function indexAction() { // Seo $this->_seo['h1'] = 'Корзина'; $this->_seo['title'] = 'Корзина'; $this->_seo['keywords'] = 'Корзина'; $this->_seo['description'] = 'Корзина'; // Get cart items $cart = C::factory()->get_list_for_basket(); // Render template $this->_content = View::tpl(array('cart' => $cart, 'payment' => Config::get('order.payment'), 'delivery' => Config::get('order.delivery')), 'Cart/Index'); }
public function deleteItemFromCartAction() { // Get and check incoming data $catalog_id = Arr::get($_POST, 'id', 0); if (!$catalog_id) { $this->error('No such item!'); } $size_id = (int) Arr::get($_POST, 'size', 0); // Add one item to cart Cart::factory()->delete($catalog_id, $size_id); $this->success(array('count' => (int) Cart::factory()->_count_goods)); }
public function hiddenData($array = array()) { $cart = Cart::factory()->get_list_for_basket(); return $this->_data['hiddenData'] = View::widget(array('cart' => $cart), 'HiddenData'); }
public function checkoutAction() { // Check incomming data $payment = Arr::get($this->post, 'payment'); if (!$payment) { $this->error('Выберите способ оплаты!'); } $delivery = Arr::get($this->post, 'delivery'); if (!$delivery) { $this->error('Выберите способ доставки!'); } $number = Arr::get($this->post, 'number'); if ($delivery == 2 and !$number) { $this->error('Укажите на какое отделение Новой почты везти товар!'); } $name = Arr::get($this->post, 'name'); if (!$name or mb_strlen($name, 'UTF-8') < 2) { $this->error('Укажите ФИО получателя!'); } $phone = trim(Arr::get($this->post, 'phone')); if (!$phone or !preg_match('/^\\+38 \\(\\d{3}\\) \\d{3}\\-\\d{2}\\-\\d{2}$/', $phone, $matches)) { $this->error('Номер телефона введен неверно!'); } // Check for bot $ip = System::getRealIP(); $check = DB::select(array(DB::expr('COUNT(orders.id)'), 'count'))->from('orders')->where('ip', '=', $ip)->where('created_at', '>', time() - 30)->as_object()->execute()->current(); // if( is_object($check) AND $check->count ) { // $this->error('Вы только что оформили заказ! Пожалуйста, повторите попытку через несколько секунд'); // } // Check for cart existance $count = Cart::factory()->_count_goods; if (!$count) { $this->error('Вы ничего не выбрали для покупки!'); } // Create order $data = array(); $data['status'] = 0; $data['ip'] = $ip; $data['payment'] = $payment; $data['delivery'] = $delivery; $data['number'] = $delivery == 2 ? $number : ''; $data['name'] = $name; $data['phone'] = $phone; $data['created_at'] = time(); if (User::info()) { $data['user_id'] = User::info()->id; } $keys = array(); $values = array(); foreach ($data as $key => $value) { $keys[] = $key; $values[] = Text::xssClean($value); } $order_id = DB::insert('orders', $keys)->values($values)->execute(); if (!$order_id) { $this->error('К сожалению, создать заказ не удалось. Пожалуйста повторите попытку через несколько секунд'); } $order_id = Arr::get($order_id, 0); // Add items to order $cart = Cart::factory()->get_list_for_basket(); foreach ($cart as $item) { $obj = Arr::get($item, 'obj'); $count = (int) Arr::get($item, 'count'); $size_id = (int) Arr::get($item, 'size'); if ($obj and $count) { $data = array(); $data['order_id'] = $order_id; $data['catalog_id'] = $obj->id; $data['size_id'] = $size_id; $data['count'] = $count; $data['cost'] = $obj->cost; $keys = array(); $values = array(); foreach ($data as $key => $value) { $keys[] = $key; $values[] = $value; } DB::insert('orders_items', $keys)->values($values)->execute(); } } // Create links $link_user = '******' . Arr::get($_SERVER, 'HTTP_HOST') . '/user/orders/id/' . $order_id; $link_admin = 'http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/backend/orders/new/id/' . $order_id; // Save log $qName = 'Новый заказ'; $url = '/backend/orders/edit/' . $order_id; Log::add($qName, $url, 8); // Get lists of delivery and payment from config file /config/order.php $d = conf::get('order.delivery'); $p = conf::get('order.payment'); // Send message to admin if need $mail = DB::select()->from('mail_templates')->where('id', '=', 11)->where('status', '=', 1)->as_object()->execute()->current(); if ($mail) { $from = array('{{site}}', '{{ip}}', '{{date}}', '{{name}}', '{{phone}}', '{{payment}}', '{{delivery}}', '{{admin_link}}', '{{user_link}}', '{{items}}'); $to = array(Arr::get($_SERVER, 'HTTP_HOST'), $ip, date('d.m.Y H:i'), $name, $phone, $p[$payment], $d[$delivery] . ($delivery == 2 ? ', ' . $number : ''), $link_admin, $link_user, View::tpl(array('cart' => $cart), 'Cart/ItemsMail')); $subject = str_replace($from, $to, $mail->subject); $text = str_replace($from, $to, $mail->text); Email::send($subject, $text); } // Send message to user if need and logged in if (User::info() and User::info()->email) { $mail = DB::select()->from('mail_templates')->where('id', '=', 12)->where('status', '=', 1)->as_object()->execute()->current(); if ($mail) { $from = array('{{site}}', '{{ip}}', '{{date}}', '{{name}}', '{{phone}}', '{{payment}}', '{{delivery}}', '{{admin_link}}', '{{user_link}}', '{{items}}'); $to = array(Arr::get($_SERVER, 'HTTP_HOST'), $ip, date('d.m.Y H:i'), $name, $phone, $p[$payment], $d[$delivery] . ($delivery == 2 ? ', ' . $number : ''), $link_admin, $link_user, View::tpl(array('cart' => $cart), 'Cart/ItemsMail')); $subject = str_replace($from, $to, $mail->subject); $text = str_replace($from, $to, $mail->text); Email::send($subject, $text, User::info()->email); } } // Clear cart Cart::factory()->clear(); // Set message and reload page Message::GetMessage(1, 'Вы успешно оформили заказ! Спасибо за то что вы с нами'); $this->success(array('redirect' => User::info() ? $link_user : '******')); }