mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[PriceHistory] Add ChannelPricingLogEntry entity
This commit is contained in:
parent
7b0fcb85fb
commit
9044e9f491
4 changed files with 172 additions and 0 deletions
|
|
@ -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
src/Sylius/Component/Core/Model/ChannelPricingLogEntry.php
Normal file
56
src/Sylius/Component/Core/Model/ChannelPricingLogEntry.php
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue