From e4ebfc2baaaf1bcaaaa81fa4070341d9474a064f Mon Sep 17 00:00:00 2001 From: Piotr Walkow Date: Mon, 19 Oct 2015 15:52:44 +0100 Subject: [PATCH 1/2] Renaming adjustment label to type --- app/migrations/Version20151019160305.php | 34 +++++++++++++++++++ .../OrderProcessing/TaxationProcessor.php | 2 +- .../OrderBundle/Form/Type/AdjustmentType.php | 4 +-- .../config/doctrine/model/Adjustment.orm.xml | 2 +- .../Resources/config/validation.xml | 4 +-- .../spec/Form/Type/AdjustmentTypeSpec.php | 2 +- .../Resources/translations/messages.en.yml | 2 +- .../views/Backend/Order/adjustments.html.twig | 4 +-- .../PaymentChargesProcessor.php | 2 +- .../ShippingChargesProcessor.php | 2 +- .../Core/Promotion/Action/DiscountAction.php | 2 +- .../Component/Core/spec/Model/OrderSpec.php | 16 ++++----- .../PaymentChargesProcessorSpec.php | 2 +- .../ShippingChargesProcessorSpec.php | 2 +- .../Action/FixedDiscountActionSpec.php | 2 +- .../Action/PercentageDiscountActionSpec.php | 2 +- .../Component/Order/Model/Adjustment.php | 10 +++--- .../Order/Model/AdjustmentInterface.php | 6 ++-- src/Sylius/Component/Order/Model/Order.php | 2 +- .../Component/Order/Model/OrderItem.php | 2 +- .../Order/spec/Model/AdjustmentSpec.php | 10 +++--- 21 files changed, 74 insertions(+), 40 deletions(-) create mode 100644 app/migrations/Version20151019160305.php diff --git a/app/migrations/Version20151019160305.php b/app/migrations/Version20151019160305.php new file mode 100644 index 0000000000..f36dbfa05c --- /dev/null +++ b/app/migrations/Version20151019160305.php @@ -0,0 +1,34 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE sylius_adjustment CHANGE label type VARCHAR(255) 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_adjustment CHANGE type label VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci'); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/OrderProcessing/TaxationProcessor.php b/src/Sylius/Bundle/CoreBundle/OrderProcessing/TaxationProcessor.php index f5f27804a0..39456dccc3 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderProcessing/TaxationProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/OrderProcessing/TaxationProcessor.php @@ -150,7 +150,7 @@ class TaxationProcessor implements TaxationProcessorInterface { foreach ($taxes as $description => $tax) { $adjustment = $this->adjustmentRepository->createNew(); - $adjustment->setLabel(AdjustmentInterface::TAX_ADJUSTMENT); + $adjustment->setType(AdjustmentInterface::TAX_ADJUSTMENT); $adjustment->setAmount($tax['amount']); $adjustment->setDescription($description); $adjustment->setNeutral($tax['included']); diff --git a/src/Sylius/Bundle/OrderBundle/Form/Type/AdjustmentType.php b/src/Sylius/Bundle/OrderBundle/Form/Type/AdjustmentType.php index 194cb29450..7c3a516096 100644 --- a/src/Sylius/Bundle/OrderBundle/Form/Type/AdjustmentType.php +++ b/src/Sylius/Bundle/OrderBundle/Form/Type/AdjustmentType.php @@ -27,8 +27,8 @@ class AdjustmentType extends AbstractResourceType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('label', 'text', array( - 'label' => 'sylius.form.adjustment.label' + ->add('type', 'text', array( + 'label' => 'sylius.form.adjustment.type' )) ->add('description', 'text', array( 'label' => 'sylius.form.adjustment.description', diff --git a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/Adjustment.orm.xml b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/Adjustment.orm.xml index 124c171e5c..e7050c8c4d 100644 --- a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/Adjustment.orm.xml +++ b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/Adjustment.orm.xml @@ -22,7 +22,7 @@ - + diff --git a/src/Sylius/Bundle/OrderBundle/Resources/config/validation.xml b/src/Sylius/Bundle/OrderBundle/Resources/config/validation.xml index c807388e3a..c705efe3c4 100644 --- a/src/Sylius/Bundle/OrderBundle/Resources/config/validation.xml +++ b/src/Sylius/Bundle/OrderBundle/Resources/config/validation.xml @@ -42,9 +42,9 @@ - + - + diff --git a/src/Sylius/Bundle/OrderBundle/spec/Form/Type/AdjustmentTypeSpec.php b/src/Sylius/Bundle/OrderBundle/spec/Form/Type/AdjustmentTypeSpec.php index 8b59f10149..3be9eb5178 100644 --- a/src/Sylius/Bundle/OrderBundle/spec/Form/Type/AdjustmentTypeSpec.php +++ b/src/Sylius/Bundle/OrderBundle/spec/Form/Type/AdjustmentTypeSpec.php @@ -39,7 +39,7 @@ class AdjustmentTypeSpec extends ObjectBehavior function it_builds_form_with_proper_fields(FormBuilderInterface $builder) { $builder - ->add('label', 'text', Argument::any()) + ->add('type', 'text', Argument::any()) ->willReturn($builder) ; diff --git a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml index 8b51b27177..c3cd9937a1 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml @@ -578,7 +578,7 @@ sylius: no_promotion: No coupons were used.order: adjustments: manage: Manage adjustments - label: Label + type: Type description: Description amount: Amount locked: Locked? diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/adjustments.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/adjustments.html.twig index c5ae6e565f..f370e49131 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/adjustments.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/adjustments.html.twig @@ -38,7 +38,7 @@ - + @@ -49,7 +49,7 @@ {% for adjustment in order.adjustments %}
{{ 'sylius.order.adjustments.label'|trans }}{{ 'sylius.order.adjustments.type'|trans }} {{ 'sylius.order.adjustments.description'|trans }} {{ 'sylius.order.adjustments.amount'|trans }} {{ 'sylius.order.adjustments.locked'|trans }}
- {{ adjustment.label }} + {{ adjustment.type }} {{ adjustment.description }} diff --git a/src/Sylius/Component/Core/OrderProcessing/PaymentChargesProcessor.php b/src/Sylius/Component/Core/OrderProcessing/PaymentChargesProcessor.php index 22cc0972f4..329b7385b9 100644 --- a/src/Sylius/Component/Core/OrderProcessing/PaymentChargesProcessor.php +++ b/src/Sylius/Component/Core/OrderProcessing/PaymentChargesProcessor.php @@ -78,7 +78,7 @@ class PaymentChargesProcessor implements PaymentChargesProcessorInterface private function prepareAdjustmentForOrder(PaymentSubjectInterface $payment) { $adjustment = $this->adjustmentRepository->createNew(); - $adjustment->setLabel(AdjustmentInterface::PAYMENT_ADJUSTMENT); + $adjustment->setType(AdjustmentInterface::PAYMENT_ADJUSTMENT); $adjustment->setAmount($this->feeCalculator->calculate($payment)); $adjustment->setDescription($payment->getMethod()->getName()); diff --git a/src/Sylius/Component/Core/OrderProcessing/ShippingChargesProcessor.php b/src/Sylius/Component/Core/OrderProcessing/ShippingChargesProcessor.php index d25442fc72..251f45d82a 100644 --- a/src/Sylius/Component/Core/OrderProcessing/ShippingChargesProcessor.php +++ b/src/Sylius/Component/Core/OrderProcessing/ShippingChargesProcessor.php @@ -61,7 +61,7 @@ class ShippingChargesProcessor implements ShippingChargesProcessorInterface $shippingCharge = $this->calculator->calculate($shipment); $adjustment = $this->adjustmentRepository->createNew(); - $adjustment->setLabel(AdjustmentInterface::SHIPPING_ADJUSTMENT); + $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT); $adjustment->setAmount($shippingCharge); $adjustment->setDescription($shipment->getMethod()->getName()); diff --git a/src/Sylius/Component/Core/Promotion/Action/DiscountAction.php b/src/Sylius/Component/Core/Promotion/Action/DiscountAction.php index 238e9ccc67..14e0d635f4 100644 --- a/src/Sylius/Component/Core/Promotion/Action/DiscountAction.php +++ b/src/Sylius/Component/Core/Promotion/Action/DiscountAction.php @@ -64,7 +64,7 @@ abstract class DiscountAction implements PromotionActionInterface protected function createAdjustment(PromotionInterface $promotion) { $adjustment = $this->adjustmentRepository->createNew(); - $adjustment->setLabel(AdjustmentInterface::PROMOTION_ADJUSTMENT); + $adjustment->setType(AdjustmentInterface::PROMOTION_ADJUSTMENT); $adjustment->setDescription($promotion->getDescription()); $this->originator->setOrigin($adjustment, $promotion); diff --git a/src/Sylius/Component/Core/spec/Model/OrderSpec.php b/src/Sylius/Component/Core/spec/Model/OrderSpec.php index 9cbff0ffe1..8f14ad8a23 100644 --- a/src/Sylius/Component/Core/spec/Model/OrderSpec.php +++ b/src/Sylius/Component/Core/spec/Model/OrderSpec.php @@ -110,10 +110,10 @@ class OrderSpec extends ObjectBehavior AdjustmentInterface $shippingAdjustment, AdjustmentInterface $taxAdjustment ) { - $shippingAdjustment->getLabel()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); + $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); $shippingAdjustment->setAdjustable($this)->shouldBeCalled(); - $taxAdjustment->getLabel()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); + $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); $taxAdjustment->setAdjustable($this)->shouldBeCalled(); $this->addAdjustment($shippingAdjustment); @@ -130,10 +130,10 @@ class OrderSpec extends ObjectBehavior AdjustmentInterface $shippingAdjustment, AdjustmentInterface $taxAdjustment ) { - $shippingAdjustment->getLabel()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); + $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); $shippingAdjustment->setAdjustable($this)->shouldBeCalled(); - $taxAdjustment->getLabel()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); + $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); $taxAdjustment->setAdjustable($this)->shouldBeCalled(); $this->addAdjustment($shippingAdjustment); @@ -153,10 +153,10 @@ class OrderSpec extends ObjectBehavior AdjustmentInterface $shippingAdjustment, AdjustmentInterface $taxAdjustment ) { - $shippingAdjustment->getLabel()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); + $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); $shippingAdjustment->setAdjustable($this)->shouldBeCalled(); - $taxAdjustment->getLabel()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); + $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); $taxAdjustment->setAdjustable($this)->shouldBeCalled(); $this->addAdjustment($shippingAdjustment); @@ -173,10 +173,10 @@ class OrderSpec extends ObjectBehavior AdjustmentInterface $shippingAdjustment, AdjustmentInterface $taxAdjustment ) { - $shippingAdjustment->getLabel()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); + $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); $shippingAdjustment->setAdjustable($this)->shouldBeCalled(); - $taxAdjustment->getLabel()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); + $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); $taxAdjustment->setAdjustable($this)->shouldBeCalled(); $this->addAdjustment($shippingAdjustment); diff --git a/src/Sylius/Component/Core/spec/OrderProcessing/PaymentChargesProcessorSpec.php b/src/Sylius/Component/Core/spec/OrderProcessing/PaymentChargesProcessorSpec.php index 2420e63e0f..5ca3b92023 100644 --- a/src/Sylius/Component/Core/spec/OrderProcessing/PaymentChargesProcessorSpec.php +++ b/src/Sylius/Component/Core/spec/OrderProcessing/PaymentChargesProcessorSpec.php @@ -59,7 +59,7 @@ class PaymentChargesProcessorSpec extends ObjectBehavior $delegatingFeeCalculator->calculate($payment)->willReturn(50); $adjustmentRepository->createNew()->willReturn($adjustment)->shouldBeCalled(); - $adjustment->setLabel('payment')->shouldBeCalled(); + $adjustment->setType('payment')->shouldBeCalled(); $adjustment->setAmount(50)->shouldBeCalled(); $adjustment->setDescription('testPaymentMethod')->shouldBeCalled(); diff --git a/src/Sylius/Component/Core/spec/OrderProcessing/ShippingChargesProcessorSpec.php b/src/Sylius/Component/Core/spec/OrderProcessing/ShippingChargesProcessorSpec.php index 3ea23db736..138ef49c0a 100644 --- a/src/Sylius/Component/Core/spec/OrderProcessing/ShippingChargesProcessorSpec.php +++ b/src/Sylius/Component/Core/spec/OrderProcessing/ShippingChargesProcessorSpec.php @@ -81,7 +81,7 @@ class ShippingChargesProcessorSpec extends ObjectBehavior $shippingMethod->getName()->willReturn('FedEx'); $adjustment->setAmount(450)->shouldBeCalled(); - $adjustment->setLabel(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); + $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); $adjustment->setDescription('FedEx')->shouldBeCalled(); $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); diff --git a/src/Sylius/Component/Core/spec/Promotion/Action/FixedDiscountActionSpec.php b/src/Sylius/Component/Core/spec/Promotion/Action/FixedDiscountActionSpec.php index ca0772e9fd..49012aed89 100644 --- a/src/Sylius/Component/Core/spec/Promotion/Action/FixedDiscountActionSpec.php +++ b/src/Sylius/Component/Core/spec/Promotion/Action/FixedDiscountActionSpec.php @@ -50,7 +50,7 @@ class FixedDiscountActionSpec extends ObjectBehavior $promotion->getDescription()->willReturn('promotion description'); $adjustment->setAmount(-500)->shouldBeCalled(); - $adjustment->setLabel(AdjustmentInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled(); + $adjustment->setType(AdjustmentInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled(); $adjustment->setDescription('promotion description')->shouldBeCalled(); $originator->setOrigin($adjustment, $promotion)->shouldBeCalled(); diff --git a/src/Sylius/Component/Core/spec/Promotion/Action/PercentageDiscountActionSpec.php b/src/Sylius/Component/Core/spec/Promotion/Action/PercentageDiscountActionSpec.php index 94a75049ad..1f53d90084 100644 --- a/src/Sylius/Component/Core/spec/Promotion/Action/PercentageDiscountActionSpec.php +++ b/src/Sylius/Component/Core/spec/Promotion/Action/PercentageDiscountActionSpec.php @@ -51,7 +51,7 @@ class PercentageDiscountActionSpec extends ObjectBehavior $promotion->getDescription()->willReturn('promotion description'); $adjustment->setAmount(-2500)->shouldBeCalled(); - $adjustment->setLabel(AdjustmentInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled(); + $adjustment->setType(AdjustmentInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled(); $adjustment->setDescription('promotion description')->shouldBeCalled(); $originator->setOrigin($adjustment, $promotion)->shouldBeCalled(); diff --git a/src/Sylius/Component/Order/Model/Adjustment.php b/src/Sylius/Component/Order/Model/Adjustment.php index 02f85db15f..07835c5acc 100644 --- a/src/Sylius/Component/Order/Model/Adjustment.php +++ b/src/Sylius/Component/Order/Model/Adjustment.php @@ -34,7 +34,7 @@ class Adjustment implements AdjustmentInterface /** * @var string */ - protected $label; + protected $type; /** * @var string @@ -127,17 +127,17 @@ class Adjustment implements AdjustmentInterface /** * {@inheritdoc} */ - public function getLabel() + public function getType() { - return $this->label; + return $this->type; } /** * {@inheritdoc} */ - public function setLabel($label) + public function setType($type) { - $this->label = $label; + $this->type = $type; } /** diff --git a/src/Sylius/Component/Order/Model/AdjustmentInterface.php b/src/Sylius/Component/Order/Model/AdjustmentInterface.php index d838b18392..30ddebef9d 100644 --- a/src/Sylius/Component/Order/Model/AdjustmentInterface.php +++ b/src/Sylius/Component/Order/Model/AdjustmentInterface.php @@ -32,12 +32,12 @@ interface AdjustmentInterface extends TimestampableInterface, OriginAwareInterfa /** * @return string */ - public function getLabel(); + public function getType(); /** - * @param string $label + * @param string $type */ - public function setLabel($label); + public function setType($type); /** * @return string diff --git a/src/Sylius/Component/Order/Model/Order.php b/src/Sylius/Component/Order/Model/Order.php index 93b808b33c..70c12478f0 100644 --- a/src/Sylius/Component/Order/Model/Order.php +++ b/src/Sylius/Component/Order/Model/Order.php @@ -282,7 +282,7 @@ class Order implements OrderInterface } return $this->adjustments->filter(function (AdjustmentInterface $adjustment) use ($type) { - return $type === $adjustment->getLabel(); + return $type === $adjustment->getType(); }); } diff --git a/src/Sylius/Component/Order/Model/OrderItem.php b/src/Sylius/Component/Order/Model/OrderItem.php index 93dd272710..86db90306d 100644 --- a/src/Sylius/Component/Order/Model/OrderItem.php +++ b/src/Sylius/Component/Order/Model/OrderItem.php @@ -144,7 +144,7 @@ class OrderItem implements OrderItemInterface } return $this->adjustments->filter(function (AdjustmentInterface $adjustment) use ($type) { - return $type === $adjustment->getLabel(); + return $type === $adjustment->getType(); }); } diff --git a/src/Sylius/Component/Order/spec/Model/AdjustmentSpec.php b/src/Sylius/Component/Order/spec/Model/AdjustmentSpec.php index 8399fa9307..fe7d4b3c3d 100644 --- a/src/Sylius/Component/Order/spec/Model/AdjustmentSpec.php +++ b/src/Sylius/Component/Order/spec/Model/AdjustmentSpec.php @@ -65,15 +65,15 @@ class AdjustmentSpec extends ObjectBehavior $this->getAdjustable()->shouldReturn(null); } - function it_has_no_label_by_default() + function it_has_no_type_by_default() { - $this->getLabel()->shouldReturn(null); + $this->getType()->shouldReturn(null); } - function its_label_is_mutable() + function its_type_is_mutable() { - $this->setLabel('Shipping Fee'); - $this->getLabel()->shouldReturn('Shipping Fee'); + $this->setType('some type'); + $this->getType()->shouldReturn('some type'); } function it_has_no_description_by_default() From bd39ff7323527ff308dd919acd2b707d801a2f05 Mon Sep 17 00:00:00 2001 From: Piotr Walkow Date: Fri, 6 Nov 2015 11:15:19 +0000 Subject: [PATCH 2/2] Added changelog changes for BC break about adjustment label to type --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45401110f6..b326b4bcb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ To get the diff between two versions, go to https://github.com/Sylius/Sylius/com * feature #3110 [BC BREAK] Bumped minimal versions, major changes: PHP >=5.5.9, Symfony ^2.7 * bc break #3364 [BC BREAK] Renamed setDefaultOptions to configureOptions + * bc break #3536 [BC BREAK] Renamed label to type on adjustment ## v0.15 (2015-09-08)