mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[ProductVariant] Add version property to a product variant
This commit is contained in:
parent
8dc02d9190
commit
3ab218a4aa
5 changed files with 63 additions and 2 deletions
34
app/migrations/Version20170206141520.php
Normal file
34
app/migrations/Version20170206141520.php
Normal 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue