Skip to content

Commit

Permalink
Added the UploadProductVariantRequest entity along with related files
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 5, 2024
1 parent b18b0a7 commit a75fadd
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Setono\SyliusPeakPlugin\Model\InventoryUpdate;
use Setono\SyliusPeakPlugin\Model\RegisteredWebhooks;
use Setono\SyliusPeakPlugin\Model\UploadOrderRequest;
use Setono\SyliusPeakPlugin\Model\UploadProductVariantRequest;
use Sylius\Component\Resource\Factory\Factory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -57,7 +58,7 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->end()
->end()
->end()
->arrayNode('registered_webhooks')
->arrayNode('registered_webhooks') // todo rename to webhook_registration?
->addDefaultsIfNotSet()
->children()
->variableNode('options')->end()
Expand All @@ -80,6 +81,19 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->children()
->scalarNode('model')->defaultValue(UploadOrderRequest::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->end()
->end()
->end()
->end()
->end()
->arrayNode('upload_product_variant_request')
->addDefaultsIfNotSet()
->children()
->variableNode('options')->end()
->arrayNode('classes')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(UploadProductVariantRequest::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->end()
;
}
}
14 changes: 14 additions & 0 deletions src/Model/ProductVariantInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusPeakPlugin\Model;

use Sylius\Component\Core\Model\ProductVariantInterface as BaseProductVariantInterface;

interface ProductVariantInterface extends BaseProductVariantInterface
{
public function getPeakUploadProductVariantRequest(): ?UploadProductVariantRequestInterface;

public function setPeakUploadProductVariantRequest(?UploadProductVariantRequestInterface $uploadProductVariantRequest): void;
}
25 changes: 25 additions & 0 deletions src/Model/ProductVariantTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusPeakPlugin\Model;

use Doctrine\ORM\Mapping as ORM;

trait ProductVariantTrait
{
/** @ORM\OneToOne(mappedBy="productVariant", targetEntity="Setono\SyliusPeakPlugin\Model\UploadProductVariantRequestInterface", cascade={"persist"}, orphanRemoval=true) */
#[ORM\OneToOne(mappedBy: 'productVariant', targetEntity: UploadProductVariantRequestInterface::class, cascade: ['persist'], orphanRemoval: true)]
protected ?UploadProductVariantRequestInterface $peakUploadProductVariantRequest = null;

public function getPeakUploadProductVariantRequest(): ?UploadProductVariantRequestInterface
{
return $this->peakUploadProductVariantRequest;
}

public function setPeakUploadProductVariantRequest(?UploadProductVariantRequestInterface $uploadProductVariantRequest): void
{
$this->peakUploadProductVariantRequest = $uploadProductVariantRequest;
$uploadProductVariantRequest?->setProductVariant($this);
}
}
99 changes: 99 additions & 0 deletions src/Model/UploadProductVariantRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusPeakPlugin\Model;

class UploadProductVariantRequest implements UploadProductVariantRequestInterface
{
protected ?int $id = null;

protected int $version = 1;

protected string $state = self::STATE_PENDING;

protected ?ProductVariantInterface $productVariant = null;

protected ?string $request = null;

protected ?string $response = null;

protected ?string $error = null;

protected ?int $peakProductId = null;

public function getId(): ?int
{
return $this->id;
}

public function getVersion(): int
{
return $this->version;
}

public function setVersion(?int $version): void
{
$this->version = (int) $version;
}

public function getState(): string
{
return $this->state;
}

public function setState(string $state): void
{
$this->state = $state;
}

public function getProductVariant(): ?ProductVariantInterface
{
return $this->productVariant;
}

public function setProductVariant(?ProductVariantInterface $productVariant): void
{
$this->productVariant = $productVariant;
}

public function getRequest(): ?string
{
return $this->request;
}

public function setRequest(?string $request): void
{
$this->request = $request;
}

public function getResponse(): ?string
{
return $this->response;
}

public function setResponse(?string $response): void
{
$this->response = $response;
}

public function getError(): ?string
{
return $this->error;
}

public function setError(?string $error): void
{
$this->error = $error;
}

public function getPeakProductId(): ?int
{
return $this->peakProductId;
}

public function setPeakProductId(?int $peakProductId): void
{
$this->peakProductId = $peakProductId;
}
}
48 changes: 48 additions & 0 deletions src/Model/UploadProductVariantRequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusPeakPlugin\Model;

use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\VersionedInterface;

interface UploadProductVariantRequestInterface extends ResourceInterface, VersionedInterface
{
public const STATE_PENDING = 'pending';

public const STATE_PROCESSING = 'processing';

public const STATE_UPLOADED = 'uploaded';

public const STATE_FAILED = 'failed';

public function getId(): ?int;

public function getState(): string;

public function setState(string $state): void;

public function getProductVariant(): ?ProductVariantInterface;

public function setProductVariant(?ProductVariantInterface $productVariant): void;

public function getRequest(): ?string;

public function setRequest(?string $request): void;

public function getResponse(): ?string;

public function setResponse(?string $response): void;

public function getError(): ?string;

public function setError(?string $error): void;

/**
* If the product variant was uploaded successfully, this method will return the peak internal id
*/
public function getPeakProductId(): ?int;

public function setPeakProductId(?int $peakProductId): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Setono\SyliusPeakPlugin\Model\UploadProductVariantRequest"
table="setono_sylius_peak_wms__upload_product_variant_request">
<id name="id" type="integer">
<generator strategy="AUTO"/>
</id>

<field name="version" type="integer" version="true"/>
<field name="state" type="string"/>
<field name="request" type="text" nullable="true"/>
<field name="response" type="text" nullable="true"/>
<field name="error" type="text" nullable="true"/>
<field name="peakProductId" type="integer" nullable="true"/>

<one-to-one field="productVariant" target-entity="Sylius\Component\Product\Model\ProductVariantInterface" inversed-by="peakUploadProductVariantRequest">
<join-column name="product_variant_id" referenced-column-name="id" nullable="false" unique="true" on-delete="CASCADE"/>
</one-to-one>
</mapped-superclass>
</doctrine-mapping>
2 changes: 1 addition & 1 deletion src/Resources/config/services/command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="ProcessUploadOrderRequestsCommand">
<service id="Setono\SyliusPeakPlugin\Command\ProcessUploadOrderRequestsCommand">
<argument type="service" id="Setono\SyliusPeakPlugin\Processor\UploadOrderRequestProcessorInterface"/>

<tag name="console.command"/>
Expand Down
20 changes: 20 additions & 0 deletions tests/Application/Model/ProductVariant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Tests\Setono\SyliusPeakPlugin\Application\Model;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusPeakPlugin\Model\ProductVariantInterface as PeakProductVariantInterface;
use Setono\SyliusPeakPlugin\Model\ProductVariantTrait as PeakProductVariantTrait;
use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;

/**
* @ORM\Entity
*
* @ORM\Table(name="sylius_product_variant")
*/
class ProductVariant extends BaseProductVariant implements PeakProductVariantInterface
{
use PeakProductVariantTrait;
}
6 changes: 6 additions & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ sylius_order:
order:
classes:
model: Tests\Setono\SyliusPeakPlugin\Application\Model\Order

sylius_product:
resources:
product_variant:
classes:
model: Tests\Setono\SyliusPeakPlugin\Application\Model\ProductVariant

0 comments on commit a75fadd

Please sign in to comment.