Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple pieces in shipment request #1

Closed
ljudina opened this issue Jul 30, 2014 · 3 comments
Closed

Multiple pieces in shipment request #1

ljudina opened this issue Jul 30, 2014 · 3 comments

Comments

@ljudina
Copy link

ljudina commented Jul 30, 2014

Hello,

Congratulations on DHL-APi, very nice work.
One question. How can you add multiple shipment pieces in shipment request.
For example:

$sample->ShipmentDetails->NumberOfPieces = '2';
$sample->ShipmentDetails->Pieces->Piece->PieceID = '1';
$sample->ShipmentDetails->Pieces->Piece->PackageType = 'EE';
$sample->ShipmentDetails->Pieces->Piece->Weight = '10.0';
$sample->ShipmentDetails->Pieces->Piece->DimWeight = '1200.0';
$sample->ShipmentDetails->Pieces->Piece->Width = '100';
$sample->ShipmentDetails->Pieces->Piece->Height = '200';
$sample->ShipmentDetails->Pieces->Piece->Depth = '300';
$sample->ShipmentDetails->Pieces->Piece->PieceID = '2';
$sample->ShipmentDetails->Pieces->Piece->PackageType = 'EE';
$sample->ShipmentDetails->Pieces->Piece->Weight = '15.0';
$sample->ShipmentDetails->Pieces->Piece->DimWeight = '1100.0';
$sample->ShipmentDetails->Pieces->Piece->Width = '50';
$sample->ShipmentDetails->Pieces->Piece->Height = '50';
$sample->ShipmentDetails->Pieces->Piece->Depth = '100';

But it accepts only one piece. How can I add another one?

Thank you for your time.

Sincerely,

Marko Jovanovic

@alfallouji
Copy link
Owner

Hello Marko,

Thanks for your feedback.

I added multivalues handling for entities and datatypes.

Therefore, you should be able now to do the following :

use DHL\Datatype\GB\Piece;

// Test a ShipmentRequestRequest using DHL XML API
$sample = new ShipmentRequest();

// Set values of the request
$sample->ShipmentDetails->NumberOfPieces = 2;

$piece = new Piece();
$piece->PieceID = '1';
$piece->PackageType = 'EE';
$piece->Weight = '5.0';
$piece->DimWeight = '600.0';
$piece->Width = '50';
$piece->Height = '100';
$piece->Depth = '150';
$sample->ShipmentDetails->addPiece($piece);

$piece = new Piece();
$piece->PieceID = '2';
$piece->PackageType = 'EE';
$piece->Weight = '5.0';
$piece->DimWeight = '600.0';
$piece->Width = '50';
$piece->Height = '100';
$piece->Depth = '150';
$sample->ShipmentDetails->addPiece($piece);

$sample->ShipmentDetails->Weight = '10.0';
$sample->ShipmentDetails->WeightUnit = 'L';
$sample->ShipmentDetails->GlobalProductCode = 'P';
$sample->ShipmentDetails->LocalProductCode = 'P';
$sample->ShipmentDetails->Date = date('Y-m-d');
$sample->ShipmentDetails->Contents = 'AM international shipment contents';
$sample->ShipmentDetails->DoorTo = 'DD';
$sample->ShipmentDetails->DimensionUnit = 'I';
$sample->ShipmentDetails->InsuredAmount = '1200.00';
$sample->ShipmentDetails->PackageType = 'EE';
$sample->ShipmentDetails->IsDutiable = 'Y';
$sample->ShipmentDetails->CurrencyCode = 'USD';

@Ominet
Copy link

Ominet commented Sep 1, 2014

Hello,
Congratulations on DHL-APi, very nice work.
I did as you said but I
Fatal error: Call to undefined method DHL\Datatype\GB\ShipmentDetails::addPiece()

I can not find the code for the function addPiece in source code

@alfallouji
Copy link
Owner

Hello Ominet,

The addPiece method is handled by the magic method __call in the base entity and datatype classes.

It is based on the definition of the property. If a property has multivalues set to true (that means that it is an array of elements), then the add{Propertyname} method will work.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants