[Promotion] Make description not required

This commit is contained in:
Mateusz Zalewski 2016-04-05 13:03:09 +02:00
parent 710b8b4f2c
commit 10fa3d6383
10 changed files with 55 additions and 24 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 Version20160405103129 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_promotion CHANGE description description VARCHAR(255) DEFAULT 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_promotion CHANGE description description VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci');
}
}

View file

@ -31,6 +31,7 @@ class PromotionType extends AbstractResourceType
])
->add('description', 'text', [
'label' => 'sylius.form.promotion.description',
'required' => false,
])
->add('exclusive', 'checkbox', [
'label' => 'sylius.form.promotion.exclusive',

View file

@ -21,7 +21,7 @@
<field name="code" type="string" unique="true" />
<field name="name" type="string" />
<field name="description" type="string" />
<field name="description" type="string" nullable="true" />
<field name="priority" type="integer">
<gedmo:sortable-position/>
</field>

View file

@ -42,10 +42,6 @@
</constraint>
</property>
<property name="description">
<constraint name="NotBlank">
<option name="message">sylius.promotion.description.not_blank</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="max">255</option>

View file

@ -77,7 +77,7 @@ abstract class DiscountAction implements PromotionActionInterface
{
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType($type);
$adjustment->setLabel($promotion->getDescription());
$adjustment->setLabel($promotion->getName());
$this->originator->setOrigin($adjustment, $promotion);

View file

@ -108,7 +108,7 @@ abstract class ItemDiscountAction implements PromotionActionInterface
{
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType($type);
$adjustment->setLabel($promotion->getDescription());
$adjustment->setLabel($promotion->getName());
$this->originator->setOrigin($adjustment, $promotion);

View file

@ -50,13 +50,13 @@ class FixedDiscountActionSpec extends ObjectBehavior
PromotionInterface $promotion
) {
$adjustmentFactory->createNew()->willReturn($adjustment);
$promotion->getDescription()->willReturn('promotion description');
$promotion->getName()->willReturn('Test promotion');
$order->getPromotionSubjectTotal()->willReturn(1000);
$adjustment->setAmount(-500)->shouldBeCalled();
$adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$adjustment->setLabel('promotion description')->shouldBeCalled();
$adjustment->setLabel('Test promotion')->shouldBeCalled();
$originator->setOrigin($adjustment, $promotion)->shouldBeCalled();
@ -74,13 +74,13 @@ class FixedDiscountActionSpec extends ObjectBehavior
PromotionInterface $promotion
) {
$adjustmentFactory->createNew()->willReturn($adjustment);
$promotion->getDescription()->willReturn('promotion description');
$promotion->getName()->willReturn('Test promotion');
$order->getPromotionSubjectTotal()->willReturn(1000);
$adjustment->setAmount(-1000)->shouldBeCalled();
$adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$adjustment->setLabel('promotion description')->shouldBeCalled();
$adjustment->setLabel('Test promotion')->shouldBeCalled();
$originator->setOrigin($adjustment, $promotion)->shouldBeCalled();

View file

@ -83,20 +83,20 @@ class ItemFixedDiscountActionSpec extends ObjectBehavior
$orderItem1->getUnits()->willReturn($units);
$units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
$promotion->getDescription()->willReturn('Test description');
$promotion->getName()->willReturn('Test promotion');
$adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
$unit1->getTotal()->willReturn(1000);
$promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment1->setAmount(-500)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
$unit2->getTotal()->willReturn(1000);
$promotionAdjustment2->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment2->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment2->setAmount(-500)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();
@ -155,20 +155,20 @@ class ItemFixedDiscountActionSpec extends ObjectBehavior
$orderItem1->getUnits()->willReturn($units);
$units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
$promotion->getDescription()->willReturn('Test description');
$promotion->getName()->willReturn('Test promotion');
$adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
$unit1->getTotal()->willReturn(300);
$promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment1->setAmount(-300)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
$unit2->getTotal()->willReturn(200);
$promotionAdjustment2->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment2->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment2->setAmount(-200)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();

View file

@ -89,18 +89,18 @@ class ItemPercentageDiscountActionSpec extends ObjectBehavior
$orderItem1->getTotal()->willReturn(1000);
$distributor->distribute(200, 2)->willReturn([100, 100]);
$promotion->getDescription()->willReturn('Test description');
$promotion->getName()->willReturn('Test promotion');
$adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
$promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment1->setAmount(-100)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
$promotionAdjustment2->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment2->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment2->setAmount(-100)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();
@ -147,12 +147,12 @@ class ItemPercentageDiscountActionSpec extends ObjectBehavior
$orderItem1->getTotal()->willReturn(5);
$distributor->distribute(1, 2)->willReturn([1, 0]);
$promotion->getDescription()->willReturn('Test description');
$promotion->getName()->willReturn('Test promotion');
$adjustmentFactory->createNew()->willReturn($promotionAdjustment1);
$promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
$promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
$promotionAdjustment1->setAmount(-1)->shouldBeCalled();
$originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();

View file

@ -49,11 +49,11 @@ class PercentageDiscountActionSpec extends ObjectBehavior
) {
$order->getPromotionSubjectTotal()->willReturn(10000);
$adjustmentFactory->createNew()->willReturn($adjustment);
$promotion->getDescription()->willReturn('promotion description');
$promotion->getName()->willReturn('Test promotion');
$adjustment->setAmount(-2500)->shouldBeCalled();
$adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$adjustment->setLabel('promotion description')->shouldBeCalled();
$adjustment->setLabel('Test promotion')->shouldBeCalled();
$originator->setOrigin($adjustment, $promotion)->shouldBeCalled();