Skip to content

Commit

Permalink
Add method UpdateProduct, GetOrders, GetOrder, And GetOrderItems
Browse files Browse the repository at this point in the history
  • Loading branch information
mabuak committed Jan 22, 2018
1 parent 0011271 commit 514a863
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);




```
98 changes: 97 additions & 1 deletion src/LazadaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 514a863

Please sign in to comment.