예제 #1
0
    $current_user = $User->fields;
    $tpl->Assign('User', $User->fields);
}
unset($parsed_res);
$Page = new Page();
$Page->PagesList();
$tpl->Assign('list_menu', $Page->list);
$GLOBALS['IERA_LINKS'] = array();
$GLOBALS['IERA_LINKS'][1]['title'] = "Корзина";
if ($User->fields['gid'] == _ACL_CUSTOMER_ || $User->fields['gid'] == _ACL_ANONYMOUS_ || $User->fields['gid'] == _ACL_DILER_ || $User->fields['gid'] == _ACL_CONTRAGENT_) {
    $Customer = new Customers();
    $Customer->SetFieldsById($User->fields['id_user']);
    $SavedCity = new Citys();
    $SavedCity->GetSavedFields($Customer->fields['id_city']);
    $SavedContragent = new Contragents();
    $SavedContragent->GetSavedFields($Customer->fields['id_contragent']);
    $DeliveryMethod = new Delivery();
    $DeliveryMethod->SetDeliveryList();
    $SavedDeliveryMethod = new Delivery();
    $SavedDeliveryMethod->GetSavedFields($Customer->fields['id_delivery']);
    $Cart = new Cart();
    if (isset($GLOBALS['REQAR'][1]) && is_numeric($GLOBALS['REQAR'][1])) {
        if (isset($_POST['add_order'])) {
            $Cart->FillByOrderId($GLOBALS['REQAR'][1], true);
        } else {
            $Cart->FillByOrderId($GLOBALS['REQAR'][1]);
        }
        header('Location: ' . _base_url . '/cart/');
    } elseif (isset($GLOBALS['REQAR'][1]) && $GLOBALS['REQAR'][1] == 'clear') {
        unset($_SESSION['Cart']);
    }
예제 #2
0
파일: cart.php 프로젝트: Arikito/webking.xt
 if (isset($customer['id_city']) && $customer['id_city'] > 0) {
     $Cities->GetSavedFields($customer['id_city']);
     $saved['city'] = $Cities->fields;
 } else {
     $saved['city'] = false;
 }
 // способы доставки
 if (isset($customer['id_delivery']) && $customer['id_delivery'] > 0) {
     $Delivery->GetSavedFields($customer['id_delivery']);
     $saved['deliverymethod'] = $Delivery->fields;
 } else {
     $saved['deliverymethod'] = false;
 }
 // сохраненный менеджер
 if (isset($customer['id_contragent']) && $customer['id_contragent'] > 0) {
     $Contragents->GetSavedFields($customer['id_contragent']);
     $saved['manager'] = $Contragents->fields;
 } else {
     $saved['manager'] = false;
 }
 // временнный менеджер
 $tempmanager = false;
 $_POST['tempmanager'] = 1;
 if ($managers_list) {
     foreach ($managers_list as $am) {
         if (!$saved['manager'] || $saved['manager']['id_user'] == $am['id_user']) {
             $_POST['tempmanager'] = 0;
         }
     }
     if ($_POST['tempmanager'] == 1) {
         $tempmanager = $managers_list[array_rand($managers_list)];
예제 #3
0
 public function Add($arr = null)
 {
     global $Cart;
     global $Products;
     global $Users;
     if (isset($arr)) {
         $GetCartForPromo = $Cart->GetCartForPromo($arr);
         $OrderCart = array();
         foreach ($GetCartForPromo['products'] as $k => $v) {
             $OrderCart[$v['id_product']] = $v;
         }
         //unset($GetCartForPromo);
         $jo_order = 1;
     }
     $OrderCart = $arr === null ? $_SESSION['cart']['products'] : $OrderCart;
     // Если список товаров в корзине пуст
     if (empty($OrderCart)) {
         print_r('products error');
         return false;
     }
     if (isset($_SESSION['cart']['promo']) && substr($_SESSION['cart']['promo'], 0, 2) == 'AG') {
         if (!$Users->SubscribeAgentUser($_SESSION['member']['id_user'], substr($_SESSION['cart']['promo'], 2))) {
             print_r('agent subscription error');
             return false;
         }
     }
     // $discount = 0;
     // if(isset($_SESSION['cart']['discount'])){
     // 	if(isset($_SESSION['price_mode']) && $_SESSION['price_mode'] == 1){
     // 		$discount = 1;
     // 	}else{
     // 		$discount = $_SESSION['cart']['discount'];
     // 	}
     // }
     // $this->UpdateSuppliersTurn();
     // Пересмотреть проверку актуальности цен
     // $Cart->IsActualPrices($err, $warn, $errm, $warnings);
     // if($err){
     // 	if(isset($_SESSION['errm'])){
     // 		$_SESSION['errm'] = array_merge($_SESSION['errm'], $errm);
     // 	}else{
     // 		$_SESSION['errm'] = $errm;
     // 		header('Location: '._base_url.'/cart/');
     // 		exit();
     // 	}
     // }
     // isset($_SESSION['member']['id_user']) ? $_SESSION['member']['id_user'] : $_SESSION['member']['id_user'] = $_POST['id_user'];
     // isset($arr['discount']) ? $arr['discount']  : $arr['discount'] = 0;
     // Определяем статус будущего заказа
     $order_status = 0;
     // Если у клиента есть промо-код - 11
     if (isset($_SESSION['cart']['promo_code']) && $_SESSION['cart']['promo_code'] != '') {
         // Написать проверку промо-кода
         $f['id_order_status'] = $order_status = 11;
         // Промо-заказ
     } else {
         $f['id_order_status'] = $order_status = 1;
         // Обычный заказ
     }
     // Сохраняем номер заказа, на основании которого был создан текущщий
     if (isset($_SESSION['cart']['base_order'])) {
         $f['base_order'] = $_SESSION['cart']['base_order'];
     }
     $f['target_date'] = $target_date = strtotime('+2 day', time());
     $f['creation_date'] = time();
     $f['id_customer'] = isset($_SESSION['cart']['id_customer']) ? $_SESSION['cart']['id_customer'] : $_SESSION['member']['id_user'];
     $Customers = new Customers();
     $Customers->SetFieldsById($f['id_customer']);
     $customer = $Customers->fields;
     // Определяем адрес по-умолчанию
     $Address = new Address();
     if ($customer_address = $Address->GetPrimaryAddress($f['id_customer'])) {
         $_SESSION['member']['id_address'] = $f['id_addrress'] = $customer_address['id'];
     }
     // Обновляем контрагента у покупателя
     if (isset($_SESSION['cart']['id_contragent'])) {
         $array['id_contragent'] = $_SESSION['cart']['id_contragent'];
         if ($_SESSION['member']['gid'] == _ACL_CUSTOMER_) {
             $_SESSION['member']['contragent']['id_user'] = $_SESSION['cart']['id_contragent'];
             $array['id_user'] = $_SESSION['member']['id_user'];
         } elseif ($_SESSION['member']['gid'] == _ACL_CONTRAGENT_ && !empty($_SESSION['cart']['id_customer'])) {
             $array['id_user'] = $_SESSION['cart']['id_customer'];
         }
     } elseif ($_SESSION['member']['gid'] == _ACL_CONTRAGENT_ && !empty($_SESSION['cart']['id_customer'])) {
         $array['id_contragent'] = $_SESSION['member']['id_user'];
         $array['id_user'] = $_SESSION['cart']['id_customer'];
     }
     if (isset($array['id_user'])) {
         $Customers->updateCustomer($array);
     }
     // Определяем контрагента
     if (isset($_SESSION['cart']['id_contragent'])) {
         $id_contragent = $_SESSION['cart']['id_contragent'];
     } else {
         if ($_SESSION['member']['gid'] == _ACL_CONTRAGENT_) {
             $id_contragent = $_SESSION['member']['id_user'];
         } else {
             //Определяем выходной или рабочий день у контрагента
             $date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 2, date("Y")));
             $sql = "SELECT work_day FROM " . _DB_PREFIX_ . "calendar_contragent\r\n\t\t\t\t\tWHERE id_contragent = " . $customer['id_contragent'] . " AND date = '" . $date . "'";
             $res = $this->db->GetOneRowArray($sql);
             if ($res['work_day'] != 1) {
                 //рандомный выбор контрагента
                 $contragents = new Contragents();
                 $contragents->SetList();
                 $id_contragent = $contragents->list[array_rand($contragents->list)]['id_user'];
             } else {
                 $id_contragent = $customer['id_contragent'];
             }
         }
     }
     if (isset($_SESSION['cart']['promo']) && $_SESSION['cart']['promo'] != '') {
         $f['promo_code'] = $_SESSION['cart']['promo'];
     }
     $f['id_contragent'] = $id_contragent;
     if (isset($customer['bonus_card']) && $customer['bonus_card'] != '') {
         $f['bonus_card'] = $customer['bonus_card'];
     }
     $cart_column = isset($_SESSION['cart']['manual_price_change']) ? $_SESSION['cart']['manual_price_change'] : $_SESSION['cart']['cart_column'];
     $f['sum_opt'] = $f['sum_mopt'] = $f['sum'] = $f['sum_discount'] = !isset($jo_order) ? $_SESSION['cart']['products_sum'][$cart_column] : $GetCartForPromo['total_sum'];
     $f['phones'] = $customer['phones'];
     $f['cont_person'] = isset($arr['cont_person']) ? trim($arr['cont_person']) : $customer['cont_person'];
     $f['skey'] = md5(time() . 'jWfUsd');
     $f['sid'] = 1;
     $f['note'] = isset($_SESSION['cart']['note']) ? $_SESSION['cart']['note'] : null;
     if (isset($_SESSION['cart']['manual_price_change']) && isset($_SESSION['cart']['manual_price_change_note'])) {
         $f['manual_price_change'] = $_SESSION['cart']['manual_price_change'] . ' - ' . $_SESSION['cart']['manual_price_change_note'];
     }
     $this->db->StartTrans();
     if (!$this->db->Insert(_DB_PREFIX_ . 'order', $f)) {
         $this->db->FailTrans();
         print_r('order insert error');
         return false;
     }
     // Получаем id нового заказа
     $id_order = $this->db->GetLastId();
     if (isset($jo_order)) {
         $GetCartForPromo['id_order'] = $id_order;
     } else {
         $_SESSION['cart']['id_order'] = $id_order;
     }
     if (isset($_SESSION['cart']['id'])) {
         $sql = "UPDATE " . _DB_PREFIX_ . "cart\r\n\t\t\t\tSET id_order = " . $id_order . "\r\n\t\t\t\tWHERE id_cart = " . $_SESSION['cart']['id'];
     }
     if (!$this->db->Query($sql)) {
         $this->db->FailTrans();
         return false;
     }
     unset($f);
     // Заполнение связки заказ-товары
     $Suppliers = new Suppliers();
     $order_otpusk_prices_sum = $ii = $sup_nb = 0;
     foreach ($OrderCart as $id_product => $item) {
         // Определяем поставщика для товара
         if ($id_supplier = $this->GetSupplierForProduct($id_product, $item['mode'])) {
             $p[$ii]['id_order'] = $id_order;
             $p[$ii]['id_product'] = $id_product;
             if ($item['mode'] == 'opt') {
                 $p[$ii]['id_supplier'] = $id_supplier;
             } else {
                 $p[$ii]['id_supplier_' . $item['mode']] = $id_supplier;
             }
             $p[$ii]['price_' . $item['mode'] . '_otpusk'] = $Suppliers->GetPriceOtpusk($id_supplier, $id_product, $item['mode']);
             $order_otpusk_prices_sum += round($p[$ii]['price_' . $item['mode'] . '_otpusk'] * $item['quantity'], 2);
             $sup_nb++;
             $Products->SetFieldsById($id_product);
             $product = $Products->fields;
             $p[$ii]['box_qty'] = $item['quantity'] / $product['inbox_qty'];
             $p[$ii][$item['mode'] . '_qty'] = $item['quantity'];
             $p[$ii]['note'] = $item['note'];
             $p[$ii]['default_sum_' . $item['mode']] = !isset($jo_order) ? $item['summary'][$cart_column] : $item['sum_prod'];
             if ($item['mode'] == 'opt') {
                 $p[$ii]['mopt_qty'] = 0;
                 $p[$ii]['note_mopt'] = '';
                 $p[$ii]['default_sum_mopt'] = 0;
                 $p[$ii]['id_supplier_mopt'] = 0;
                 $p[$ii]['price_mopt_otpusk'] = 0;
             } else {
                 $p[$ii]['opt_qty'] = 0;
                 $p[$ii]['note_opt'] = '';
                 $p[$ii]['default_sum_opt'] = 0;
                 $p[$ii]['id_supplier'] = 0;
                 $p[$ii]['price_opt_otpusk'] = 0;
             }
             $p[$ii][$item['mode'] . '_sum'] = !isset($jo_order) ? $item['summary'][$cart_column] : $item['sum_prod'];
             $p[$ii]['site_price_' . $item['mode']] = !isset($jo_order) ? $item['actual_prices'][$cart_column] : $item['price'];
             if ($item['mode'] == 'opt') {
                 $p[$ii]['mopt_sum'] = 0;
                 $p[$ii]['site_price_mopt'] = 0;
             } else {
                 $p[$ii]['opt_sum'] = 0;
                 $p[$ii]['site_price_opt'] = 0;
             }
             $p[$ii]['gift'] = 0;
         }
         $ii++;
     }
     if (isset($_SESSION['cart']['id_gift']) && ($id_supplier = $this->GetSupplierForProduct($_SESSION['cart']['id_gift'], 'mopt'))) {
         $p[$ii]['id_order'] = $id_order;
         $p[$ii]['id_product'] = $_SESSION['cart']['id_gift'];
         $p[$ii]['id_supplier_mopt'] = $id_supplier;
         $p[$ii]['price_mopt_otpusk'] = $Suppliers->GetPriceOtpusk($id_supplier, $_SESSION['cart']['id_gift'], 'mopt');
         $order_otpusk_prices_sum += 0.01;
         $sup_nb++;
         $Products->SetFieldsById($_SESSION['cart']['id_gift']);
         $product = $Products->fields;
         $p[$ii]['box_qty'] = 1 / $product['inbox_qty'];
         $p[$ii]['mopt_qty'] = 1;
         $p[$ii]['note'] = 'Подарок!';
         $p[$ii]['default_sum_mopt'] = '0.01';
         $p[$ii]['opt_qty'] = 0;
         $p[$ii]['note_opt'] = '';
         $p[$ii]['default_sum_opt'] = 0;
         $p[$ii]['id_supplier'] = 0;
         $p[$ii]['price_opt_otpusk'] = 0;
         $p[$ii]['mopt_sum'] = '0.01';
         $p[$ii]['site_price_mopt'] = '0.01';
         $p[$ii]['opt_sum'] = 0;
         $p[$ii]['site_price_opt'] = 0;
         $p[$ii]['gift'] = 1;
     }
     // Если ни у одного товара нет поставщика
     if ($sup_nb == 0) {
         $_SESSION['errm']['limit'] = "Невозможно сформировать заказ. Недостаточное количество одного или нескольких товаров на складе. Остаток недостающего товара отображен в поле названия товара.";
         print_r('sup_nb error');
         return false;
     }
     if (empty($p) || !$this->db->InsertArr(_DB_PREFIX_ . 'osp', $p)) {
         $this->db->FailTrans();
         print_r('osp insert error');
         return false;
     }
     // Сохранить сумму заказа по отпускным ценам
     $sql = "UPDATE " . _DB_PREFIX_ . "order\r\n\t\t\tSET otpusk_prices_sum = " . round($order_otpusk_prices_sum, 2) . "\r\n\t\t\tWHERE id_order = " . $id_order;
     if (!$this->db->Query($sql)) {
         $this->db->FailTrans();
         print_r('order update error');
         return false;
     }
     $this->db->CompleteTrans();
     unset($p);
     if ($order_status == 1 && $_SESSION['member']['gid'] == _ACL_CUSTOMER_) {
         $Mailer = new Mailer();
         $Mailer->SendOrderInvoicesToCustomers($id_order);
         $Users->SetFieldsById($_SESSION['member']['id_user']);
         $Gateway = new APISMS($GLOBALS['CONFIG']['sms_key_private'], $GLOBALS['CONFIG']['sms_key_public'], 'http://atompark.com/api/sms/', false);
         $Contragents = new Contragents();
         $string = $Contragents->GetSavedFields($id_contragent);
         $manager2send = $string['name_c'] . ' ' . preg_replace("/[,]/i", ", ", preg_replace("/[a-z\\(\\)\\-\\040]/i", "", $string['phones']));
         //			 if($Users->fields['phone'] != '' ){
         //				$Gateway->execCommad(
         //					'sendSMS',
         //					array(
         //						'sender' => $GLOBALS['CONFIG']['invoice_logo_sms'],
         //						'text' => 'Заказ № '.$id_order.' принят. Ваш менеджер '.$manager2send,
         //						'phone' => $Users->fields['phone'],
         //						'datetime' => null,
         //						'sms_lifetime' => 0
         //					)
         //				);
         //			 }
     }
     if (isset($_SESSION['member']['gid']) && $_SESSION['member']['gid'] == _ACL_CONTRAGENT_) {
         unset($_SESSION['cart']['base_order'], $_SESSION['cart']['id_customer'], $_SESSION['member']['bonus']);
     }
     if (isset($_SESSION['cart']['promo'])) {
         unset($_SESSION['cart']['promo']);
     }
     if (isset($_SESSION['cart']['id_gift'])) {
         unset($_SESSION['cart']['id_gift']);
     }
     if (isset($_SESSION['cart']['note'])) {
         unset($_SESSION['cart']['note']);
     }
     if (isset($_SESSION['cart']['id_contragent'])) {
         unset($_SESSION['cart']['id_contragent']);
     }
     if (isset($_SESSION['cart']['manual_price_change'])) {
         unset($_SESSION['cart']['manual_price_change']);
     }
     if (isset($_SESSION['cart']['manual_price_change_note'])) {
         unset($_SESSION['cart']['manual_price_change_note']);
     }
     return $id_order;
 }
예제 #4
0
$Contragents = new Contragents();
$Products = new Products();
$News = new News();
$Cart = new Cart();
if (isset($_SESSION['member'])) {
    $Users->SetUser($_SESSION['member']);
    if (isset($_SESSION['member']['email']) && $_SESSION['member']['email'] != 'anonymous') {
        $GLOBALS['user'] = $Users->fields;
    }
}
$Customers->SetFieldsById($Users->fields['id_user']);
// список всех менеджеров
$Contragents->SetList();
$tpl->Assign('managers_list', $Contragents->list);
if (!isset($_SESSION['member']['promo_code']) || $_SESSION['member']['promo_code'] == '') {
    $Contragents->GetSavedFields($Customers->fields['id_contragent']);
    $tpl->Assign('SavedContragent', $Contragents->fields);
} else {
    $Suppliers = new Suppliers();
    $Suppliers->GetSupplierIdByPromoCode($_SESSION['member']['promo_code']);
    $tpl->Assign('promo_supplier', $Suppliers->fields);
    unset($Suppliers);
}
// Выборка просмотренных товаров
if (isset($_COOKIE['view_products'])) {
    foreach (json_decode($_COOKIE['view_products']) as $value) {
        $Products->SetFieldsById($value, 1, 1);
        $product = $Products->fields;
        if (isset($product['id_product']) && $product['id_product'] != '') {
            $product['images'] = $Products->GetPhotoById($product['id_product']);
        }