[Product] Remove softdeletable form ProductVariant

This commit is contained in:
Łukasz Chruściel 2016-02-29 14:49:36 +01:00
parent fe757e8650
commit 3b35136919
7 changed files with 40 additions and 42 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 Version20160229145014 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 DROP deleted_at');
}
/**
* @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 ADD deleted_at DATETIME DEFAULT NULL');
}
}

View file

@ -32,9 +32,6 @@
<field name="updatedAt" column="updated_at" type="datetime" nullable="true">
<gedmo:timestampable on="update"/>
</field>
<field name="deletedAt" column="deleted_at" type="datetime" nullable="true" />
<gedmo:soft-deleteable field-name="deletedAt" />
</mapped-superclass>
</doctrine-mapping>

View file

@ -354,7 +354,7 @@ class Product implements ProductInterface
public function getVariants()
{
return $this->variants->filter(function (BaseVariantInterface $variant) {
return !$variant->isDeleted() && !$variant->isMaster();
return !$variant->isMaster();
});
}
@ -364,7 +364,7 @@ class Product implements ProductInterface
public function getAvailableVariants()
{
return $this->variants->filter(function (BaseVariantInterface $variant) {
return !$variant->isDeleted() && !$variant->isMaster() && $variant->isAvailable();
return $variant->isMaster() && $variant->isAvailable();
});
}

View file

@ -176,10 +176,9 @@ class ProductSpec extends ObjectBehavior
function it_should_not_add_master_variant_twice_to_collection(VariantInterface $variant)
{
$variant->isMaster()->willReturn(true);
$variant->isDeleted()->willReturn(false);
$variant->setProduct($this)->shouldBeCalled();
$variant->setMaster(true)->shouldBeCalled();
$variant->setProduct($this)->shouldBeCalledTimes(1);
$variant->setMaster(true)->shouldBeCalledTimes(2);
$this->setMasterVariant($variant);
$this->setMasterVariant($variant);
@ -195,7 +194,6 @@ class ProductSpec extends ObjectBehavior
function its_hasVariants_should_return_true_only_if_any_variants_defined(VariantInterface $variant)
{
$variant->isMaster()->willReturn(false);
$variant->isDeleted()->willReturn(false);
$variant->setProduct($this)->shouldBeCalled();

View file

@ -21,7 +21,7 @@ use Sylius\Component\Resource\Model\TimestampableTrait;
*/
class Variant implements VariantInterface
{
use SoftDeletableTrait, TimestampableTrait;
use TimestampableTrait;
/**
* @var mixed

View file

@ -19,7 +19,7 @@ use Sylius\Component\Resource\Model\TimestampableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface VariantInterface extends SoftDeletableInterface, TimestampableInterface, ResourceInterface
interface VariantInterface extends TimestampableInterface, ResourceInterface
{
/**
* Checks whether variant is master.

View file

@ -137,35 +137,4 @@ class VariantSpec extends ObjectBehavior
{
$this->getUpdatedAt()->shouldReturn(null);
}
function it_should_not_have_deletion_date_by_default()
{
$this->getDeletedAt()->shouldReturn(null);
}
function its_deletion_date_should_be_mutable()
{
$deletedAt = new \DateTime('now');
$this->setDeletedAt($deletedAt);
$this->getDeletedAt()->shouldReturn($deletedAt);
}
function it_is_deleted_only_if_deletion_date_is_in_past()
{
$deletedAt = new \DateTime('yesterday');
$this->setDeletedAt($deletedAt);
$this->shouldBeDeleted();
$deletedAt = new \DateTime('tomorrow');
$this->setDeletedAt($deletedAt);
$this->shouldNotBeDeleted();
}
function it_should_not_be_deleted_by_default()
{
$this->shouldNotBeDeleted();
}
}