[HACK] Login for price

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
meules
Confirmed
Confirmed
Posts: 95
Joined: Wed Jun 17, 2009 8:56 pm
Location: NL

Re: [HACK] Login for price

Post by meules »

Hi there,

The code posted before works correct now, thanks to Painstik' addition. There's only one thing that needs to be done which I can't get to work. Right now if a customer signs up I have to send them an email which says that their account is approved and that they are ready to make an order. This is done by hand and sometimes a very boring proces :x What I try to archieve is that when I update the customer account group (eg from waiting for verification to approved) an email is send out automatically. The code that updates the customergroup is as follows:

Code: Select all

		
private function _BuildGroupDropdown($CustomerId, $SelectedGroup, $CustomerName)
		{
			$output = sprintf("<select onchange='updateCustomerGroup(%d, this.options[this.selectedIndex].value, \"%s\", this.options[this.selectedIndex].text)' name='customergroup_%d' id='customergroup_%d'>", $CustomerId, isc_html_escape($CustomerName), $CustomerId, $CustomerId);
			$output .= sprintf("<option value='0'>%s</option>", GetLang("SelectCustomerGroup"));

			$output .= $this->GetCustomerGroupsAsOptions($SelectedGroup);
			$output .= "</select>";
			return $output;			
}
Does anybody knows how this can be done?
ISC v6
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: [HACK] Login for price

Post by Tony Barnes »

It's not going to be too tricky, will be along the lines of :
$output = sprintf("<select onchange='updateCustomerGroup(%d, this.options[this.selectedIndex].value, \"%s\", this.options[this.selectedIndex].text); emailcustomer([this.selectedindex].value)'
Then have a function like:
emailcustomer(thisValue) {
if (val.(thisValue)==6) {
sendapprovalemail()
}
};
with sendapprovalemail() being set up to send the mail, no idea on that one though.

Do note my javascript writing ain't great, so whilst the first bit of this should be spot on (getting the onchange to fire the function) the actual function likely needs a little TLC..!!! More of a start point than an end one ;) :D
meules
Confirmed
Confirmed
Posts: 95
Joined: Wed Jun 17, 2009 8:56 pm
Location: NL

Re: [HACK] Login for price

Post by meules »

Thanks Tony... Indeed a good starting point which I definitely will try out this evening. My biggest problem is how to set the code so that the dropdown will send out an email. Creating the function itself can't be to hard... I guess... :D

Anymore suggestions? Painstik?
ISC v6
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: [HACK] Login for price

Post by Tony Barnes »

How do you mean? The stuff I've just put there will cause changing the drop down to fire off the email function, which you need to make. I'd copy/paste it from elsewhere :D
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: [HACK] Login for price

Post by Painstik »

I will try to do something about this
Need custom coding for Interspire Shopping Cart? Contact me
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: [HACK] Login for price

Post by Painstik »

I think this is how they are sending email, i found this code in various files, orders.php, customers.php, etc.

Code: Select all

// Now send a notification email to the customer
					$customer_email = $this->GetCustomerEmailByOrderId($order_id);

					// Create a new email API object to send the email
					$store_name = GetConfig('StoreName');

					$emailTemplate = FetchEmailTemplateParser();
					$emailTemplate->SetTemplate("ordermessage_notification");
					$message = $emailTemplate->ParseTemplate(true);

					require_once(ISC_BASE_PATH . "/lib/email.php");
					$obj_email = GetEmailClass();
					$obj_email->Set('CharSet', GetConfig('CharacterSet'));
					$obj_email->From(GetConfig('OrderEmail'), $store_name);
					$obj_email->Set("Subject", $subject);
					$obj_email->AddBody("html", $message);
					$obj_email->AddRecipient($customer_email, "", "h");
					$email_result = $obj_email->Send();

But I doubt that you are looking in right function, we need a function for assigning a customer group, and this fuction you are looking at is just for dropdown output...
Need custom coding for Interspire Shopping Cart? Contact me
meules
Confirmed
Confirmed
Posts: 95
Joined: Wed Jun 17, 2009 8:56 pm
Location: NL

Re: [HACK] Login for price

Post by meules »

Painstik, thanks for helping.

I think this is the complete code for updating a customer group:

in admin/includes/classes/class.customer.php find around line 2945

Code: Select all

		/**
		* _GetGroupList
		* Get a list of groups and return them as an array
		*
		* @param Int $NumGroups A reference variable to hold the number of groups
		* @return Array The list of groups
		*/
		private function _GetGroupList(&$NumGroups)
		{
			$groups = array();
			$query = "SELECT * FROM [|PREFIX|]customer_groups ORDER BY groupname ASC";
			$result = $GLOBALS["ISC_CLASS_DB"]->Query($query);
			$NumGroups = $GLOBALS["ISC_CLASS_DB"]->CountResult($result);

			while($row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result)) {
				$groups[$row['customergroupid']] = $row;
			}

			return $groups;
		}

		/**
		* _BuildGroupDropdown
		* Build the select box to show a customer's group on the View Customers page
		*
		* @param Int $CustomerId The ID of the customer from the customers table
		* @param Int $SelectedGroup The ID of the group that the customer belongs to
		* @param String CustomerName The customer's name for the flashmessage when the group is changed
		*
		* @return String The select box's HTML
		*/
		private function _BuildGroupDropdown($CustomerId, $SelectedGroup, $CustomerName)
      	{
         $output = sprintf("<select onchange='updateCustomerGroup(%d, this.options[this.selectedIndex].value, \"%s\", this.options[this.selectedIndex].text)' name='customergroup_%d' id='customergroup_%d'>", 
		 
		 $CustomerId, isc_html_escape($CustomerName), $CustomerId, $CustomerId);
         
		 $output .= sprintf("<option value='0'>%s</option>", GetLang("SelectCustomerGroup"));
		 $output .= $this->GetCustomerGroupsAsOptions($SelectedGroup);
         $output .= "</select>";
         return $output;         
}
		



		/**
		* GetCustomerGroupsAsOptions
		* Return a list of option tags containing name/values of customer groups
		*
		* @param Int $SelectedGroup The group to mark as selected in the option tags
		*
		* @return String The HTML <option> tags
		*/
		public function GetCustomerGroupsAsOptions($SelectedGroup=0)
		{
			$this->_customerGroups = &$this->_GetGroupList($numGroups);
			$options = "";

			foreach($this->_customerGroups as $group) {
				if ($SelectedGroup == $group['customergroupid']) {
					$sel = "selected='selected'";
				}
				else {
					$sel = "";
				}

				$options .= sprintf("<option value='%d' %s>%s</option>", (int) $group['customergroupid'], $sel, isc_html_escape($group['groupname']));
				}
 
   }


			return $options;
		}
Found the code you posted and tried to implement it but no luck. I think it is something in the last line where it says "return options;" I think that's the part that updates the customer group and saves it. Maybe what Tony said has to go in one of the last lines??
Anyway I'm not that good in php and just good in reproducing :o

Any thoughts?
ISC v6
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: [HACK] Login for price

Post by Tony Barnes »

Was that first bit of code from the php..?? lmao, brain clearly wasn't in gear, I had javascript in mind!

However, what I did sorta still holds - by getting the drop down to fire the javascript to action the php email system, though doing it in a one-er with the php may make more sense..!!!
Crisper
Posts: 12
Joined: Thu Oct 22, 2009 6:24 pm

Re: [HACK] Login for price

Post by Crisper »

Waiting with baited breath for this...
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: [HACK] Login for price

Post by Painstik »

Ok, done.

First create new html file in templates/__emails and name it verified_account.html

Add this in that file:

Code: Select all

<html><body style="font-family:Arial; font-size:12px">
	<div style="padding:0px 20px 20px 20px">
		<h2 style="font-size:22px; height:30px; color:#cc6600; border-bottom:dashed 1px gray">%%LNG_ThanksForRegisteringAt%% %%GLOBAL_StoreName%%</h2>

		<p>%%LNG_Hi%% %%GLOBAL_FirstName%%,</p>

		<p>%%LNG_YourAccountIsVerified%%</a>

		<p>%%LNG_ThanksForRegisteringEmailLogin%%</a>

		<p>%%LNG_ThanksForRegisteringAtIntro%%</p>		

		%%GLOBAL_EmailFooter%%
	</div>
</body></html>
Open: language/admin/customers.ini
Add this:

Code: Select all

YourAccountIsVerifiedIntro = "Your account is verified."
YourAccountIsVerified = "You account is verified blabla (text within content)."
ThanksForRegisteringAtIntro = "Thank you for registering on our site bla bla bla"
ThanksForRegisteringEmailLogin = "For login on your account please visit <a href='%s'>%s</a> or <a href='%s'>click here</a>."
Open: admin/includes/classes/class.customers.php
Find: (~ line 2850)

Code: Select all

if (gzte11(ISC_MEDIUMPRINT)) {
				$existingCustomer = $this->customerEntity->get($customerId);
				if (isId($existingCustomer['custformsessionid'])) {
					$GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT, true, $existingCustomer['custformsessionid']);
				} else {
					$formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT);
					if (isId($formSessionId)) {
						$StoreCustomer['custformsessionid'] = $formSessionId;
					}
				}
			}
Add before:

Code: Select all

$GLOBALS['FirstName'] = isc_html_escape($StoreCustomer['firstname']);
			$GLOBALS['ISC_LANG']['ThanksForRegisteringEmailLogin'] = sprintf(GetLang('ThanksForRegisteringEmailLogin'), $GLOBALS['ShopPathSSL']."/account.php", $GLOBALS['ShopPathSSL']."/account.php", $GLOBALS['ShopPathSSL']."/account.php");
			
			if ($StoreCustomer['customergroupid']) {
				$store_name = GetConfig('StoreName');
				$subject = GetLang('YourAccountIsVerifiedIntro');

				$emailTemplate = FetchEmailTemplateParser();
				$emailTemplate->SetTemplate("verified_account");
				$message = $emailTemplate->ParseTemplate(true);

				require_once(ISC_BASE_PATH . "/lib/email.php");
				$obj_email = GetEmailClass();
				$obj_email->Set('CharSet', GetConfig('CharacterSet'));
				$obj_email->From(GetConfig('OrderEmail'), $store_name);
				$obj_email->Set("Subject", $subject);
				$obj_email->AddBody("html", $message);
				$obj_email->AddRecipient($StoreCustomer['email'], "", "h");
				$email_result = $obj_email->Send();			   
			}

Note: It works only when you go edit customer, and click save changes. It doesn't work when you change customers group from customers grid at dropdown menu.
Last edited by Painstik on Thu Jan 28, 2010 11:29 pm, edited 1 time in total.
Need custom coding for Interspire Shopping Cart? Contact me
Post Reply