Post by lucaslopatka » Fri Feb 05, 2010 9:14 am

Hi, I recently wrote a set of classes that adds newly accumulated customer "points" to a database. However, if I refresh the confirm screen, the points will keep adding to the existing balance every time. Is there something I can isset() these functions to, or is there somewhere where I clear the variables to stop this from happening?

Help would be much appreciated... new to OpenCart, and still trying to figure out where everything is. Thanks!

This is from model->order.php

Code: Select all

$order_id = $this->db->getLastId();

		/*--EDIT--*/
		// Load Reward Points module
		$this->load->model('module/points');
		$this->points = $this->model_module_points;
		/*--END EDIT--*/
		foreach ($data['products'] as $product) { 
			$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', quantity = '" . (int)$product['quantity'] . "'");
 
			$order_product_id = $this->db->getLastId();

			foreach ($product['option'] as $option) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', price = '" . (float)$product['price'] . "', prefix = '" . $this->db->escape($option['prefix']) . "'");
			}
				
			foreach ($product['download'] as $download) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
			}
		}
		
		// Add reward points to customer account
		if ($this->points->hasProductPoints($product['product_id'])) {
			$this->points->addCustomerPoints($data['customer_id'], $this->points->getProductPoints($product['product_id']) * $product['quantity']);
		}
This is from controller->confirm.php

Code: Select all

$this->data['products'] = array();
		/*--EDIT--*/
    	$this->load->model('module/points');
		$this->points = $this->model_module_points;
		/*--END EDIT--*/
		foreach ($this->cart->getProducts() as $product) {
      		$option_data = array();

      		foreach ($product['option'] as $option) {
        		$option_data[] = array(
          			'name'  => $option['name'],
          			'value' => $option['value']
        		);
      		} 
 
      		$this->data['products'][] = array(
				'product_id' => $product['product_id'],
        		'name'       => $product['name'],
        		'model'      => $product['model'],
        		'option'     => $option_data,
				/*--EDIT--*/
				'points'	 => $this->points->getProductPoints($product['product_id']),
				/*--END EDIT--*/
				'quantity'   => $product['quantity'],
				'tax'        => $this->tax->getRate($product['tax_class_id']),
        		'price'      => $this->currency->format($product['price']),
        		'total'      => $this->currency->format($product['total']),
				'href'       => $this->url->http('product/product&product_id=' . $product['product_id'])
      		); 

Newbie

Posts

Joined
Fri Jan 22, 2010 5:13 pm

Post by Qphoria » Fri Feb 05, 2010 9:48 am

Code: Select all

if (!isset($this->points) || !$this->points) {
      $this->load->model('module/points');
      $this->points = $this->model_module_points;
}

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by lucaslopatka » Fri Feb 05, 2010 8:02 pm

Hi Q -- yep, that was a miss... still not fixing the issue though -- am I attaching the function to the wrong file? Tried commenting the lines out on both the model and controller previously mentioned... no diff..

What variable is set when you click the "confirm" button on checkout? If you use a submit button, that would be as simple as isset('submit')... What's the workaround with your JavaScript? If I can get this resolved, you deserve a donnie, and the community can have a plugin...

Newbie

Posts

Joined
Fri Jan 22, 2010 5:13 pm

Post by Qphoria » Sat Feb 06, 2010 9:01 am

Well you need to put it in the confirm file for displaying the points to the customer on the confirm page.
Then after checkout, in the model/checkout/order.php is where you would do any adding/removing of points.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 1 guest