Post by subdivide » Thu Mar 15, 2012 3:07 pm

Hey All,

Maybe I'm missing something, but I'm building and testing now and I've made well over 100 test orders at this point, with every single one of my products having rewards points set on them, yet I have never been awarded a single reward point for any purchase.

I can add rewards points just fine through the admin, but on checkout, rewards points are never issued to the customer.

So I searched ....

This is 1.5.1.3 btw.

There are 15 references to the phrase DB_PREFIX . "customer_reward in the entire system which would signify some action with the customer_rewards table where rewards are inserted and calculated for customers.

Those 15 queries with the customer_rewards table break down like so:

SELECT :: 10
DELETE :: 3
UPDATE :: 0
INSERT :: 2

Only updates or inserts could possibly add rows to the table so that leaves only 2 possible places in the script where points could be added to the account.

1. admin/model/sale/customer.php

This is used from within the admin section to add rewards points to a customer and the only way I've found so far to get points in there.

2. catalog/model/total/reward.php

The confirm method within this model searches each entry in the order_total variable passed in by sub-string for any items that contain (), which would ONLY be rewards points entries that are used to PAY FOR a purchase, and then inserts an entry with a negative value ie: points= (float)-$points thus subtractive points that have been used to purchase.

Thats' it ... I've searched through this code several times now and nowhere can I find a place where points are ADDED to a customers account other than manually through the admin panel.

Am I missing something? There doesn't seem to be much reason for points if the customer never receives them.

If someone, Daniel perhaps can address this and let me know what the heck I'm missing I would be greatly appreciative.

Thanks a lot for the great work you guys do.

-Vince

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by uksitebuilder » Tue Mar 20, 2012 1:48 am

Points rewarding is not automatic, they need to be added manually when viewing an order.

Points can only be added to Real Customers (i.e. not to Guest Checkout Customers)

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by subdivide » Tue Mar 20, 2012 9:03 am

LOL!

That has the be the stupidest thing I've ever heard of.

As if people are going to go into the admin panel for each sale and add points. We have over 15,000 orders per month.

I wrote it all into the customer class once the order reaches the proper status, this allows us to give points for other tasks as well such as reviewing and sharing products on Twitter and Facebook.

There's a serious lack of forward thinking here in reference to this issue. Crazy.

Peace.

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by olstar » Thu Apr 26, 2012 7:05 pm

@Subdivide

Did you get it working automatically then mate?

Care to share? ;D

If not i may make a mod for this as this is batsh*t crazy!

Professional UK Based eCommerce - Our Free Opencart Mods - Our Premium Opencart Mods
Kashflow Integration


User avatar
New member

Posts

Joined
Tue Jul 05, 2011 3:53 pm


Post by subdivide » Thu Apr 26, 2012 7:14 pm

LMAO yeah it is ... unbelievable actually, I was flabbergasted once the reality hit me, as you could probably tell by my previous post.

Lemme dig up the code for you.

Gimme a bit.

-V

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

User avatar
New member

Posts

Joined
Tue Jul 05, 2011 3:53 pm


Post by subdivide » Thu Apr 26, 2012 7:47 pm

1. Open system->library->customer.php
2. Add new public variable to Customer class:

Code: Select all

public  $rewardpoints;
3. In __construct function set the $rewardpoints variable inside:

Code: Select all

if ($customer_query->num_rows) { 
AS:

Code: Select all

$this->rewardpoints = $this->getRewardPoints();
4. Inside: public function login() SET:

Code: Select all

$this->rewardpoints = $this->getRewardPoints();

(you'll see where)

5. Inside: public function logout() SET:

Code: Select all

$this->rewardpoints = '';

(you'll see where)

6. Create new function:

Code: Select all

public function getRewardPoints() {
		$query = $this->db->query("SELECT SUM(points) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$this->customer_id . "'");
		$total = ($query->row['total'] > 0) ? $query->row['total'] : 0;
		
		return $total;	
  	}
7. Create new function:

Code: Select all

public function addRewardPoints($customer_id, $description = '', $points = '', $order_id = 0) {
		if ($customer_id) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$customer_id . "', order_id = '" . (int)$order_id . "', points = '" . (int)$points . "', description = '" . $this->db->escape($description) . "', date_added = NOW()");
		}
	}
Now you can simply add points from anywhere in your app as:

Code: Select all

// customer shares their purchase on Facebook from order success page
$this->customer->addRewardPoints (5, "Shared Purchase on Facebook", 10, 2263);
or

Code: Select all

// customer reviews a product
$this->customer->addRewardPoints (5, "Product Review for" . $product['name'], 5);
or whatever.

Also you can show the customer's current points simply by calling the variable in your controller and rendering it to the view:

Code: Select all

$this->data['reward_points'] = $this->customer->rewardpoints;
This is the reason for making the variable public as opposed to private, easier to call and no need to call the method again which would be another query when you already have it. If you're feeling it needs to be more secure or something, make it private and call the method:

Code: Select all

$this->data['reward_points'] = $this->customer->getRewardPoints();
I also wrote a club leader function with gravatar support that displays the user's name and gravatar and added some cache support so the leader never has to be an extra query unless it changes. Kids stuff.

Just keep in mind this is a permanent approach as the customer class is a core file. Make sure you write this stuff down and save it if you're gonna upgrade your OC to a new version.

Enjoy

-V

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by olstar » Thu Apr 26, 2012 7:49 pm

Hmm, maybe make it a vQmod?

If i do ill send it you man - if thats OK by you anyway?

Professional UK Based eCommerce - Our Free Opencart Mods - Our Premium Opencart Mods
Kashflow Integration


User avatar
New member

Posts

Joined
Tue Jul 05, 2011 3:53 pm


Post by subdivide » Thu Apr 26, 2012 7:54 pm

Oh I have no need for it.

If we upgrade we do it via changelog. I've completely rewritten a great deal of the front end of this for our own HTML5 fork of the project. It doesn't get any automated updates of any of that stuff.

No vQmods here, only solid error free code :)

Peace.

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by olstar » Thu Apr 26, 2012 8:26 pm

Sweet man..

Just confirm for me what the above stuff will actually do to my site..

I get that i can go on to reward them for other stuff, but does this add the reward points they acrue from buying stuff to their account automatically?

Thanks man!

Professional UK Based eCommerce - Our Free Opencart Mods - Our Premium Opencart Mods
Kashflow Integration


User avatar
New member

Posts

Joined
Tue Jul 05, 2011 3:53 pm


Post by Avvici » Thu Apr 26, 2012 8:34 pm

No, he set up a variable in customer class so you can call the class and add however many points as you wish through the argument(s).
$this->customer->addRewardPoints (5, "Product Review for" . $product['name'], 5);

It's your job to call $this->customer->addRewardPoints (5, "Product Review for" . $product['name'], 5); in the appropriate place such as order confirmation. It's the same type of call that OC uses to add to cart.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by subdivide » Thu Apr 26, 2012 8:39 pm

Sorry man my bad, you have to add it to the order model.

catalog/model/checkout/order.php

Line 211 is where mine is, but your milage may vary, as long as it's after the language file is loaded.

Code: Select all

// Add rewards points
// this should really go earlier in the script
// but needed a language file loaded first
			
if ($order_info['customer_id'] > 0):
	$description = sprintf($language->get('reward_purchase'), $order_info['order_id']);
	$this->customer->addRewardPoints ($order_info['customer_id'], $description, $order_info['reward'], $order_info['order_id']);
endif;
Then add it to your mail/order.php language files, I put mine at the end.

Code: Select all

// Rewards points for sale
$_['reward_purchase'] 			= 'Reward points from Order ID: #%s';
Sorry about the mix up.

-Vince

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by krosoftware » Sun May 13, 2012 11:10 pm

Hi all
how can I display total reward points (for current order) somewhere under
Sub-Total:
or
VAT:
on the "Confirm order" page?
I will use reward points for anothe purpose, and I need it allways displayed.

Thanks.

New member

Posts

Joined
Thu May 10, 2012 3:11 am

Post by subdivide » Mon May 14, 2012 6:12 am

You'd need to create a new Order Totals module for this I believe.

There's a rewards module now, but it does something different, it's used for displaying the reward points redeemed at checkout. You can see it at:

admin->extensions->order totals

There's a mod there called reward points I think ...

You'd have to do some programming to make this happen, it's not a switch you can turn on and off.

-V

User avatar
New member

Posts

Joined
Sun Jan 01, 2012 9:47 am

Post by olstar » Mon May 14, 2012 10:12 pm

Try this guys;

http://www.opencart.com/index.php?route ... on_id=6385

We made it as i fear your changes were just too much!

This is vQmod and works by auto adding them when order status changed to COMPLETE. O0

Professional UK Based eCommerce - Our Free Opencart Mods - Our Premium Opencart Mods
Kashflow Integration


User avatar
New member

Posts

Joined
Tue Jul 05, 2011 3:53 pm


Post by Avvici » Tue May 15, 2012 1:38 pm

Very nice

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by nezah » Mon May 21, 2012 4:13 am

Ty the new extension i just published. its exactly what you need. no need to do anything manual. it adds reward points to all completed orders. if the order was complete at checkout or updated, the reward points will be added to the customer who earned them.

http://www.opencart.com/index.php?route ... on_id=6486

Newbie

Posts

Joined
Wed Feb 01, 2012 8:28 am
Who is online

Users browsing this forum: No registered users and 287 guests