Remove total from OrderItemUnit

This commit is contained in:
michalmarcinkowski 2015-12-31 00:32:35 +01:00 committed by Mateusz Zalewski
parent bbf6544540
commit d46c7c129b
7 changed files with 10 additions and 50 deletions

View file

@ -8,7 +8,7 @@ use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20151230142358 extends AbstractMigration
class Version20151231002659 extends AbstractMigration
{
/**
* @param Schema $schema
@ -19,6 +19,7 @@ class Version20151230142358 extends AbstractMigration
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_order_item ADD units_total INT NOT NULL');
$this->addSql('ALTER TABLE sylius_order_item_unit DROP total');
}
/**
@ -30,5 +31,6 @@ class Version20151230142358 extends AbstractMigration
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_order_item DROP units_total');
$this->addSql('ALTER TABLE sylius_order_item_unit ADD total INT NOT NULL');
}
}

View file

@ -21,7 +21,6 @@
<generator strategy="AUTO" />
</id>
<field name="total" column="total" type="integer" />
<field name="adjustmentsTotal" column="adjustments_total" type="integer" />
<many-to-one field="orderItem" target-entity="Sylius\Component\Order\Model\OrderItemInterface" inversed-by="units">

View file

@ -138,7 +138,7 @@ class OrderItem implements OrderItemInterface
}
$this->unitPrice = $unitPrice;
$this->recalculateUnits();
$this->recalculateUnitsTotal();
}
/**
@ -191,21 +191,6 @@ class OrderItem implements OrderItemInterface
$this->recalculateTotal();
}
/**
* Recalculates all units' total together with units total update.
*/
protected function recalculateUnits()
{
$this->unitsTotal = 0;
foreach ($this->units as $unit) {
$unit->recalculateTotal();
$this->unitsTotal += $unit->getTotal();
}
$this->recalculateTotal();
}
/**
* {@inheritdoc}
*/

View file

@ -25,11 +25,6 @@ class OrderItemUnit implements OrderItemUnitInterface
*/
protected $id;
/**
* @var int
*/
protected $total = 0;
/**
* @var OrderItemInterface
*/
@ -49,7 +44,6 @@ class OrderItemUnit implements OrderItemUnitInterface
{
$this->adjustments = new ArrayCollection();
$this->orderItem = $orderItem;
$this->recalculateTotal();
$this->orderItem->addUnit($this);
}
@ -66,19 +60,13 @@ class OrderItemUnit implements OrderItemUnitInterface
*/
public function getTotal()
{
return $this->total;
}
$total = $this->orderItem->getUnitPrice() + $this->adjustmentsTotal;
/**
* {@inheritdoc}
*/
public function recalculateTotal()
{
$this->total = $this->orderItem->getUnitPrice() + $this->adjustmentsTotal;
if ($this->total < 0) {
$this->total = 0;
if ($total < 0) {
return 0;
}
return $total;
}
/**
@ -184,7 +172,6 @@ class OrderItemUnit implements OrderItemUnitInterface
{
if (!$adjustment->isNeutral()) {
$this->adjustmentsTotal += $adjustment->getAmount();
$this->recalculateTotal();
}
}
@ -192,7 +179,6 @@ class OrderItemUnit implements OrderItemUnitInterface
{
if (!$adjustment->isNeutral()) {
$this->adjustmentsTotal -= $adjustment->getAmount();
$this->recalculateTotal();
}
}
@ -208,7 +194,5 @@ class OrderItemUnit implements OrderItemUnitInterface
$this->adjustmentsTotal += $adjustment->getAmount();
}
}
$this->recalculateTotal();
}
}

View file

@ -26,11 +26,6 @@ interface OrderItemUnitInterface extends AdjustableInterface
*/
public function getTotal();
/**
* Recalculates total. Should be used after every unit price change.
*/
public function recalculateTotal();
/**
* @return OrderItemInterface
*/

View file

@ -155,8 +155,6 @@ class OrderItemSpec extends ObjectBehavior
$this->addUnit($orderItemUnit1);
$this->addUnit($orderItemUnit2);
$orderItemUnit1->recalculateTotal()->shouldBeCalled();
$orderItemUnit2->recalculateTotal()->shouldBeCalled();
$this->setUnitPrice(100);
}
@ -317,8 +315,6 @@ class OrderItemSpec extends ObjectBehavior
$this->addUnit($orderItemUnit1);
$this->addUnit($orderItemUnit2);
$orderItemUnit1->recalculateTotal()->shouldBeCalled();
$orderItemUnit2->recalculateTotal()->shouldBeCalled();
$this->setUnitPrice(100);
$this->getTotal()->shouldReturn(200);
}

View file

@ -157,7 +157,7 @@ class OrderItemUnitSpec extends ObjectBehavior
$this->getTotal()->shouldReturn(1000);
}
function it_recalculates_its_total_properly_after_order_item_unit_price_change(
function it_has_proper_total_after_order_item_unit_price_change(
AdjustmentInterface $adjustment1,
AdjustmentInterface $adjustment2,
OrderItemInterface $orderItem
@ -177,7 +177,6 @@ class OrderItemUnitSpec extends ObjectBehavior
$orderItem->getUnitPrice()->willReturn(500);
$this->recalculateTotal();
$this->getTotal()->shouldReturn(650);
}