Skip to content

Commit

Permalink
[PriceHistory] Add ChannelPricingLogEntry entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafikooo committed Mar 17, 2023
1 parent 7b0fcb8 commit 9044e9f
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>

<mapped-superclass name="Sylius\Component\Core\Model\ChannelPricingLogEntry" table="sylius_channel_pricing_log_entry">
<id name="id" column="id" type="integer">
<generator />
</id>

<field name="price" column="price" type="integer" />
<field name="originalPrice" column="original_price" type="integer" nullable="true" />
<field name="loggedAt" column="logged_at" type="datetime" />

<many-to-one field="channelPricing" target-entity="Sylius\Component\Core\Model\ChannelPricingInterface">
<join-column name="channel_pricing_id" nullable="false" on-delete="CASCADE" />
</many-to-one>
</mapped-superclass>
</doctrine-mapping>
56 changes: 56 additions & 0 deletions src/Sylius/Component/Core/Model/ChannelPricingLogEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Component\Core\Model;

class ChannelPricingLogEntry implements ChannelPricingLogEntryInterface
{
/** @var mixed|null */
protected $id;

public function __construct(
protected ChannelPricingInterface $channelPricing,
protected \DateTimeInterface $loggedAt,
protected int $price,
protected ?int $originalPrice,
) {
}

/**
* @psalm-suppress MissingReturnType
*/
public function getId()
{
return $this->id;
}

public function getChannelPricing(): ChannelPricingInterface
{
return $this->channelPricing;
}

public function getPrice(): int
{
return $this->price;
}

public function getOriginalPrice(): ?int
{
return $this->originalPrice;
}

public function getLoggedAt(): \DateTimeInterface
{
return $this->loggedAt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Component\Core\Model;

use Sylius\Component\Resource\Model\ResourceInterface;

interface ChannelPricingLogEntryInterface extends ResourceInterface
{
public function getChannelPricing(): ChannelPricingInterface;

public function getPrice(): int;

public function getOriginalPrice(): ?int;

public function getLoggedAt(): \DateTimeInterface;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\Component\Core\Model;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ChannelPricingInterface;
use Sylius\Component\Core\Model\ChannelPricingLogEntryInterface;

final class ChannelPricingLogEntrySpec extends ObjectBehavior
{
function let(ChannelPricingInterface $channelPricing): void
{
$this->beConstructedWith($channelPricing, new \DateTime(), 1000, 2000);
}

function it_implements_channel_pricing_log_entry_interface(): void
{
$this->shouldImplement(ChannelPricingLogEntryInterface::class);
}

function it_initialize_with_no_original_price(ChannelPricingInterface $channelPricing): void
{
$this->beConstructedWith($channelPricing, new \DateTime(), 1000, null);
$this->getOriginalPrice()->shouldReturn(null);
}

function it_gets_a_channel_pricing(): void
{
$this->getChannelPricing()->shouldReturnAnInstanceOf(ChannelPricingInterface::class);
}

function it_gets_a_price(): void
{
$this->getPrice()->shouldReturn(1000);
}

function it_gets_an_original_price(): void
{
$this->getOriginalPrice()->shouldReturn(2000);
}

function it_gets_a_logged_at(): void
{
$this->getLoggedAt()->shouldReturnAnInstanceOf(\DateTimeInterface::class);
}
}

0 comments on commit 9044e9f

Please sign in to comment.