$tpl->Assign('SavedContragent', $SavedContragent->fields); $tpl->Assign('DeliveryMethod', $DeliveryMethod->list); $tpl->Assign('SavedDeliveryMethod', $SavedDeliveryMethod->fields); if (isset($_POST['apply'])) { require_once $GLOBALS['PATH_block'] . 't_fnc.php'; // для ф-ции проверки формы $nocheck[] = 'keystring'; if (isset($_POST['passwd']) && $_POST['passwd'] == '') { $nocheck[] = 'passwdconfirm'; $nocheck[] = 'passwd'; } list($err, $errm) = Register_form_validate($nocheck); if (!$err) { $tpl->Assign('msg', 'Информация обновлена.'); $User->updateUser($_POST); $Customer->updateCustomer($_POST); $Customer->updateContPerson($_POST['cont_person']); $Customer->updatePhones($_POST['phones']); $Customer->updateContragent($_POST['id_manager']); $Customer->updateCity($_POST['id_delivery_department']); $Customer->updateDelivery($_POST['id_delivery']); if (!$Customer->fields['bonus_card']) { $Customer->registerBonus($_POST); } else { $Customer->updateBonus($_POST['bonus_card']); } header("Location: " . _base_url . "/cabinet"); } else { // показываем все заново но с сообщениями об ошибках $tpl->Assign('msg', 'Информация не обновлена.'); $tpl->Assign('errm', $errm);
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; }
$err = 1; $errm['email'] = 'Пользователь с таким email уже зарегистрирован!'; } } if ($unique_phone !== true) { $err = 1; $errm['phone'] = 'Пользователь с таким номером телефона уже зарегистрирован!'; } if (!$err) { $Customers = new Customers(); $_POST['cont_person'] = (isset($_POST['first_name']) ? trim($_POST['first_name']) : null) . ' ' . (isset($_POST['middle_name']) ? trim($_POST['middle_name']) : null) . ' ' . (isset($_POST['last_name']) ? trim($_POST['last_name']) : null); //Перезаписываем данные в сессии $_SESSION['member']['name'] = $_POST['cont_person']; $_SESSION['member']['email'] = $_POST['email']; $_SESSION['member']['phone'] = $_POST['phone']; if ($Customers->updateCustomer($_POST) && $Users->UpdateUser($_POST)) { echo json_encode('true'); } if (isset($_POST['avatar'])) { $old_path = $GLOBALS['PATH_global_root'] . $_POST['avatar']; $new_path = $GLOBALS['PATH_global_root'] . 'images/avatars/' . $_SESSION['member']['id_user'] . '.jpeg'; if (copy($old_path, $new_path)) { unlink($old_path); } } } else { echo json_encode($errm); } break; case 'AccessCode': $Users = new Users();