Jump to content

Recommended Posts

Всем привет!
Нуждаюсь в Вашей помощи.
Пишу дополнительный заказ товара через аккаунт, проблема в том что не обновляет таблицу БД, с opencart недавно начал разбираться, так что не судите строго.
Спасибо!


Controller:

class ControllerAccountNewOrder extends Controller{
	private $error = array();	
	public function index(){
		if (!$this->customer->isLogged()) {
			$this->redirect($this->url->link('account/login', '', 'SSL'));
			
		}
		
		$this->language->load('account/new_order');
		$this->document->setTitle($this->language->get('heading_title'));
		$this->load->model('account/neworder');
		
		/*if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_account_neworder->newOrder($this->request->post);						  	  
	  		//$this->redirect($this->url->link('account/account'));
    	} */
		
		/* load text */
		$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['text_form'] = $this->language->get('text_form');
		$this->data['linktopr'] = $this->language->get('linktopr');
		$this->data['text_description'] = $this->language->get('text_description');
		$this->data['text_color'] = $this->language->get('text_color');
		$this->data['text_size'] = $this->language->get('text_size');
		$this->data['text_count_product'] = $this->language->get('text_count_product');
		$this->data['text_price'] = $this->language->get('text_price');
		$this->data['text_sposob'] = $this->language->get('text_sposob');
		$this->data['text_delivery_usa'] = $this->language->get('text_delivery_usa');
		$this->data['text_hint'] = $this->language->get('text_hint');
		$this->data['text_new_pochta'] = $this->language->get('text_new_pochta');
		$this->data['text_btn_save'] = $this->language->get('text_btn_save');
		$this->data['text_count'] = $this->language->get('text_count');
		$this->data['text_comments'] = $this->language->get('text_comments');
		$this->data['text_enter_comment'] = $this->language->get('text_enter_comment');
		
		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
		$this->data['action'] = $this->url->link('account/new_order', '', 'SSL');
		
		/* data */
		if (isset($this->error['forma'])) {
			$this->data['error_forma'] = $this->error['forma'];
		} else {
			$this->data['error_forma'] = '';
		}
		
		if (isset($this->error['linkto'])) {
			$this->data['error_linkto'] = $this->error['linkto'];
		} else {
			$this->data['error_linkto'] = '';
		}
		
		if (isset($this->error['description'])) {
			$this->data['error_description'] = $this->error['description'];
		} else {
			$this->data['error_description'] = '';
		}
		
		if (isset($this->error['color'])) {
			$this->data['error_color'] = $this->error['color'];
		} else {
			$this->data['error_color'] = '';
		}
		
		if (isset($this->error['sizes'])) {
			$this->data['error_sizes'] = $this->error['sizes'];
		} else {
			$this->data['error_sizes'] = '';
		}
		
		if (isset($this->error['counts'])) {
			$this->data['error_counts'] = $this->error['counts'];
		} else {
			$this->data['error_counts'] = '';
		}
		if (isset($this->error['tcena'])) {
			$this->data['error_tcena'] = $this->error['tcena'];
		} else {
			$this->data['error_tcena'] = '';
		}

		
		if (isset($this->request->post['forma'])) {
			$this->data['forma'] = $this->request->post['forma'];
		} elseif (isset($customer_info)) {
			$this->data['forma'] = $customer_info['forma'];
		} else {
			$this->data['forma'] = '';
		}
		
		if (isset($this->request->post['linkto'])) {
			$this->data['linkto'] = $this->request->post['linkto'];
		} elseif (isset($customer_info)) {
			$this->data['linkto'] = $customer_info['linkto'];
		} else {
			$this->data['linkto'] = '';
		}
		
		if (isset($this->request->post['description'])) {
			$this->data['description'] = $this->request->post['description'];
		} elseif (isset($customer_info)) {
			$this->data['description'] = $customer_info['description'];
		} else {
			$this->data['description'] = '';
		}
		if (isset($this->request->post['color'])) {
			$this->data['color'] = $this->request->post['color'];
		} elseif (isset($customer_info)) {
			$this->data['color'] = $customer_info['color'];
		} else {
			$this->data['color'] = '';
		}
		if (isset($this->request->post['sizes'])) {
			$this->data['sizes'] = $this->request->post['sizes'];
		} elseif (isset($customer_info)) {
			$this->data['sizes'] = $customer_info['sizes'];
		} else {
			$this->data['sizes'] = '';
		}
		if (isset($this->request->post['counts'])) {
			$this->data['counts'] = $this->request->post['counts'];
		} elseif (isset($customer_info)) {
			$this->data['counts'] = $customer_info['counts'];
		} else {
			$this->data['counts'] = '';
		}
		if (isset($this->request->post['tcena'])) {
			$this->data['tcena'] = $this->request->post['tcena'];
		} elseif (isset($customer_info)) {
			$this->data['tcena'] = $customer_info['tcena'];
		} else {
			$this->data['tcena'] = '';
		}

		
		$this->data['back'] = $this->url->link('account/account', '', 'SSL');
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/new_order.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/account/new_order.tpl';
		} else {
			$this->template = 'default/template/account/new_order.tpl';
		}
		
		$this->children = array(
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'	
		);

		$this->response->setOutput($this->render());
	}
	public function insert() { 
		$this->load->model('account/neworder');
		$this->document->setTitle($this->language->get('heading_title'));
	
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validateForm())) {
			$this->model_catalog_news->newOrder($this->request->post);

			$this->session->data['success'] = $this->language->get('text_success');

			$this->redirect($this->url->link('account/new_order', 'token=' . $this->session->data['token'], 'SSL'));
		}
	
		$this->getForm();
	}
	protected function validate() {
		if ((utf8_strlen($this->request->post['forma']) < 1) || (utf8_strlen($this->request->post['forma']) > 32)) {
      		$this->error['forma'] = $this->language->get('error_forma');
    	}
		if ((utf8_strlen($this->request->post['linkto']) < 1) || (utf8_strlen($this->request->post['linkto']) > 32)) {
      		$this->error['linkto'] = $this->language->get('error_linkto');
    	}
		if ((utf8_strlen($this->request->post['description']) < 1) || (utf8_strlen($this->request->post['description']) > 32)) {
      		$this->error['description'] = $this->language->get('error_description');
    	}
		if ((utf8_strlen($this->request->post['color']) < 1) || (utf8_strlen($this->request->post['color']) > 32)) {
      		$this->error['color'] = $this->language->get('error_color');
    	}
		if ((utf8_strlen($this->request->post['sizes']) < 1) || (utf8_strlen($this->request->post['sizes']) > 32)) {
      		$this->error['sizes'] = $this->language->get('error_sizes');
    	}
		if ((utf8_strlen($this->request->post['counts']) < 1) || (utf8_strlen($this->request->post['counts']) > 32)) {
      		$this->error['counts'] = $this->language->get('error_counts');
    	}
		if ((utf8_strlen($this->request->post['tcena']) < 1) || (utf8_strlen($this->request->post['tcena']) > 32)) {
      		$this->error['tcena'] = $this->language->get('error_tcena');
    	}
		
		if (!$this->error) {
      		return true;
    	} else {
      		return false;
    	}
	}
	
}

Model
 

class ModelAccountNewOrder extends Model{
	public function newOrder($data){		
		$this->db->query("INSERT INTO " . DB_PREFIX 
		. "new_order SET new_order_id = '" . (int)$data['new_order_id'] 
		. "', forma = '" . $this->db->escape($data['forma']) 
		. "', linkto = '" . $this->db->escape($data['linkto']) 
		. "', description = '" . $this->db->escape($data['description']) 
		. "', color = '" . $this->db->escape($data['color']) 
		. "', sizes = '" . $this->db->escape($data['sizes']) 
		.  "', counts = '" . (int)$data['counts'] 
		. "', tcena = '" . $this->db->escape($data['tcena']) 
		. "'");
      	$new_order_id = $this->db->getLastId();
	}
}

view
 

 <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
    <div class="information_page">
		<table border="0">
			<tr>
				<th><?php echo $text_form; ?></th>
				<th><?php echo $linktopr; ?></th>
				<th><?php echo $text_description; ?></th>
				<th><?php echo $text_color; ?></th>
				<th><?php echo $text_size; ?></th>
				<th><?php echo $text_count_product; ?></th>
				<th><?php echo $text_price; ?></th>
			</tr>
			<tr>
				<td>
					<input type="text" name="forma" />
					 <?php if ($error_forma) { ?>
						<span class="error"><?php echo $error_forma; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="linkto" />
					 <?php if ($error_linkto) { ?>
						<span class="error"><?php echo $error_linkto; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="description" />
					 <?php if ($error_description) { ?>
						<span class="error"><?php echo $error_description; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="color" />
					 <?php if ($error_color) { ?>
						<span class="error"><?php echo $error_color; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="sizes" />
					 <?php if ($error_sizes) { ?>
						<span class="error"><?php echo $error_sizes; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="counts" />
					 <?php if ($error_counts) { ?>
						<span class="error"><?php echo $error_counts; ?></span>
					<?php } ?>
				</td>
				<td>
					<input type="text" name="tcena" />
					 <?php if ($error_tcena) { ?>
						<span class="error"><?php echo $error_tcena; ?></span>
					<?php } ?>
				</td>
			</tr>
</table>

     </div>
	 <div class="buttons">
      <div class="left"><a href="<?php echo $back; ?>" class="button">Назад</a></div>
      <div class="right">
        <input type="submit" value="Отправить" class="button" />
      </div>

Share this post


Link to post
Share on other sites

У вас метод insert каким образом вызывается вообще? логично было бы сделать     его тут, а из самого метода убрать проверку на пост данные, илбо вообще удалить метод и передачу в модель оставить тут ...

 /*if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {

            $this->model_account_neworder->newOrder($this->request->post);                             
             //$this->redirect($this->url->link('account/account'));
    } */

        

Share this post


Link to post
Share on other sites

тему можно закрывать, вопрос решен!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Content

    • By seotime
      День добрый. Прошу помощи в составлении запроса к БД.
      По id категории получить seo_url этой категории.
      Переменная $categories содержит массив с номерами id категорий.
      В бд таблица url_alias, где столбцы столбцы query (где хранятся урлы вида category_id=номер) и столбец keyword (где прописан алиас).
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.