From 514a86305f83ea457f563076a24795bea72a6361 Mon Sep 17 00:00:00 2001 From: Fachruzi Ramadhan Date: Mon, 22 Jan 2018 22:25:22 +0700 Subject: [PATCH] Add method UpdateProduct, GetOrders, GetOrder, And GetOrderItems --- README.md | 20 ++++++++- src/LazadaClient.php | 98 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad49afb..688cef2 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $lazada = new ramadhan\LazadaClient( [ ```php // Use this call to get all or a range of products. // $parameters = array('Limit' => 20, 'Offset' => 0) -$lazada->GetProducts($parameters = array()); +$lazada->GetProducts($parameters = []); ``` ### Create product @@ -58,4 +58,22 @@ $lazada->MigrateImages($imagesUrl); //Use this call to set the images for an existing product by associating one or more image URLs with it $lazada->SetImages($xmlContent); +//Use this call to update attributes or SKUs of an existing product. +$lazada->UpdateProduct($xmlContent); + +//Use this call to remove an existing product. +$lazada->RemoveProduct($sellerSku = []); + +//Use this call to get the customer details for a range of orders. +$lazada->GetOrders($parameters = []); + +//Use this call to get the list of items for a single order. +$lazada->GetOrder($orderId); + +//Use this call to get the item information of an order. +$lazada->GetOrderItems($orderId); + + + + ``` \ No newline at end of file diff --git a/src/LazadaClient.php b/src/LazadaClient.php index 5148c2d..6448b93 100644 --- a/src/LazadaClient.php +++ b/src/LazadaClient.php @@ -159,7 +159,7 @@ private function xmlToArray( $xmlstring ) { * @param $array array to convert * @param $customRoot [$customRoot = 'AmazonEnvelope'] * - * @return sting + * @return string */ private function arrayToXml( array $array, $customRoot = 'Request' ) { return ArrayToXml::convert( $array, $customRoot ); @@ -246,6 +246,44 @@ public function CreateProduct( $xmlContent ) { return $response; } + /** + * A method to Update Products + * + * @param $xmlContent + * + * @return mixed + */ + public function UpdateProduct( $xmlContent ) { + $response = $this->request( array( 'Action' => 'UpdateProduct' ), 'POST', $xmlContent ); + + return $response; + } + + /** + * A method to Remove Products + * + * @param array $sellerSku + * + * @return mixed + * @throws Exception + */ + public function RemoveProduct( $sellerSku = array() ) { + + if ( count( $sellerSku ) > 100 ) { + throw new Exception( 'Maximum amount of SKU\'s for this call is 100' ); + } + + foreach ( $sellerSku as $sku ) { + $skuList['Skus']['Sku']['SellerSku'][] = $sku; + } + + $xmlContent = $this->arrayToXml( [ 'Product' => $skuList ] ); + + $response = $this->request( array( 'Action' => 'RemoveProduct' ), 'POST', $xmlContent ); + + return $response; + } + /** * A method to Get Response * @@ -298,4 +336,62 @@ public function SetImages( $xmlContent ) { return $response; } + + /** + * A method to Get Orders + * + * @param array $parameters + * + * @return mixed + * @throws Exception + */ + public function GetOrders( $parameters = [] ) { + $acceptKey = array( 'CreatedAfter', 'CreatedBefore', 'UpdatedAfter', 'UpdatedBefore', 'Search', 'Filter', 'Limit', 'Offset', 'Status', 'SortBy', 'SortDirection' ); + + $requestParameter = array( 'Action' => 'GetOrders' ); + + foreach ( $parameters as $key => $parameter ) { + if ( in_array( $key, $acceptKey ) ) { + $requestParameter[ $key ] = $parameter; + } else { + throw new Exception( 'We don\'t accept the ' . $key . ' parameter' ); + } + } + + $response = $this->request( $requestParameter, 'GET' ); + + return $response; + } + + /** + * A method to Get Order + * + * @param $orderId + * + * @return mixed + */ + public function GetOrder( $orderId ) { + + $requestParameter = array( 'Action' => 'GetOrder', 'OrderId' => $orderId ); + + $response = $this->request( $requestParameter, 'GET' ); + + return $response; + } + + /** + * A method to Get Order Items + * + * @param $orderId + * + * @return mixed + */ + public function GetOrderItems( $orderId ) { + + $requestParameter = array( 'Action' => 'GetOrderItems', 'OrderId' => $orderId ); + + $response = $this->request( $requestParameter, 'GET' ); + + return $response; + } } \ No newline at end of file