Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions Api/Resource/PredictConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php

namespace Predict\Api\Resource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Patch;
use Predict\Api\State\PredictConfigPersister;
use Predict\Api\State\PredictConfigProvider;
use Symfony\Component\Serializer\Annotation\Groups;

#[ApiResource(
operations: [
new Get(
uriTemplate: '/front/predict/config',
name: 'api_predict_config_get',
provider: PredictConfigProvider::class
),
new Patch(
uriTemplate: '/front/predict/config',
name: 'api_predict_config_patch',
processor: PredictConfigPersister::class
),
],
normalizationContext: ['groups' => [self::GROUP_ADMIN_READ]],
denormalizationContext: ['groups' => [self::GROUP_ADMIN_WRITE]]
)]
class PredictConfig
{
public const GROUP_ADMIN_READ = 'admin:predict_config:read';
public const GROUP_ADMIN_WRITE = 'admin:predict_config:write';

/**
* @var bool|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?bool $predict_freeshipping = null;

/**
* @var float|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?float $predict_freeshipping_amount = null;

/**
* @var string|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?string $store_exapaq_account = null;

/**
* @var string|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?string $store_cellphone = null;

/**
* @var string|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?string $store_phone = null;

/**
* @var bool|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?bool $store_predict_option = null;

/**
* @var int|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?int $predict_tax_rule_id = null;

/**
* @return bool|null
*/
public function getPredictFreeshipping(): ?bool
{
return $this->predict_freeshipping;
}

/**
* @param bool|null $predict_freeshipping
* @return void
*/
public function setPredictFreeshipping(?bool $predict_freeshipping): void
{
$this->predict_freeshipping = $predict_freeshipping;
}

/**
* @return float|null
*/
public function getPredictFreeshippingAmount(): ?float
{
return $this->predict_freeshipping_amount;
}

/**
* @param float|null $predict_freeshipping_amount
* @return void
*/
public function setPredictFreeshippingAmount(?float $predict_freeshipping_amount): void
{
$this->predict_freeshipping_amount = $predict_freeshipping_amount;
}

/**
* @return string|null
*/
public function getStoreExapaqAccount(): ?string
{
return $this->store_exapaq_account;
}

/**
* @param string|null $store_exapaq_account
* @return void
*/
public function setStoreExapaqAccount(?string $store_exapaq_account): void
{
$this->store_exapaq_account = $store_exapaq_account;
}

/**
* @return string|null
*/
public function getStoreCellphone(): ?string
{
return $this->store_cellphone;
}

/**
* @param string|null $store_cellphone
* @return void
*/
public function setStoreCellphone(?string $store_cellphone): void
{
$this->store_cellphone = $store_cellphone;
}

/**
* @return bool|null
*/
public function getStorePredictOption(): ?bool
{
return $this->store_predict_option;
}

/**
* @param bool|null $store_predict_option
* @return void
*/
public function setStorePredictOption(?bool $store_predict_option): void
{
$this->store_predict_option = $store_predict_option;
}

/**
* @return int|null
*/
public function getPredictTaxRuleId(): ?int
{
return $this->predict_tax_rule_id;
}

/**
* @param int|null $predict_tax_rule_id
* @return void
*/
public function setPredictTaxRuleId(?int $predict_tax_rule_id): void
{
$this->predict_tax_rule_id = $predict_tax_rule_id;
}

/**
* @return string|null
*/
public function getStorePhone(): ?string
{
return $this->store_phone;
}

/**
* @param string|null $store_phone
* @return void
*/
public function setStorePhone(?string $store_phone): void
{
$this->store_phone = $store_phone;
}
}
142 changes: 142 additions & 0 deletions Api/Resource/PredictPriceSlice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace Predict\Api\Resource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use Predict\Api\State\PredictPriceSlicePersister;
use Predict\Api\State\PredictPriceSliceProvider;
use Symfony\Component\Serializer\Annotation\Groups;

#[ApiResource(
operations: [
new Get(
uriTemplate: '/front/predict/price-slice/{id}',
name: 'api_predict_price_slice_get',
provider: PredictPriceSliceProvider::class
),
new GetCollection(
uriTemplate: '/front/predict/price-slices',
name: 'api_predict_price_slice_get_collection',
provider: PredictPriceSliceProvider::class
),
new Post(
uriTemplate: '/front/predict/price-slice',
name: 'api_predict_price_slice_post',
processor: PredictPriceSlicePersister::class
),
new Patch(
uriTemplate: '/front/predict/price-slice/{id}',
name: 'api_predict_price_slice_patch',
processor: PredictPriceSlicePersister::class
),
new Delete(
uriTemplate: '/front/predict/price-slice/{id}',
name: 'api_predict_price_slice_delete',
processor: PredictPriceSlicePersister::class
)
],
normalizationContext: ['groups' => [self::GROUP_ADMIN_READ]],
denormalizationContext: ['groups' => [self::GROUP_ADMIN_WRITE]],
)]
class PredictPriceSlice
{
public const GROUP_ADMIN_READ = 'admin:predict_price_slice:read';
public const GROUP_ADMIN_WRITE = 'admin:predict_price_slice:write';

/**
* @var string|null
*/
#[Groups([self::GROUP_ADMIN_READ])]
public ?string $id = null; // ex: "1_12"

/**
* @var int|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?int $area = null;

/**
* @var float|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?float $weight = null;

/**
* @var float|null
*/
#[Groups([self::GROUP_ADMIN_READ, self::GROUP_ADMIN_WRITE])]
public ?float $price = null;

/**
* @return string|null
*/
public function getId(): ?string
{
return $this->id;
}

/**
* @param string|null $id
* @return void
*/
public function setId(?string $id): void
{
$this->id = $id;
}

/**
* @return int|null
*/
public function getArea(): ?int
{
return $this->area;
}

/**
* @param int|null $area
* @return void
*/
public function setArea(?int $area): void
{
$this->area = $area;
}

/**
* @return float|null
*/
public function getWeight(): ?float
{
return $this->weight;
}

/**
* @param float|null $weight
* @return void
*/
public function setWeight(?float $weight): void
{
$this->weight = $weight;
}

/**
* @return float|null
*/
public function getPrice(): ?float
{
return $this->price;
}

/**
* @param float|null $price
* @return void
*/
public function setPrice(?float $price): void
{
$this->price = $price;
}
}
44 changes: 44 additions & 0 deletions Api/State/PredictConfigPersister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Predict\Api\State;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use Thelia\Model\ConfigQuery;

class PredictConfigPersister implements ProcessorInterface
{
/**
* @param $data
* @param Operation $operation
* @param array $uriVariables
* @param array $context
* @return mixed
*/
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
{
if (isset($data->predict_freeshipping)) {
ConfigQuery::write('predict_freeshipping', $data->predict_freeshipping ? '1' : '0');
}
if (isset($data->predict_freeshipping_amount)) {
ConfigQuery::write('predict_freeshipping_amount', $data->predict_freeshipping_amount);
}
if (isset($data->store_exapaq_account)) {
ConfigQuery::write('store_exapaq_account', $data->store_exapaq_account);
}
if (isset($data->store_phone)) {
ConfigQuery::write('store_phone', $data->store_phone);
}
if (isset($data->store_cellphone)) {
ConfigQuery::write('store_cellphone', $data->store_cellphone);
}
if (isset($data->store_predict_option)) {
ConfigQuery::write('store_predict_option', $data->store_predict_option ? '1' : '0');
}
if (isset($data->predict_tax_rule_id)) {
ConfigQuery::write('predict_tax_rule_id', $data->predict_tax_rule_id);
}

return $data;
}
}
Loading