generated from Setono/SyliusPluginSkeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allowed shipment templates to the shipping method. This makes it …
…more reliable to map shipping methods to shipment templates
- Loading branch information
Showing
10 changed files
with
285 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusShipmondoPlugin\Model; | ||
|
||
use Setono\Shipmondo\Response\ShipmentTemplates\ShipmentTemplate; | ||
use Sylius\Component\Core\Model\ShippingMethodInterface as BaseShippingMethodInterface; | ||
|
||
interface ShippingMethodInterface extends BaseShippingMethodInterface | ||
{ | ||
/** | ||
* Returns a list Shipmondo shipment template ids that are allowed for this shipping method | ||
* | ||
* @return list<int> | ||
*/ | ||
public function getAllowedShipmentTemplates(): array; | ||
|
||
/** | ||
* @param list<string|int|ShipmentTemplate> $allowedShipmentTemplates | ||
*/ | ||
public function setAllowedShipmentTemplates(?array $allowedShipmentTemplates): void; | ||
|
||
public function addAllowedShipmentTemplate(int|ShipmentTemplate $shipmentTemplate): void; | ||
|
||
public function hasAllowedShipmentTemplate(int|ShipmentTemplate $shipmentTemplate): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusShipmondoPlugin\Model; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Setono\Shipmondo\Response\ShipmentTemplates\ShipmentTemplate; | ||
|
||
trait ShippingMethodTrait | ||
{ | ||
/** | ||
* @var list<int> | ||
* | ||
* @ORM\Column(type="json", nullable=true) | ||
*/ | ||
#[ORM\Column(type: 'json', nullable: true)] | ||
protected ?array $allowedShipmentTemplates = []; | ||
|
||
public function getAllowedShipmentTemplates(): array | ||
{ | ||
return $this->allowedShipmentTemplates ?? []; | ||
} | ||
|
||
public function setAllowedShipmentTemplates(?array $allowedShipmentTemplates): void | ||
{ | ||
$this->allowedShipmentTemplates = null; | ||
|
||
if (null === $allowedShipmentTemplates) { | ||
return; | ||
} | ||
|
||
foreach ($allowedShipmentTemplates as $allowedShipmentTemplate) { | ||
$this->addAllowedShipmentTemplate($allowedShipmentTemplate instanceof ShipmentTemplate ? $allowedShipmentTemplate->id : (int) $allowedShipmentTemplate); | ||
} | ||
} | ||
|
||
public function addAllowedShipmentTemplate(int|ShipmentTemplate $shipmentTemplate): void | ||
{ | ||
if (null === $this->allowedShipmentTemplates) { | ||
$this->allowedShipmentTemplates = []; | ||
} | ||
|
||
$id = $shipmentTemplate instanceof ShipmentTemplate ? $shipmentTemplate->id : $shipmentTemplate; | ||
|
||
if ($this->hasAllowedShipmentTemplate($id)) { | ||
return; | ||
} | ||
|
||
$this->allowedShipmentTemplates[] = $id; | ||
} | ||
|
||
public function hasAllowedShipmentTemplate(int|ShipmentTemplate $shipmentTemplate): bool | ||
{ | ||
if (null === $this->allowedShipmentTemplates) { | ||
return false; | ||
} | ||
|
||
return in_array($shipmentTemplate instanceof ShipmentTemplate ? $shipmentTemplate->id : $shipmentTemplate, $this->allowedShipmentTemplates, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.