update exception
This commit is contained in:
		
							parent
							
								
									6cab863d14
								
							
						
					
					
						commit
						498471d50b
					
				|  | @ -0,0 +1,23 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace IpSupply\SyncOrder\Config; | ||||||
|  | 
 | ||||||
|  | use Magento\Store\Model\StoreManagerInterface; | ||||||
|  | 
 | ||||||
|  | class GetBaseURL | ||||||
|  | { | ||||||
|  |     protected $storeManagerInterface; | ||||||
|  | 
 | ||||||
|  |     static function get() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||||||
|  |         $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface'); | ||||||
|  |         return $storeManager->getStore()->getBaseUrl(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function __construct(StoreManagerInterface $storeManagerInterface) | ||||||
|  |     { | ||||||
|  |         $this->storeManagerInterface = $storeManagerInterface; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -13,10 +13,10 @@ class Buyer implements \JsonSerializable | ||||||
|     { |     { | ||||||
|         $this->username = $order->getCustomerEmail() ?? null; |         $this->username = $order->getCustomerEmail() ?? null; | ||||||
|         $this->fullName = $order->getCustomerName() ?? null; |         $this->fullName = $order->getCustomerName() ?? null; | ||||||
|         $this->primaryPhone = $order->getBillingAddress()?->getTelephone() ?? $order->getShippingAddress()->getTelephone(); |         $this->primaryPhone = $order->getBillingAddress()?->getTelephone() ?? $order->getShippingAddress()?->getTelephone(); | ||||||
|         $this->email = |         $this->email = | ||||||
|             $order->getBillingAddress()?->getEmail() |             $order->getBillingAddress()?->getEmail() | ||||||
|             ?? $order->getShippingAddress()->getEmail(); |             ?? $order->getShippingAddress()?->getEmail(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function jsonSerialize(): mixed |     public function jsonSerialize(): mixed | ||||||
|  |  | ||||||
|  | @ -3,7 +3,9 @@ | ||||||
| namespace IpSupply\SyncOrder\Sync; | namespace IpSupply\SyncOrder\Sync; | ||||||
| 
 | 
 | ||||||
| use GuzzleHttp\Client; | use GuzzleHttp\Client; | ||||||
|  | use GuzzleHttp\Exception\ClientException; | ||||||
| use GuzzleHttp\Psr7\Request as GuzzRequest; | use GuzzleHttp\Psr7\Request as GuzzRequest; | ||||||
|  | use IpSupply\SyncOrder\Config\GetBaseURL; | ||||||
| use IpSupply\SyncOrder\Config\Getter; | use IpSupply\SyncOrder\Config\Getter; | ||||||
| 
 | 
 | ||||||
| final class Index | final class Index | ||||||
|  | @ -41,7 +43,7 @@ final class Index | ||||||
| 
 | 
 | ||||||
|             $payload = [ |             $payload = [ | ||||||
|                 ...$orderDetail->jsonSerialize(), |                 ...$orderDetail->jsonSerialize(), | ||||||
|                 'url' => $this->_config['url'], |                 'url' => GetBaseURL::get(), | ||||||
|                 'source' => 'magento', |                 'source' => 'magento', | ||||||
|                 'details' => [], |                 'details' => [], | ||||||
|                 'buyer' => $buyer->jsonSerialize(), |                 'buyer' => $buyer->jsonSerialize(), | ||||||
|  | @ -50,14 +52,26 @@ final class Index | ||||||
|             foreach ($order->getAllVisibleItems() as $item) { |             foreach ($order->getAllVisibleItems() as $item) { | ||||||
|                 $payload['details'][] = (new Detail($item))->jsonSerialize(); |                 $payload['details'][] = (new Detail($item))->jsonSerialize(); | ||||||
|             } |             } | ||||||
|             $this->_client()->post($this->_config['url'], [ |             try { | ||||||
|                 'json' => $payload |                 $response = $this->_client()->post($this->_config['url'], [ | ||||||
|             ]); |                     'json' => $payload | ||||||
| 
 |                 ]); | ||||||
|             return json_encode($payload); |                 $statusCode = $response->getStatusCode(); | ||||||
|  |                 $responseContent = $response->getBody()->getContents(); | ||||||
|  |             } catch (ClientException $ex) { | ||||||
|  |                 $statusCode = $ex->getResponse()->getStatusCode(); | ||||||
|  |                 $responseContent = $ex->getResponse()->getBody()->getContents(); | ||||||
|  |             } finally { | ||||||
|  |                 return json_encode([ | ||||||
|  |                     'guzzle' => [ | ||||||
|  |                         'statusCode' => $statusCode, | ||||||
|  |                         'response' => $responseContent | ||||||
|  |                     ], | ||||||
|  |                     'payload' => $payload | ||||||
|  |                 ]); | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             throw new \ErrorException('$order is not instance \Magento\Sales\Model\Order\Interceptor'); |             throw new \ErrorException('$order is not instance \Magento\Sales\Model\Order\Interceptor'); | ||||||
|             return false; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue