Solution Technologies
Управление сайтом без ограничений
<?php
/**
 * XS2:
 *
 * This file is developed by Solutecs, LLC for the purpose of the company
 * and is provided together with XS2 Framework as and inherent part of the
 * system. This file can be used on the terms of License Agreement.
 *
 * +7 (495) 585-0833 / 13 Rusakovskaya street, Moscow 107140 Russia
 *
 * @link http://www.solutecs.com
 * @copyright ©1998-2007 Solutecs, LLC
 * @package XS2-MODCOM
 * @subpackage proc-shop
 * @version 1.XX
 */



session_start();

$basket = $_SESSION['basket'] ? $_SESSION['basket'] : array();
$_HTML->assign('errors', array());

$total = 0;
if(count($basket)) {
  $items = xs2GetNodes(array('NType'=>'item',
                             'condition'=>'NodId in ('.join(',', array_keys($basket)).')'));

  foreach($items as $key=>$item) {
    $sum = $basket[$item['NodId']]*$item['Price'];
    $items[$key]['_sum'] = $sum;
    $items[$key]['_count'] = $basket[$item['NodId']];
    $total += $sum;
  }

  if($_POST['action']) {
    $ok = true;

    if(!$_POST['NName']) {
      $ok = false;
      $_HTML->append('errors', 'Не указано имя');
    }
    if(!$_POST['Phone']) {
      $ok = false;
      $_HTML->append('errors', 'Не указан телефон');
    }

    if($ok) {
      $dir = xs2GetNodes(array('NType'=>'orders'));
      // Список заказов
      if($dir) {
        unset($_POST['action']);
        $order = $_POST;
        $order['Total'] = $total;
        $order['NFlag'] = 1;
        $order['ParId'] = $dir[0]['NodId'];
        $order['NType'] = 'order';
        $id = xs2InsertNode($order);
        if($id) {
          foreach($items as $key=>$item) {
            // Строки заказа
            $order_string = array('NType'=>'order_string',
                                  'ParId'=> $id,
                                  'NFlag'=>1,
                                  'item'=> array($item['NodId']),
                                  'NName'=> $item['NName'],
                                  'Count'=> $item['_count'],
                                  'Price'=> $item['Price'],
                                  'Amount'=> $item['_sum']);
            xs2InsertNode($order_string);
          }
          $_HTML->assign('orderId', $id);
          unset($_SESSION['basket']); // Очищаем сессию (корзину) после сделанного заказа

          if($dir[0]['Email']) {
          	// Уведомление администратору магазина
            $node = xs2GetNode(array('NodId'=> $id));
            $subject = 'Новый заказ в магазине';
            $_HTML->assign('node', $node);
            $_HTML->assign('items', $items);
            $message = xs2Fetch(array('mod'=> $_THE['QUE']['MOD'],
                                      'obj'=> $_THE['QUE']['OBJ'],
                                      'met'=>'email'));
            $headers =
                "MIME-Version: 1.0\r\n".
                "Content-type: text/html; charset=windows-1251\r\n".
                "From: robot@" . $_THE['PRJ']['Domain'] . "\r\n";
            mail($dir[0]['Email'], $subject, $message, $headers);
          }
        }
        else {
          $_HTML->append('errors', 'Не получилось создать заказ');
        }
      }
      else {
        $_HTML->append('errors', 'Ошибка при сохранении заказа');
      }
    }
  }
}
else {
  $_HTML->append('errors', 'Корзина пуста');
}

?>
Copyright ©1998-2008 Солютекс. Все права защищены.
Этот сайт сделан в designLab | Работает на технологии XS2
Условия использования | О защите конфиденциальности