Skip to content

Commit

Permalink
Updated shipping calculators with v4 Configurable/Schematized methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Feb 27, 2024
1 parent c196bdc commit 471ddbe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Foundation/Shipping/FlatFeeCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace Vanilo\Foundation\Shipping;

use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Vanilo\Adjustments\Adjusters\SimpleShippingFee;
use Vanilo\Contracts\Buyable;
use Vanilo\Contracts\CheckoutSubject;
Expand Down Expand Up @@ -58,6 +60,24 @@ public function calculate(?object $subject = null, ?array $configuration = null)
return new ShippingFee($cost, true);
}

public function getSchema(): Schema
{
return Expect::structure([
'title' => Expect::string(__('Shipping fee')),
'cost' => Expect::float()->required(),
'free_threshold' => Expect::float(),
]);
}

public function getSchemaSample(array $mergeWith = null): array
{
return [
'title' => __('Shipping fee'),
'cost' => 7.99,
'free_threshold' => null,
];
}

private function toParameters(?array $configuration): array
{
if (!is_array($configuration) || !isset($configuration['cost'])) {
Expand Down
20 changes: 20 additions & 0 deletions src/Foundation/Shipping/PaymentDependentShippingFeeCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace Vanilo\Foundation\Shipping;

use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Vanilo\Contracts\Buyable;
use Vanilo\Contracts\CheckoutSubject;
use Vanilo\Shipment\Contracts\ShippingFeeCalculator;
Expand Down Expand Up @@ -58,6 +60,24 @@ public function calculate(?object $subject = null, ?array $configuration = null)
return new ShippingFee($price, $isEstimate);
}

public function getSchema(): Schema
{
return Expect::structure([
'title' => Expect::string(__('Shipping fee')),
'prices' => Expect::arrayOf('float', 'string'),
'free_threshold' => Expect::float(),
]);
}

public function getSchemaSample(array $mergeWith = null): array
{
return [
'title' => __('Shipping fee'),
'prices' => ['default' => 8.99, '1' => 4.99],
'free_threshold' => null,
];
}

private function toParameters(?array $configuration): array
{
if (!is_array($configuration) || !isset($configuration['prices'])) {
Expand Down

0 comments on commit 471ddbe

Please sign in to comment.