Skip to content

Commit

Permalink
url_friendly_id
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Feb 12, 2020
1 parent f26b44f commit a753fbc
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function contacts()
{
return $this->request->handleWithExceptions(function () {

$builder = new CustomerContactBuilder($this->request, $this->{$this->primaryKey});
$builder = new CustomerContactBuilder($this->request, $this->{$this->url_friendly_id});

return $builder->get();
});
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CustomerInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function book($send_email = false)
];
}

return $this->request->client->post("{$this->entity}/{$this->{$this->primaryKey}}/book" . $query, [
return $this->request->client->post("{$this->entity}/{$this->{$this->url_friendly_id}}/book" . $query, [
'json' => $body,
])
->getBody()
Expand Down
4 changes: 2 additions & 2 deletions src/Models/DraftOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class DraftOrder extends Model
public function getPDF()
{
return $this->request->handleWithExceptions( function () {
return $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}.pdf" )->getBody()
->getContents();
return $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}.pdf")->getBody()
->getContents();
} );
}
}
4 changes: 2 additions & 2 deletions src/Models/DraftPurchaseOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class DraftPurchaseOrder extends Model
public function getPDF()
{
return $this->request->handleWithExceptions( function () {
return $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}.pdf" )->getBody()
->getContents();
return $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}.pdf")->getBody()
->getContents();
} );
}
}
4 changes: 2 additions & 2 deletions src/Models/Lot.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function variations( $variation_id = 1001 )
{
return $this->request->handleWithExceptions( function () use ( $variation_id ) {

$response = $this->request->client->get( "variations/{$this->{$this->primaryKey}}/variation-matrix" );
$response = $this->request->client->get("variations/{$this->{$this->url_friendly_id}}/variation-matrix");

$html = (string) $response->getBody();

Expand All @@ -33,7 +33,7 @@ public function location()
{
return $this->request->handleWithExceptions( function () {

$response = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/locations" );
$response = $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}/locations");

return collect( json_decode( (string) $response->getBody() )->lot_locations );

Expand Down
12 changes: 6 additions & 6 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Order extends Model
public function getPDF()
{
return $this->request->handleWithExceptions( function () {
return $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}.pdf" )->getBody()
return $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}.pdf")->getBody()
->getContents();
} );
}
Expand All @@ -32,7 +32,7 @@ public function reopen()

return $this->request->handleWithExceptions( function () {

return $this->request->client->post( "{$this->entity}/{$this->{$this->primaryKey}}/reopen" )
return $this->request->client->post("{$this->entity}/{$this->{$this->url_friendly_id}}/reopen")
->getBody()
->getContents();
} );
Expand All @@ -42,7 +42,7 @@ public function createShipment()
{
return $this->request->handleWithExceptions(function () {

$response = json_decode((string)$this->request->client->post("{$this->entity}/{$this->{$this->primaryKey}}/create-shipment")
$response = json_decode((string)$this->request->client->post("{$this->entity}/{$this->{$this->url_friendly_id}}/create-shipment")
->getBody());

return new OrderShipment($this->request, $response->order_shipment);
Expand All @@ -56,7 +56,7 @@ public function shipments()
$builder = new OrderShipmentBuilder($this->request);

return $builder->get([
['order_number', '=', $this->{$this->primaryKey}],
['order_number', '=', $this->{$this->url_friendly_id}],
]);
});
}
Expand All @@ -71,7 +71,7 @@ public function convertToInvoice($book = false)
{
return $this->request->handleWithExceptions(function () use ($book) {

$response = json_decode((string)$this->request->client->post("{$this->entity}/{$this->{$this->primaryKey}}/convert-to-invoice?book=" . (($book === true) ? 'true' : 'false'))
$response = json_decode((string)$this->request->client->post("{$this->entity}/{$this->{$this->url_friendly_id}}/convert-to-invoice?book=" . (($book === true) ? 'true' : 'false'))
->getBody());

$invoice = (new CustomerInvoiceBuilder($this->request))->find($response->invoice_id);
Expand All @@ -85,7 +85,7 @@ public function notes()
return $this->request->handleWithExceptions(function () {

$builder = new OrderNoteBuilder($this->request);
$builder->setEntity(str_replace(':number', $this->{$this->primaryKey}, $builder->getEntity()));
$builder->setEntity(str_replace(':number', $this->{$this->url_friendly_id}, $builder->getEntity()));

return $builder->get();
});
Expand Down
4 changes: 2 additions & 2 deletions src/Models/OrderShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function markShipped()
{
return $this->request->handleWithExceptions(function () {

return $this->request->client->post("orders/shipments/{$this->{$this->primaryKey}}/mark-shipped", [
return $this->request->client->post("orders/shipments/{$this->{$this->url_friendly_id}}/mark-shipped", [

'json' => [

'pick' => true,
]
],
])
->getBody()
->getContents();
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function inventoryMatrix( $location_id = null, array $filter = null )
}
}

$response = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/variation-matrix" .
$query );
$response = $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}/variation-matrix" .
$query);

$html = (string) $response->getBody();

Expand All @@ -58,7 +58,7 @@ public function variations( $variation_id = 1001 )
{
return $this->request->handleWithExceptions( function () use ( $variation_id ) {

$response = $this->request->client->get( "variations/{$this->{$this->primaryKey}}/variation-matrix" );
$response = $this->request->client->get("variations/{$this->{$this->url_friendly_id}}/variation-matrix");

$html = (string) $response->getBody();

Expand All @@ -70,7 +70,7 @@ public function location($number = null)
{
return $this->request->handleWithExceptions(function () use ($number) {

$response = json_decode((string)$this->request->client->get("{$this->entity}/{$this->{$this->primaryKey}}/locations" . (($number !== null) ? '/' . $number : ''))->getBody());
$response = json_decode((string)$this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}/locations" . (($number !== null) ? '/' . $number : ''))->getBody());

if (isset($response->product_locations)) {

Expand Down Expand Up @@ -109,7 +109,7 @@ public function fields()
return $this->request->handleWithExceptions( function () {

$response =
$this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/fields" );
$this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}/fields");

return collect( json_decode( (string) $response->getBody() )->field_values );

Expand Down
4 changes: 2 additions & 2 deletions src/Models/ProductionOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ProductionOrder extends Model
public function getPDF()
{
return $this->request->handleWithExceptions( function () {
return $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}.pdf" )->getBody()
->getContents();
return $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}.pdf")->getBody()
->getContents();
} );
}
}
10 changes: 5 additions & 5 deletions src/Models/PurchaseOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PurchaseOrder extends Model
public function getPDF()
{
return $this->request->handleWithExceptions( function () {
return $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}.pdf" )->getBody()
->getContents();
return $this->request->client->get("{$this->entity}/{$this->{$this->url_friendly_id}}.pdf")->getBody()
->getContents();
} );
}

Expand All @@ -23,9 +23,9 @@ public function reopen()

return $this->request->handleWithExceptions( function () {

return $this->request->client->post( "{$this->entity}/{$this->{$this->primaryKey}}/reopen" )
->getBody()
->getContents();
return $this->request->client->post("{$this->entity}/{$this->{$this->url_friendly_id}}/reopen")
->getBody()
->getContents();
} );
}
}
4 changes: 2 additions & 2 deletions src/Models/Variation/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function options()
{
$options = new TypeOptionBuilder( $this->request );
$old_entity = $options->getEntity();
$new_entity = $options->setEntity( str_replace( ':variation_number', $this->variation_id, $old_entity ) );
$options->setEntity( str_replace( ':type_number', $this->{$this->primaryKey}, $new_entity ) );
$new_entity = $options->setEntity(str_replace(':variation_number', $this->variation_id, $old_entity));
$options->setEntity(str_replace(':type_number', $this->{$this->url_friendly_id}, $new_entity));

return $options;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Utils/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Model
{
protected $entity;
protected $primaryKey;
protected $url_friendly_id;
protected $modelClass = self::class;
protected $fillable = [];

Expand Down Expand Up @@ -45,7 +46,7 @@ protected function setAttribute( $attribute, $value )
{
if ($attribute === $this->primaryKey) {

$value = rawurlencode(rawurlencode($value));
$this->url_friendly_id = rawurldecode(rawurldecode($value));
}

$this->{$attribute} = $value;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function delete()
{
return $this->request->handleWithExceptions( function () {

return $this->request->client->delete( "{$this->entity}/{$this->{$this->primaryKey}}" );
return $this->request->client->delete("{$this->entity}/{$this->{$this->url_friendly_id}}");
} );
}

Expand All @@ -85,9 +86,9 @@ public function update( $data = [] )

return $this->request->handleWithExceptions( function () use ( $data ) {

$response = $this->request->client->put( "{$this->entity}/{$this->{$this->primaryKey}}", [
$response = $this->request->client->put("{$this->entity}/{$this->{$this->url_friendly_id}}", [
'json' => $data,
] );
]);

$responseData = collect( json_decode( (string) $response->getBody() ) );

Expand Down

0 comments on commit a753fbc

Please sign in to comment.