OpenCart: How to disable province display on the invoice? - php

Although we have provinces in the Netherlands we do not use them in an address (postcode is the most important thing with us). For this reason I disabled the province in the OpenCart checkout process. It still displays however on the invoice I print out, and since no province is filled in, the first province on the list is standard displayed, which is often the wrong one. For this reason I want to take away the province from the OpenCart invoice.
So I opened admin/view/template/sale/order_invoice.tpl and searched for the relevant part. Unfortunately, the address is referred to as $order['payment_address'] and $order['shipping_address']. Somehow, that code prints out the address including breaklines (<br />).
My question is now: how do I disable just the province in the customer address displayed on the invoice?

Open up also the controller class admin/controller/sale/order.php and check for the relevant parts where the $order['payment_address'] and $order['shipping_address'] are filled and comment out the appropriate lines (where the province is added to the string/array).
The same thing should also be done in the frontend - catalog/controller/account/order.php.
Should be something like this:
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
//'{zone}',
//'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
//'zone' => $order_info['payment_zone'],
//'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
You would probably also have to change the format line from
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
to (see the /* and */ comment):
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' /*. "\n" . '{zone}'*/ . "\n" . '{country}';
To the comment:
Now I am not sure, it is possible that the addresses format is stored within an order after it is created. In that case, change the appropriate lines in controllers to these:
/*if ($order_info['payment_address_format']) { // <-- same for $order_info['shipping_address_format']
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}*/
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' /*. "\n" . '{zone}'*/ . "\n" . '{country}';

For me this solution works:
edit in: admin/controller/sale/order.php
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
//'zone' => $order_info['shipping_zone'],
//'zone_code' => $order_info['shipping_zone_code'],
'zone' => '',
'zone_code' => '',
'country' => $order_info['shipping_country']
First it didn't work, i thought it was a cache problem and clear all the cache, but it did not work. Then I searched on the request order_invoice and this was also used in /system/storage/modification/admin/controller/sale. After clear the modification cache it worked!

Related

Error Notice Array to string conversion after updating CF7

I need help on below error
Notice: Array to string conversion in /www/test_123/public/wp-content/plugins/test-functions/match-functions.php on line 302
Below is written on 301 and 302 lines, I am not sure what is wrong. It is happening when I am updating the contact form 7 to latest version, but on 5.1.6 there is no such error.
$location = WC_Geolocation::geolocate_ip();
$p1_dob = $your_birth_year . "-" . $your_birth_month . "-" . $your_birth_day;
$p2_dob = $partners_birth_year . "-" . $partners_birth_month . "-" . $partners_birth_day;
$pmf_love_match_html_url = "https://primary.astrowebserver.net/v2/reports/CreateShortHTML/REL-NEW-DUALMATCH/?APIKEY=012bc72f-093a-4617-9432-0cbb55662ad7&P1FirstName=" . $your_first_name . "&P1DOB=" . $p1_dob . "&P1Sex=" . $your_gender . "&P1Country=" . $location['country'] . "&P2FirstName=" . $partners_first_name . "&P2DOB=" . $p2_dob . "&P2Sex=" . $partners_gender . "&P2Country=" . $location['country'];
You are appending different variables into a string. Some of those variables are not of type string (but are instead an array), and thus cannot be appended to a string.
$string_val = "foo";
$result = "-" . $string_val . "-" // works fine
$array_val = [
"foo" => "bar",
"bar" => "foo",
];
$result = "-" . $array_val . "-" // 'Notice: Array to string conversion ...'

What am I doing wrong when signing my request? AWS SignatureV4 and PHP

I've been stuck on this problem for like two days. I've written a Python script which makes a PUT request to AWS Pinpoint service.
Pinpoint like many other AWS services requires a signature authentification on requests, which I managed to handle in Python.
Right now I'm trying to translate my script into a PHP service for Symfony. When I run my first request to AWS pinpoint I get this:
The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
The Canonical String for this request should have been\n'PUT\n/v1/apps/.../endpoints/...\n\ncontent-type:application/json\nhost:pinpoint.eu-west-1.amazonaws.com\nx-amz-content-sha256:de98d86577f0e1...655e6de27154af1c05ab34\nx-amz-date:20191226T151542Z\nx-amz-security-token:IQoJb....\nx-amz-user-agent:aws-amplify/1.1.2 react-native aws-amplify/1.1.2 react-native callback\n\ncontent-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent\n0240a9479d0a66d74eaae42dc...95247aaa800fcbe5cf2
The String-to-Sign should have been
'AWS4-HMAC-SHA256\n20191226T151542Z\n20191226/eu-west-1/mobiletargeting/aws4_request\nb2c451534fe370503ecf4068b45c...63e91280cc3187ae3230034107
So I already checked if my Canonical String was wrong, it is the exact same AWS is asking. The String-to-Sign is different by the Canonical String hash.
Here's my headers function
public function create_headers($data,\DateTime $time,$canonical_uri,$method,$to_api=null)
{
$amz_date = $time->format('Ymd\THis\Z');
$date_stamp = $time->format('Ymd');
$payload_hash = hash('sha256',$data);#utf8_encode($data));
$canonical_querystring = "";
$canonical_headers = 'content-type:' . $this->content_type . '\n' . 'host:' . $this->host . '\n' . 'x-amz-content-sha256:' . $payload_hash . '\n' . 'x-amz-date:' . $amz_date . '\n' . 'x-amz-security-token:' . $this->security_token . '\n' . 'x-amz-user-agent:aws-amplify/1.1.2 react-native aws-amplify/1.1.2 react-native callback' . '\n';
$signed_headers = 'content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent';
$canonical_request = $method . '\n' . $canonical_uri . '\n' . $canonical_querystring . '\n' . $canonical_headers . '\n' . $signed_headers . '\n' . $payload_hash;
echo '<br><br>';
print_r(str_replace('\n','<br>',$canonical_request));
#var_dump($canonical_request);
$algorithm = 'AWS4-HMAC-SHA256';
$credential_scope = "{$date_stamp}/{$this->region}/{$this->service}/aws4_request";
#$date_stamp . '/' . $this->region . '/' . $this->service . '/' . 'aws4_request';
#$credential_scope = $this->createScope($date_stamp,$this->region,$this->service);
echo '<br><br>';
#$string_to_sign = $algorithm . '\n' . $amz_date . '\n' . $credential_scope . '\n' . hash('sha256', utf8_encode($canonical_request));
$hash = hash('sha256', $canonical_request);
$string_to_sign = "AWS4-HMAC-SHA256\n{$amz_date}\n{$credential_scope}\n{$hash}";
print_r(str_replace('\n','<br>',$string_to_sign));
echo '<br><br>';
$signing_key = $this->get_signature_key($this->secret_key,$date_stamp,$this->region,$this->service);
$signature = hash_hmac('sha256',$string_to_sign,$signing_key);
$authorization_header = $algorithm . ' ' . 'Credential=' . $this->access_key . '/' . $credential_scope . ', ' . 'SignedHeaders=' . $signed_headers . ', ' . 'Signature=' . $signature;
$headers = array(
'host'=> $this->host,
'content-type'=> $this->content_type,
'x-amz-user-agent'=> 'aws-amplify/1.1.2 react-native aws-amplify/1.1.2 react-native callback',
'x-amz-content-sha256'=> $payload_hash,
'x-amz-security-token'=> $this->security_token,
'x-amz-date'=> $amz_date,
'authorization'=> $authorization_header
);
$this->s->headers = $headers;
return $headers;
}
I've been looking for my error for days but I think I need someone with a fresh eye...
Thank you!
After hours and hours of questionning myself, I've finally found why I was getting that error.
In PHP "\n" and '\n' doesn't have the same meaning.
"\n" is a real line break - which is what AWS is asking.
'\n' is a string of \ and n characters.
AWS API is still pretty shit though.

Laravel Scout and Elastic Search Don't Work in Tests

I have elastic search working when not in a testing environment. However when I create a model in a test for some reason it does not work. I have tried running it with the queue and without the queue. I can see that the job gets created and that the job runs before making the call. However, I am able to pull things that are already in the database in the test code. Any ideas why it would not work in testing?
This is my test code
$user = $this->newLoggedInUser();
$invoice = factory(App\Invoice::class)->create(['account_id' => $user->account_id]);
$this->get($this->url() . '?q=' . $invoice->title, $this->userAuthHeader($user))
->seeJson([
'Title' => 'Invoice: ' . $invoice->number . ($invoice->title ? ' - ' . $invoice->title : ''),
'Description' => 'Customer: ' . $invoice->customer->name,
'Type' => 'Invoice',
])
->assertResponseStatus(200);
I found that I had to add a slight delay to the get call as the index was not updated before the call was made. So I added sleep(1) and that fixed it. Also, I found that it is best to specify a separate index for the testing environment in the config.
$user = $this->newLoggedInUser();
$invoice = factory(App\Invoice::class)->create(['account_id' => $user->account_id]);
sleep(1);
$this->get($this->url() . '?q=' . $invoice->title, $this->userAuthHeader($user))
->seeJson([
'Title' => 'Invoice: ' . $invoice->number . ($invoice->title ? ' - ' . $invoice->title : ''),
'Description' => 'Customer: ' . $invoice->customer->name,
'Type' => 'Invoice',
])
->assertResponseStatus(200);

Twitter Streaming 401 Unauthorized OAuth

I'm trying to create a script that uses the twitter streaming api to keep a tab on tweets with a certain hash-tag.
Whenever I try creating a request though, I always get a 401 Unauthorized return. Can anyone help me figure out what I'm doing incorrectly?
I tried to follow twitter's api to the dot, but apparently I'm doing something wrong. The code I have is below.
$base_url_string = urlencode($base_url);
$parameter_string = urlencode('oauth_consumer_key') . '=' . urlencode($consumer_key) . '&'
. urlencode('oauth_nonce') . '=' . urlencode($nonce) . '&'
. urlencode('oauth_signature_method') . '=' . urlencode($signature_method) . '&'
. urlencode('oauth_timestamp') . '=' . urlencode($timestamp) . '&'
. urlencode('oauth_token') . '=' . urlencode($token) . '&'
. urlencode('oauth_version') . '=' . urlencode($version) . '&'
. urlencode('track') . '=' . urlencode('#kitten');
$signature_base_string = $method . "&" . $base_url_string . "&" . urlencode($parameter_string);
$signature = base64_encode(hash_hmac('sha1', $signature_base_string, $secret, true));
$fp = fsockopen("ssl://stream.twitter.com", 443, $errno, $errstr, 30);
if (!$fp) {
print "$errstr ($errno)\n";
} else {
$request = $method . " /1.1/statuses/filter.json?" . urlencode("track") . "=" . urlencode("#kitten") . " HTTP/1.1\r\n";
$request .= "Host: stream.twitter.com\r\n";
$request .= 'Authorization: OAuth'
. ' oauth_consumer_key="' . $consumer_key . '",'
. ' oauth_nonce="' . $nonce . '",'
. ' oauth_signature="' . $signature . '",'
. ' oauth_signature_method="' . $signature_method . '",'
. ' oauth_timestamp="' . $timestamp . '",'
. ' oauth_token="' . $token . '",'
. ' oauth_version="' . $version . '"'
. "\r\n\r\n";
print $request . "</br>";
fwrite($fp, $request);
while (!feof($fp)) {
$json = fgets($fp);
echo $json;
$data = json_decode($json, true);
if ($data) {
print $data;
}
}
print 'exiting...';
fclose($fp);
}
Ok so I figured this all out. It was a combination of poor string manipulation and not Percent Encoding everything. Both the keys and values of the OAuth string must be Percent encoded. I had done that in the signature, but not in the actual request. Once I fixed that, the request got through and I was connected to the Twitter Streaming API.

Facebook batch request on /me/photos does not schedule my posts

I was using the facebook graph api without batch requests to schedule posts of pictures to my pages.
Now I am trying to work with batch requests but I have an issue, the photo are posted immediately, even if I set the parameters to delay it.
Example:
$args = array(
'message' => $this->message,
);
$args['published'] = false;
$args['scheduled_publish_time'] = strtotime($this->programmed_dt);
$appsecretProof = hash_hmac('sha256', $facebookPage['access_token'], self::APP_SECRET);
$queries[] = array('method' => 'POST',
'relative_url' => urlencode('/' . $facebookPage['id'] . '/photos?access_token=' . $facebookPage['access_token'] . '&appsecret_proof=' . $appsecretProof),
'body' => $args,
'attached_files' => 'file1',
);
$params['file1'] = '#' . realpath('images/' . $timestamp . '.jpg');
$urlPost = '?batch=' . json_encode($queries) . '&access_token=' . self::ACCESS_TOKEN;
$res = $this->fb->api($urlPost, 'POST', $params);
I have a response with the post ID, but the photo post is not scheduled ... Do you see anything wrong?
Thanks.
Found:
published and scheduled_publish_time should be passed to the relative_url
$relativeUrl = '/' . $facebookPage['id'] . '/photos?published=' . (string) $args['published'];
$relativeUrl .= $args['published'] ? '' : '&scheduled_publish_time=' . $args['scheduled_publish_time'] . '&access_token=' . $facebookPage['access_token'] . '&appsecret_proof=' . $appsecretProof;

Categories