How to use Prestashop Customer website field for cc email - prestashop

Some customers require order emails to be sent for one more recipient (ie. accounting). So, as customer website field not used in shop, planned to use this. However, have trouble for getting data for classes/Mail.php
$website = Context::getContext()->customer->website;
does not get the data stored in customer website field. How to get this data from customer table website field correctly?
PS 1.7.8.7
All the rest seems doable, just set the value for cc field and it works.

So, found some solution. Not the nice one, as there will be extra query to DB, but it works.
$website = Db::getInstance()->getValue('SELECT `website` FROM `'._DB_PREFIX_.'customer` WHERE `email` = \''.($to).'\' ');

Related

MS Access 2010: Automatically Filters all the records depending on the user logged in

I am creating a database in Microsoft Access 2010 where when a user logged in the database, the user will only see records that is related to him or her. I've put a criteria in the record's query specifically in IssuingManager field which is [Forms]![frm_Home]![txtUser] but I always get enter parameter value when I run it. txtUser is an invisible text box in my main form so the records will have a reference on which records to filter. My main goal is to limit the user's data to their own records and hide or block them to others. I am new to access and still learning it. Any help or other ways I can filter the data or limit it to the records that is only related to the current user logged in is a big help.
This is my SQL code:
SELECT AdditionalFields.Status, tbl_NTE.CaseIDNo, tbl_NTE.EmployeeName,
tbl_PAH.DPosition, tbl_NTE.Function, tbl_NTE.IssuingManager,
tbl_NTE.ApprovingManager, tbl_NTE.ObjectOfViolation, tbl_NTE.Offense,
tbl_NTE.ClassPenalty, tbl_NTE.CorrectiveActionPenalty,
tbl_NTE.ObjectOfViolation2, tbl_NTE.Offense2, tbl_NTE.ClassPenalty2,
tbl_NTE.ObjectOfViolation3, tbl_NTE.CorrectiveActionPenalty2,
tbl_NTE.Offense3, tbl_NTE.ClassPenalty3, tbl_NTE.ObjectOfViolation4,
tbl_NTE.CorrectiveActionPenalty3, tbl_NTE.Offense4, tbl_NTE.ClassPenalty4,
tbl_NTE.CorrectiveActionPenalty4, tbl_NTE.DatesWhenActsWasWereCommited,
tbl_NTE.DatesWhenActsWasWereDiscovered, tbl_NTE.NTEDate,
tbl_NTE.NTELastDateModified, tbl_NTE.NTELastTimeModified,
tbl_NTE.NTELastUser, tbl_PAH.PAHDate, tbl_PAH.PAHLastDateModified,
tbl_PAH.PAHLastTimeModified, tbl_PAH.PAHLastUser, tbl_NCA.NCADate,
tbl_NCA.NCALastDateModified, tbl_NCA.NCALastTimeModified,
tbl_NCA.NCALastUser, tbl_NTE.EndorsedNTENoticeToHR,
tbl_NTE.EndorsementOfNTEToIS, tbl_NTE.DateReceivedNTEByTheEmployee,
tbl_NTE.SubmissionOfWEtoIS, tbl_NTE.SubmissionOfWEtoHRER,
tbl_NTE.InitialDecision, tbl_PAH.ScheduleForPAH, tbl_PAH.Recommendation,
tbl_PAH.EndorsementOfDecisionNoticeFromPAHCommitteeChairToHR,
tbl_PAH.EndorsementOfFinalizedPAHRecommendationToIS,
tbl_NCA.EndorsementOfDA2ToHRForReview, tbl_NCA.EndorsementOfReviewedDA2ToIS,
tbl_NCA.EmployeeAcceptanceOfDecision,
AdditionalFields.DescriptionOfPenaltyFinalDecision,
AdditionalFields.ApplicableDatesofEffectivity, AdditionalFields.Remarks,
AdditionalFields.RunningTAT, AdditionalFields.TAT, tbl_NTE.EHRID,
tbl_NTE.IssuingManagerEmailAddress, tbl_NTE.WrittenExplanationDueDate,
tbl_NTE.OffenseNo5, tbl_NTE.Offense5, tbl_NTE.ObjectOfViolation5,
tbl_NTE.ClassPenalty5, tbl_NTE.CorrectiveActionPenalty5, tbl_NTE.OffenseNo6,
tbl_NTE.Offense6, tbl_NTE.ObjectOfViolation6, tbl_NTE.ClassPenalty6,
tbl_NTE.CorrectiveActionPenalty6, tbl_NTE.OffenseNo7, tbl_NTE.Offense7,
tbl_NTE.ObjectOfViolation7, tbl_NTE.ClassPenalty7,
tbl_NTE.CorrectiveActionPenalty7
FROM (tbl_Worker INNER JOIN ((tbl_PAH INNER JOIN tbl_NCA ON tbl_PAH.
[CaseIDNo] = tbl_NCA.[CaseIDNo]) INNER JOIN AdditionalFields ON
tbl_NCA.CaseIDNo = AdditionalFields.CaseIDNo) ON tbl_Worker.WorkerID =
tbl_NCA.NameOfIssuingManager) INNER JOIN tbl_NTE ON (tbl_NTE.CaseIDNo =
tbl_PAH.CaseIDNo) AND (tbl_Worker.WorkerName = tbl_NTE.IssuingManager)
WHERE (((tbl_NTE.IssuingManager)=[Forms]![frm_Home]![txtUser]));
I would recommend to avoid using form's field references in queries at all. If form closed, the query will request parameter, like most likely in your case.
Replace the reference by global function created in standard module. This function can store the name, for instance, in static/global variable or retrieve it from table. Main or login form can set this variable/table record once, then the form can be closed without affecting queries functionality
Add another column and put the username. So when selecting the records, there's a condition where user='username'. They look all the data base on what the username has.
your method is fine & correct; you just have some sort of cockpit implementation error
the criteria in the query should be: Forms!frm_Home.txtUser
you could have a spelling error in your form name or text box name
make the textbox visible and enter a valid entry and run the query manually
what you are getting appears to be a parameter prompt that means it cannot find the object i.e. form named frm_Home

NULL values in Crystal Reports

I am trying to produce a Crystal Report showing MAIN and ALTERNATE contact details for our customers.
All works fine if the customer has both types of addresses (i.e. MAIN and ALTERNATE) but no report comes out at all for customers who only have a MAIN address. So, to summarise, all customers will have a MAIN address but only some will MAIN and ALTERNATE addresses.
I need to get the report to print sheets for all customers where or not the second address (in this case in our database as Addresses2.AddressType is ALTERNATE or NULL).
My selection formula is shown below:
{SubscriptionMembers.Current} and
{Categories.CategoryType} = "M" and
{SubscriptionMembers.MainSubscription} and
{Addresses.AddressType} in ["MAIN"] and
{Addresses2.AddressType} in ["ALTERNATE"] and
{Addresses.Country} = "United Kingdom" and
not {SubscriptionMembers.Lapsed} and
not {Contacts.Deleted}
I would recommend to use SQL Expression Field, containing something like (isnull({Addresses2.AddressType}, 'ALTERNATE')) and use this field in record selection formula - this way you do not depend on report options about handling NULL values etc.
Because only some have an 'Alternative address', the selection formula is only going to show customers with a 'main' AND 'alternative'.
I assume every customer has a main address
A way I would deal with this is take out {Addresses2.AddressType} in ["ALTERNATE"] and
and just drop the 'alternative' address details in the same section(group) as the main address.
As long as these are linked correctly it will display every customer from your other selection parameters, therefore will show 'main' and the customers who have an 'alternative' address.
How it should look:
Group - CustomerID
'MAIN' address details here 'ALTERNATE' address details here
Group - Details
'DATA' here
Since you need To get customer in either case then one way would be dont take address in record selection formula. Instead create a formula as to check null for address2
If isnull ({Addresses2.AddressType} in ["ALTERNATE"])
then your code
Else If (Addresses.AddressType} in ["MAIN"] or
{Addresses2.AddressType} in ["ALTERNATE"])
Then your calculation
This way you can handle easily

Take email value from table in query

I'm trying to replace all avatars with an avatar generator.
The avatars get generated by putting your email address in the URL.
(I've tried searching but resulted in no solution. That may be because I don't really know what to exactly search for. I hope you can help me out by either linking me an existing thread or simply giving an answer.)
My current table has 2 columns, avatars and email
I want to replace all avatars hello.jpg with //avatar.com/emailadress.png
How can I put the users email value in the replacement query?
I'm using MySQL as DMBS.
This is my current query.
UPDATE members SET avatar = REPLACE(avatar, 'hello.jpg', '//avatar.com/%.png')
% Would be the value of the email adress.
Thank you!
You can just simply concatenate in the value of the email column to the second parameter of REPLACE:
UPDATE members SET avatar = REPLACE(avatar, 'hello.jpg', CONCAT('//avatar.com/', email, '.png'))
WHERE avatar LIKE '%hello.jpg%';
If you want to test it before updating the column. Have a look at the output of this:
SELECT REPLACE(avatar, 'hello.jpg', CONCAT('//avatar.com/', email, '.png'))
from members
WHERE avatar LIKE '%hello.jpg%';

ROR find by sql to grab email addresses out of IBM iSeries (DB2)

We've been continuously working on this issue for a few months and not getting far with it. Since this was first asked, we changed the code (based on what the original developer for the site suggested), but we are still not getting where we need to be.
I'm relatively new to Ruby and am currently taking some courses to learn more about it, so please bear with me. We're using Ruby 1.9 and Rails 3.2 We use AS/400 for our database. We've tried using Active Record for this before, and it doesn't want to work because of our versions of Ruby and Rails being older combined with getting it to connect with the 400.
We have an online ordering site that you have to have an account set up to access. Depending on what type of account you are set up as, you might have to have your order approved by someone. I.e. if I am a drop ship account, my distributor has to approve what I'm ordering. The way it had been set up, the distributor wasn't getting any kind of approval email.
Each account that requires approval has x number of email addresses attached to it of people who are able to approve the order. We have been told that target_email needs to be a string, so we tried numerous ways of making it a string to no avail. As is, it's only sending the first two email, not the approval email. If we run target_email = Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"] in console, it returns the expected email addresses associated with that account. So we know that's working the way it should... but we're at a loss as to what is wrong with the rest of the code.
# notify Customer
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation", email_details)
target_email = Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
# Order Approval
if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD"
# If there is no distributor email address, the mailer model will substitute in the admin's email from their settings
target_email.each do | email_address | Mailer.deliver_order_distributor_approval_email(email_address, 'Coastal Pet Online Ordering<noreply#coastalpet.com>', "Order Confirmation Approval", email_details)
end
# notify Coastal staff
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation-Notify Staff", email_details)
end
I tried
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = act223").uniq
This works but it sends emails to multiple accounts why this would happen? I think I need to set a value for act223
act223 = "ACT223"
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = #{Contact.connection.quote(act223)}").uniq
this throws NameError (undefined local variable or methodact223' for #):`
in development.log.
Here is a link to the relevant table data if more table information is needed just let me know and I can add it to that page. I am looking to do some sort of a join of a field from another table. In this same model I have SignOn.prefdstw1 which gets me the same account number is there a way to Join this field in the query with the 400?
Any help or suggestions would be greatly appreciated! Thank you in advance!
find_by_sql always returns an array of model objects, so
Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]
is not an array of email addresses - it's an array of Contact objects, with only one object
You could either extract the email addresses from this, using something like
Contact.find_by_sql(["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]).collect do |contract|
contact.emal23
end
I'm not entirely sure what rails will do to the uppercased column name.
If you don't want to instantiate a whole Contact object just to get the email you could also do
Contact.where("ACT223 = ''").pluck('EMAL23')
which would return an array of emails, assuming that Rails knows that the correct table to use for this is WEBOEL23 - it's not clear to me whether that is the table for Contact (and thus you've use set_table_name to configure this) or whether Contact is just a random model unrelated to that table.
You could also drop down a level and do
Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
which will also return an array of email addresses.
Inside the each loop, target_email is a bareword variable (without quotes), but the first argument to the mailer is the string (within quotes) 'target_email'.
Remove those quotes to get to this (whitespace added for readability):
target_email.each do | email_address |
Mailer.deliver_order_distributor_approval_email(
email_address,
'Coastal Pet Online Ordering<noreply#coastalpet.com>',
"Order Confirmation Approval",
email_details
)
end
Then the mailer should have access to the email address.

Easiest way to find a value in one of three columns?

I am using twilio to provide audio conference functionality in my rails app. When I call my conference number, twilio passes on a couple of values - including 'From' which contains the caller's phone number in international format.
I have a profile for every user in my system and in my controller I am querying the profile to provide a personalised welcome message. Every profile contains between 0 and 3 numbers (primary, secondary and cellphone) and I need to check the caller's ID against those three fields in all profiles.
When I use the console on my dev machine, the following code finds the correct profile:
Profile.find_by('+44000000000')
When I upload to heroku, I use following code instead:
name = Profile.find_by(params['From']) || 'there'
Which causes an error in my app:
2014-04-03T19:20:22.801284+00:00 app[web.1]: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type bigint
2014-04-03T19:20:22.801284+00:00 app[web.1]: LINE 1: SELECT "profiles".* FROM "profiles" WHERE (+4400000000) ...
Any suggestion how that could be solved?
Thanks!
Additional information:
I think my problem is that I don't know how to query either the whole profile or three columns at once. Right now the code:
name = Profile.find_by(params['From'])
is not correct (params['From'] contains a phone number) because I am not telling rails to query the columns primary phone number, secondary phone number and cellphone. Neither am I querying the whole profile which would also be an option.
So the question basically is:
How can I change this code:
Profile.find_by(params['From'])
so that it queries either all fields in all profiles or just the three columns with phone numbers which each profile contains?
Is there something like Profile.where(:primary_number).or.where(:secondary_number)or.where(:cellphone) => params['From']
?
I am not familiar with twilio and not sure if this helps but find and find_by_attribute_name accepts array of values as options:
name = Profile.find_by([params['From'], 'there'] )
suppose params['From'] was here , This should generate:
SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`attribute` IN ('here', 'there')
Or:
If you are trying to build dynamic matcher at run time , which is called Meta-programming , you can try this code:
name = eval("Profile.find_by_#{params['From']) || 'there'}(#rest of query params here) ")
Update
First of all, i think you are not using find_by correctly!! the correct syntax is:
Model.find_by(attribute_name: value)
#e.g
Profile.find_by(phone_number: '0123456')
Which will call where and retrive one record, but passing a value will generate a condition that always passes, for example:
Model.find_by('wrong_condition')
#will generate SQL like:
SELECT `models`.* FROM `models` WHERE ('wrong_condition') LIMIT 1
#which will return the first record in the model since there is no valid condition here
Why don't you try:
Profile.where('primary_number = ? OR secondary_number = ? OR cellphone = ?', params['From'], params['From'], params['From'])
You can write your query like:
Profile.where("primary_number = ? or secondary_number = ? or cellphone = ?", params['From'])
Just double check the syntax, but that should do it.