forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PriceHistory] Add ChannelPricingLogEntry entity
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ChannelPricingLogEntry.orm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
src/Sylius/Component/Core/Model/ChannelPricingLogEntry.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Sylius/Component/Core/Model/ChannelPricingLogEntryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Sylius/Component/Core/spec/Model/ChannelPricingLogEntrySpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |