Skip to content

Instantly share code, notes, and snippets.

@cezar62882
Created December 7, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cezar62882/4025da21df3d64c32ce8 to your computer and use it in GitHub Desktop.
Save cezar62882/4025da21df3d64c32ce8 to your computer and use it in GitHub Desktop.
public function add_to_orders($fromCabinet = FALSE, $itemSum = 0)
{
try
{
$this->load->library('form_validation');
$this->form_validation->set_rules('url', 'Ссылка на товар', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('name', 'Название товара', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('color', 'Цвет', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('size', 'Размер', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('picture', 'Фото', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('comment', 'Комментарий', 'trim|htmlspecialchars|xss_clean');
$this->form_validation->set_rules('verificationComment', 'Комментарий проверки товара', 'trim|htmlspecialchars|xss_clean');
if ( ! $this->form_validation->run())
{
throw new Exception('Не пройдена валидация входящих параметров!');
}
// Если пользователь не авторизован, то добавляем лот в redis на неделю
if (empty($this->user->userID))
{
$this->user->add_basket($this->input->post('item_type'), $this->input->post());
if ($this->input->is_ajax_request())
{
$ajax_response = array(
'status' => 'success',
'message' => 'Товар добавлен в раздел Мои заказы. Для продолжения оформления заказа нажмите "Оформить заказ"!',
);
die(json_encode($ajax_response));
}
else
{
$this->log_model->success('Товар добавлен в раздел Мои заказы. Для продолжения оформления заказа нажмите "Оформить заказ"!', 'login/index');
}
}
$item_type = $this->input->post('item_type');
if (empty($item_type) && strpos($this->input->post('url'), 'ebay'))
{
$item_type = 'lot';
}
elseif (empty($item_type))
{
$item_type = 'shop';
}
// Добавляем товар в заказ
if ($item_type === 'lot')
{
$post_data = array_merge([
'country' => NULL,
'amount' => 1,
'comment' => NULL,
'verificationComment' => NULL,
'color' => NULL,
'size' => NULL,
'property_list' => NULL,
'itemCost' => NULL,
'itemID' => NULL,
'itemSum' => NULL,
'verified' => NULL,
'is_auction' => NULL,
], $this->input->post());
$message = $this->lots_model->add_lot($fromCabinet, $post_data);
}
elseif ($item_type === 'shop')
{
$post_data = array_merge([
'url' => NULL,
'name' => NULL,
'country' => NULL,
'price' => 0,
'amount' => 1,
'usa_price' => 0,
'tax_store' => 0,
'color' => NULL,
'size' => NULL,
'comment' => NULL,
'picture' => NULL,
'property_list' => NULL,
'confirm' => NULL,
'verificationComment' => NULL,
'itemID' => NULL,
'store' => NULL,
], $this->input->post());
$message = $this->shops_model->add_shop($fromCabinet, $post_data);
}
if ($this->input->is_ajax_request())
{
$ajax_response = array(
'status' => 'success',
'message' => $message,
);
die(json_encode($ajax_response));
}
else
{
$this->log_model->success($message, $this->input->post('without_redirect') ? NULL : order_link('need_pay'));
}
}
catch (Exception $e)
{
if ($this->input->is_ajax_request())
{
$ajax_response = array(
'status' => 'error',
'message' => $e->getMessage(),
);
die(json_encode($ajax_response));
}
else
{
$this->log_model->error($e->getMessage(), $this->input->post('without_redirect') ? NULL : order_link('need_pay'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment