Skip to content

Commit

Permalink
Merge pull request #6 from markakk/address_splitting
Browse files Browse the repository at this point in the history
Address splitting
  • Loading branch information
markakk authored Jan 22, 2021
2 parents 4b94c9e + ef5f5dc commit cf58925
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog

## [2.3.1] - Address splitting
### Changed
- divided sender address into different parameters
- added a ability to translate email text

## [2.3.0] - ItellaPickups API
### Added
- created ItellaPickups API
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ $items = array( // selected orders array
),
);

$translates = array( // translate text in email, recommend use english
'mail_title' => 'Pickup information',
'mail_sender' => 'Sender',
'mail_address' => 'Address (pickup from)',
'mail_phone' => 'Contact Phone',
'mail_pickup_time' => 'Pickup time',
'mail_attachment' => 'See attachment for manifest PDF.',
);

$sendTo = 'test@test.com'; // email to send courier call to
try {
$caller = new CallCourier($sendTo);
Expand All @@ -440,11 +449,16 @@ try {
->setSubject('E-com order booking') // currently it must be 'E-com order booking'
->setPickUpAddress(array( // strings to show in email message
'sender' => 'Name / Company name',
'address' => 'Street, Postcode City, Country',
'contact_phone' => '860000000',
'address_1' => 'Street str. 1',
'postcode' => '12345',
'city' => 'City name',
'country' => 'LT', // Country code
'pickup_time' => '8:00 - 17:00',
'contact_phone' => '+37060000000',
))
->setAttachment($manifest_string, true) // attachment is previously generated manifest, true - means we are passing base64 encoded string
->setItems($items) // add orders
->setTranslates($translates) // add translated email text
->callCourier() // send email
;
if ($result) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mijora/itella-api",
"description": "Itella API wrapper",
"type": "library",
"version": "2.3.0",
"version": "2.3.1",
"authors": [
{
"name": "Rimvydas",
Expand Down
50 changes: 38 additions & 12 deletions src/CallCourier.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ class CallCourier
private $isTest = false;
private $pickupAddress = array(
'sender' => '',
'address' => '',
'address_1' => '',
'postcode' => '',
'city' => '',
'country' => '',
'pickup_time' => '',
'contact_phone' => '',
);
private $subject = 'Call Itella Courier';
private $items = array();
private $translates = array(
'mail_title' => 'Pickup information',
'mail_sender' => 'Sender',
'mail_address' => 'Address (pickup from)',
'mail_phone' => 'Contact Phone',
'mail_pickup_time' => 'Pickup time',
'mail_attachment' => 'See attachment for manifest PDF.',
);

public function __construct($itella_email, $isTest = false)
{
Expand Down Expand Up @@ -84,23 +95,27 @@ public function callMailCourier()

public function buildMailBody()
{
$body = '<h2>Pickup information</h2><br/>' . PHP_EOL;
$body = '<h2>' . $this->translates['mail_title'] . '</h2><br/>' . PHP_EOL;
$body .= '<table>' . PHP_EOL;
if (!empty($this->pickupAddress['sender'])) {
$body .= "<tr><td>Sender:</td><td>" . $this->pickupAddress['sender'] . "</td></tr>" . PHP_EOL;
$body .= "<tr><td>" . $this->translates['mail_sender'] . ":</td><td>" . $this->pickupAddress['sender'] . "</td></tr>" . PHP_EOL;
}
if (!empty($this->pickupAddress['address'])) {
$body .= "<tr><td>Adress (pickup from):</td><td>" . $this->pickupAddress['address'] . "</td></tr>" . PHP_EOL;
if (!empty($this->pickupAddress['address_1'])) {
$address = $this->pickupAddress['address_1'];
$address .= (!empty($this->pickupAddress['postcode'])) ? ', ' . $this->pickupAddress['postcode'] : '';
$address .= (!empty($this->pickupAddress['city'])) ? ', ' . $this->pickupAddress['city'] : '';
$address .= (!empty($this->pickupAddress['country'])) ? ', ' . $this->pickupAddress['country'] : '';
$body .= "<tr><td>" . $this->translates['mail_address'] . ":</td><td>" . $address . "</td></tr>" . PHP_EOL;
}
if (!empty($this->pickupAddress['contact_phone'])) {
$body .= "<tr><td>Contact Phone:</td><td>" . $this->pickupAddress['contact_phone'] . "</td></tr>" . PHP_EOL;
$body .= "<tr><td>" . $this->translates['mail_phone'] . ":</td><td>" . $this->pickupAddress['contact_phone'] . "</td></tr>" . PHP_EOL;
}
if (!empty($this->pickupAddress['pickup_time'])) {
$body .= "<tr><td>Pickup time:</td><td>" . $this->pickupAddress['pickup_time'] . "</td></tr>" . PHP_EOL;
$body .= "<tr><td>" . $this->translates['mail_pickup_time'] . ":</td><td>" . $this->pickupAddress['pickup_time'] . "</td></tr>" . PHP_EOL;
}
$body .= '</table>' . PHP_EOL;
if ($this->attachment) {
$body .= "<br/>See attachment for manifest PDF." . PHP_EOL;
$body .= "<br/>" . $this->translates['mail_attachment'] . PHP_EOL;
}
return $body;
}
Expand All @@ -119,10 +134,12 @@ public function buildApiRequest()

$data['sender']['name'] = (!empty($this->pickupAddress['sender'])) ? $this->pickupAddress['sender'] : '';
$data['sender']['email'] = (!empty($this->sender_email)) ? $this->sender_email : '';
$data['sender']['address'] = (!empty($this->pickupAddress['address'])) ? $this->pickupAddress['address'] : '';
$data['sender']['address_1'] = (!empty($this->pickupAddress['address_1'])) ? $this->pickupAddress['address_1'] : '';
$data['sender']['postcode'] = (!empty($this->pickupAddress['postcode'])) ? $this->pickupAddress['postcode'] : '';
$data['sender']['city'] = (!empty($this->pickupAddress['city'])) ? $this->pickupAddress['city'] : '';
$data['sender']['country'] = (!empty($this->pickupAddress['country'])) ? $this->pickupAddress['country'] : '';
$data['sender']['phone'] = (!empty($this->pickupAddress['contact_phone'])) ? $this->pickupAddress['contact_phone'] : '';
$data['pickup_time'] = (!empty($this->pickupAddress['pickup_time'])) ? $this->pickupAddress['pickup_time'] : '';
$data['total_items'] = (!empty($this->items)) ? count($this->items) : 0;
$data['items'] = (!empty($this->items)) ? $this->items : array();

return $data;
Expand All @@ -131,9 +148,12 @@ public function buildApiRequest()
/**
* $pickup = array(
* 'sender' => 'Name / Company name',
* 'address' => 'Street, Postcode City, Country',
* 'address_1' => 'Street st. 1',
* 'postcode' => '12345',
* 'city' => 'City name',
* 'country' => 'LT',
* 'pickup_time' => '8:00 - 17:00',
* 'contact_phone' => '865465411',
* 'contact_phone' => '+37060000000',
* );
*/
public function setPickUpAddress($pickupAddress)
Expand Down Expand Up @@ -175,4 +195,10 @@ public function setItems($items = [])
$this->items = $items;
return $this;
}

public function setTranslates($translates)
{
$this->translates = array_merge($this->translates, $translates);
return $this;
}
}

0 comments on commit cf58925

Please sign in to comment.