Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Friendship customers discount


YePix

Recommended Posts

Posted

Hello people, could someone look here and tell me if he sees a mistake? The database is not updated. friendship_applied and friendship_order_id are not written

Update:
 

//Friendship customers discount
if (FRIENDSHIP_ENABLE == 'True'){
	$friendship = get_friendship_discount(FRIENDSHIP_ORDER_STATUS);
	$friendship_discount = FRIENDSHIP_DISCOUNT;
	$this_order = $insert_id; 
		
	if (($friendship!=false) and ($friendship['friendship_newcustomer']==1)){
		$update_friendship_info_query = tep_db_query("update " . TABLE_CUSTOMERS_FRIENDSHIP . " set friendship_applied = 1, friendship_order_id = " . $insert_id . ", date_discount_applied = now()  where friendship_id = '" . $friendship['friendship_id'] . "'");
		$customer_friendship = tep_db_fetch_array($update_friendship_info_query);
		$sql_data_array = array('friendship_customer_id' => $friendship['friendship_friend_id'],
                                'friendship_friend_id' => $friendship['friendship_customer_id'],
                                'friendship_date' => 'now()',
                                'friendship_applied' => '0',
                                'friendship_discount' => $friendship_discount,
                                'friendship_newcustomer' => '0',
                                'friendship_order_id' => (int)$insert_id);
                                
		tep_db_perform(TABLE_CUSTOMERS_FRIENDSHIP, $sql_data_array);
		
	}elseif($friendship!=false){
		$update_friendship_info_query = tep_db_query("update " . TABLE_CUSTOMERS_FRIENDSHIP . " set friendship_applied = 1, date_discount_applied = now()  where friendship_id = '" . $friendship['friendship_id'] . "'");
		$customer_friendship = tep_db_fetch_array($update_friendship_info_query);
	}
	
}		
//End Friendship customers discount 

 

Funktion:
 

function get_friendship_discount($status) {
  	global $customer_id;
  	$customer_friendship_query = tep_db_query("select * from " .TABLE_CUSTOMERS_FRIENDSHIP. " where friendship_customer_id = '".(int)$customer_id."' and friendship_applied = 0");
	if (tep_db_num_rows($customer_friendship_query) > 0){
		$customer_friendship = tep_db_fetch_array($customer_friendship_query);
		if ($customer_friendship['friendship_newcustomer'] == 1){
		    //Controlar que el cliente que ha recomendado la tienda ya haya realizado algun pedido anteriormente
		    $friendship_orders_query = tep_db_query("select count(*) as 'orders' from " .TABLE_ORDERS. " where customers_id = '".$customer_friendship['friendship_friend_id']."' and orders_status = '".$status."' ");
		    $friendship_orders = tep_db_fetch_array($friendship_orders_query);
		    $num_orders = $friendship_orders['orders'];
		    if ($num_orders < 1){
		    	return false;
		    }  
		    else{ return $customer_friendship ;
		    }
		}else{
			$order_status_query = tep_db_query("select orders_status from " .TABLE_ORDERS. " where orders_id = '".(int)$customer_friendship['friendship_order_id']."' ");
			$order_status = tep_db_fetch_array($order_status_query);
			if ($order_status['orders_status'] == $status)
				return $customer_friendship ;
			else
				return false;
		}
	}else
		return false;
  }

 

Posted
//Friendship customers discount
if (FRIENDSHIP_ENABLE == 'True'){
	$friendship = get_friendship_discount(FRIENDSHIP_ORDER_STATUS);
	$friendship_discount = FRIENDSHIP_DISCOUNT;
	$this_order = $insert_id; // <---------- It's $this_order used on other place???
		
	if (($friendship!=false) and ($friendship['friendship_newcustomer']==1)){
		$update_friendship_info_query = tep_db_query("update " . TABLE_CUSTOMERS_FRIENDSHIP . " set friendship_applied = 1, friendship_order_id = " . $insert_id . ", date_discount_applied = now()  where friendship_id = '" . $friendship['friendship_id'] . "'");
		$customer_friendship = tep_db_fetch_array($update_friendship_info_query); // <---------- without a select??? That's nonsens!!!
		
// This array is filled from your function get_friendship_discount                                             
                                             $sql_data_array = array('friendship_customer_id' => $friendship['friendship_friend_id'],
                                'friendship_friend_id' => $friendship['friendship_customer_id'],
                                'friendship_date' => 'now()',
                                'friendship_applied' => '0',
                                'friendship_discount' => $friendship_discount,
                                'friendship_newcustomer' => '0',
                                'friendship_order_id' => (int)$insert_id);
                                
		tep_db_perform(TABLE_CUSTOMERS_FRIENDSHIP, $sql_data_array);
		
	}elseif($friendship!=false){
		$update_friendship_info_query = tep_db_query("update " . TABLE_CUSTOMERS_FRIENDSHIP . " set friendship_applied = 1, date_discount_applied = now()  where friendship_id = '" . $friendship['friendship_id'] . "'");
		$customer_friendship = tep_db_fetch_array($update_friendship_info_query); // <---------- without a select??? That's nonsens!!!
	}
	
}		
//End Friendship customers discount 

 

function get_friendship_discount($status) {
  	global $customer_id;
  	$customer_friendship_query = tep_db_query("select * from " .TABLE_CUSTOMERS_FRIENDSHIP. " where friendship_customer_id = '".(int)$customer_id."' and friendship_applied = 0");
	//if (tep_db_num_rows($customer_friendship_query) > 0){
		if (tep_db_num_rows($customer_friendship_query)){ // <----------- it's the same like ---> if (tep_db_num_rows($customer_friendship_query) > 0){
		$customer_friendship = tep_db_fetch_array($customer_friendship_query);
		if ($customer_friendship['friendship_newcustomer'] == 1){
		    //Controlar que el cliente que ha recomendado la tienda ya haya realizado algun pedido anteriormente
		    $friendship_orders_query = tep_db_query("select count(*) as 'orders' from " .TABLE_ORDERS. " where customers_id = '".$customer_friendship['friendship_friend_id']."' and orders_status = '".$status."' ");
		    $friendship_orders = tep_db_fetch_array($friendship_orders_query);
		    $num_orders = $friendship_orders['orders'];
		    if ($num_orders < 1){
		    	return false;
		    }  
		    else{ return $customer_friendship ;
		    }
		} else {
			$order_status_query = tep_db_query("select orders_status from " .TABLE_ORDERS. " where orders_id = '".(int)$customer_friendship['friendship_order_id']."' ");
			$order_status = tep_db_fetch_array($order_status_query);
			/*
			if ($order_status['orders_status'] == $status)
				return $customer_friendship ;
			else
				return false;
			*/	
			//short and faster
			($order_status['orders_status'] == $status ? return $customer_friendship : return false);
		}
	}else
		return false;
  }

🤣🤣🤣 clever!!!

  • The clever one learn from everything and from everybody
  • The normal one learn from his experience
  • The silly one knows everything better

[socrates, 412 before Christ]

Computers help us with the problems we wouldn't have without them!
99.9% of the bugs sit in front of the computer!
My programmed add-ons: WDW EasyTabs 1.0.3, WDW Facebook Like 1.0.0

if(isset($this) || !isset($this)){ // that's the question...

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...