Skip to content

Commit

Permalink
allow for address line 2 in postmates delivery call
Browse files Browse the repository at this point in the history
  • Loading branch information
CupNoodles committed Jun 22, 2021
1 parent ec7050d commit 643e0e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ public function updatePostmatesDeliveryCost($location){

// if $location->coveredArea is of the base type but has delivery_service == postmates, replace it with the new PostmatesCoveredAreaClass
if(is_array($location->coveredArea()->conditions) && isset($location->coveredArea()->conditions[0])){
if($location->coveredArea()->conditions[0]['delivery_service'] == 'postmates' &&
get_class($location->coveredArea()) == 'Igniter\Local\Classes\CoveredArea'){
if($location->coveredArea()->conditions[0]['delivery_service'] == 'postmates'
&& is_object($location->coveredArea()) && get_class($location->coveredArea()) == 'Igniter\Local\Classes\CoveredArea'){

if ($areaId = (int)$location->getSession('area')){
$area = $location->getModel()->findDeliveryArea($areaId);
Expand Down
17 changes: 10 additions & 7 deletions classes/PostmatesCoveredArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Igniter\Flame\Location\Contracts\AreaInterface;

use CupNoodles\Postmates\Models\PostmatesSettings;

use ApplicationException;
use Igniter\Flame\Database\Model;
/**
* @method getLocationId()
Expand Down Expand Up @@ -35,21 +35,23 @@ public function deliveryAmount($cartTotal)
if($user_position && ( !isset($this->oldPosition) || $user_position != $this->oldPosition )){
$this->oldPosition = $user_position;
$delivery_cost_estimate = $this->curl_postmates_delivery_quote($user_position, $cartTotal);

if($delivery_cost_estimate >= 0 ){
// amount condition value is added as a surcharge
$delivery_cost_estimate += $this->getConditionValue('amount', $cartTotal);
session(['postmates_delivery_quote' => $delivery_cost_estimate]);

return $delivery_cost_estimate;
}
else{
return 0;
}
}
elseif($user_position){
elseif($user_position && session('postmates_delivery_quote') > 0){
return session('postmates_delivery_quote');

}

return -1;
return 0;

}

Expand All @@ -59,10 +61,11 @@ public function curl_postmates_delivery_quote($user_position, $cartTotal){
$user_position->format();
// Postmates specifically requests comma-separated address formatting, so remove any potential commas in existing address fields
$street_address = str_replace(',', ' ', $user_position->getStreetNumber() . ' ' . $user_position->getStreetName());
$address_2 = isset($user_position->data['subpremise']) ? $user_position->data['subpremise'] : '';
$city = str_replace(',', ' ', $user_position->getSubLocality());
$state = str_replace(',', ' ', $user_position->getLocality());
$postcode = str_replace(',', ' ', $user_position->getPostalCode());
$user_address = $street_address . ', ' . $city . ', ' . $state . ', ' . $postcode;
$user_address = $street_address . ' ' . $address_2 . ' , ' . $city . ', ' . $state . ', ' . $postcode;

// get location address string
$location_address = $this->location->getModel()->getAddress();
Expand Down Expand Up @@ -105,7 +108,7 @@ public function curl_postmates_delivery_quote($user_position, $cartTotal){
return $result['fee'] / 100;
}
else{
//
flash()->alert('Postmates Delivery Quote failed. ' . $result['message']);
return -1;
}
}
Expand Down

0 comments on commit 643e0e2

Please sign in to comment.