[ProductVariant] Add version property to a product variant

This commit is contained in:
Grzegorz Sadowski 2017-02-06 15:15:36 +01:00
parent 8dc02d9190
commit 3ab218a4aa
5 changed files with 63 additions and 2 deletions

View file

@ -0,0 +1,34 @@
<?php
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20170206141520 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_product_variant ADD version INT DEFAULT 1 NOT NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_product_variant DROP version');
}
}

View file

@ -17,6 +17,8 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Core\Model\ProductVariant" table="sylius_product_variant">
<field name="version" type="integer" version="true" />
<field name="onHold" column="on_hold" type="integer" />
<field name="onHand" column="on_hand" type="integer" />
<field name="tracked" type="boolean" />

View file

@ -23,6 +23,11 @@ use Webmozart\Assert\Assert;
*/
class ProductVariant extends BaseVariant implements ProductVariantInterface
{
/**
* @var int
*/
protected $version = 1;
/**
* @var int
*/
@ -105,6 +110,14 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface
return $string;
}
/**
* {@inheritdoc}
*/
public function getVersion()
{
return $this->version;
}
/**
* {@inheritdoc}
*/

View file

@ -14,6 +14,7 @@ namespace Sylius\Component\Core\Model;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Inventory\Model\StockableInterface;
use Sylius\Component\Product\Model\ProductVariantInterface as BaseVariantInterface;
use Sylius\Component\Resource\Model\VersionedInterface;
use Sylius\Component\Shipping\Model\ShippableInterface;
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
use Sylius\Component\Taxation\Model\TaxableInterface;
@ -26,7 +27,8 @@ interface ProductVariantInterface extends
BaseVariantInterface,
ShippableInterface,
StockableInterface,
TaxableInterface
TaxableInterface,
VersionedInterface
{
/**
* @return float

View file

@ -16,10 +16,10 @@ use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ChannelPricingInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariant;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Product\Model\ProductVariant as BaseProductVariant;
use Sylius\Component\Resource\Model\VersionedInterface;
use Sylius\Component\Shipping\Model\ShippableInterface;
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
use Sylius\Component\Taxation\Model\TaxableInterface;
@ -55,6 +55,16 @@ final class ProductVariantSpec extends ObjectBehavior
$this->shouldImplement(ShippableInterface::class);
}
function it_implements_versioned_interface()
{
$this->shouldImplement(VersionedInterface::class);
}
function it_has_version_1_by_default()
{
$this->getVersion()->shouldReturn(1);
}
function it_has_no_weight_by_default()
{
$this->getWeight()->shouldReturn(null);