Skip to content

Commit

Permalink
✨ expose the colli relationship on the shipment model
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tini committed Dec 4, 2024
1 parent 9dda3e6 commit 7f739af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Resources/Interfaces/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,10 @@ public function setShipmentSurcharges(array $surcharges): self;
public function addShipmentSurcharge(ShipmentSurchargeInterface $surcharge): self;

public function getShipmentSurcharges(): array;

public function setColli(array $colli): self;

public function addCollo(ShipmentInterface $collo): self;

public function getColli(): array;
}
19 changes: 19 additions & 0 deletions src/Resources/Proxy/ShipmentProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,25 @@ public function getShipmentSurcharges(): array
return $this->getResource()->getShipmentSurcharges();
}

public function setColli(array $colli): self
{
$this->getResource()->setColli($colli);

return $this;
}

public function addCollo(ShipmentInterface $collo): self
{
$this->getResource()->addCollo($collo);

return $this;
}

public function getColli(): array
{
return $this->getResource()->getColli();
}

/**
* This function puts all object properties in an array and returns it.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/Resources/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Shipment implements ShipmentInterface
const ATTRIBUTE_TOTAL_VALUE = 'total_value';
const ATTRIBUTE_TAGS = 'tags';

const RELATIONSHIP_COLLI = 'colli';
const RELATIONSHIP_CONTRACT = 'contract';
const RELATIONSHIP_FILES = 'files';
const RELATIONSHIP_MANIFEST = 'manifest';
Expand Down Expand Up @@ -143,6 +144,9 @@ class Shipment implements ShipmentInterface
self::RELATIONSHIP_SHIPMENT_SURCHARGES => [
'data' => [],
],
self::RELATIONSHIP_COLLI => [
'data' => [],
],
];

private array $meta = [
Expand Down Expand Up @@ -821,4 +825,27 @@ public function getShipmentSurcharges(): array
{
return $this->relationships[self::RELATIONSHIP_SHIPMENT_SURCHARGES]['data'];
}

public function setColli(array $colli): self
{
$this->relationships[self::RELATIONSHIP_COLLI]['data'] = [];

array_walk($colli, function ($collo) {
$this->addCollo($collo);
});

return $this;
}

public function addCollo(ShipmentInterface $collo): self
{
$this->relationships[self::RELATIONSHIP_COLLI]['data'][] = $collo;

return $this;
}

public function getColli(): array
{
return $this->relationships[self::RELATIONSHIP_COLLI]['data'];
}
}

0 comments on commit 7f739af

Please sign in to comment.