Commit 8372f42a authored by Peter Čeklovský's avatar Peter Čeklovský
Browse files

Orders

parent 2fa83981
......@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210323155904 extends AbstractMigration
final class Version20210325101949 extends AbstractMigration
{
public function getDescription() : string
{
......@@ -20,16 +20,20 @@ final class Version20210323155904 extends AbstractMigration
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE order_item CHANGE id_order orderid_id INT NOT NULL');
$this->addSql('ALTER TABLE order_item ADD CONSTRAINT FK_52EA1F096F90D45B FOREIGN KEY (orderid_id) REFERENCES orders (id)');
$this->addSql('CREATE INDEX IDX_52EA1F096F90D45B ON order_item (orderid_id)');
$this->addSql('ALTER TABLE order_item DROP FOREIGN KEY FK_52EA1F096F90D45B');
$this->addSql('DROP INDEX IDX_52EA1F096F90D45B ON order_item');
$this->addSql('ALTER TABLE order_item ADD orders_id INT DEFAULT NULL, DROP orderid_id');
$this->addSql('ALTER TABLE order_item ADD CONSTRAINT FK_52EA1F09CFFE9AD6 FOREIGN KEY (orders_id) REFERENCES orders (id)');
$this->addSql('CREATE INDEX IDX_52EA1F09CFFE9AD6 ON order_item (orders_id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE order_item DROP FOREIGN KEY FK_52EA1F096F90D45B');
$this->addSql('DROP INDEX IDX_52EA1F096F90D45B ON order_item');
$this->addSql('ALTER TABLE order_item CHANGE orderid_id id_order INT NOT NULL');
$this->addSql('ALTER TABLE order_item DROP FOREIGN KEY FK_52EA1F09CFFE9AD6');
$this->addSql('DROP INDEX IDX_52EA1F09CFFE9AD6 ON order_item');
$this->addSql('ALTER TABLE order_item ADD orderid_id INT NOT NULL, DROP orders_id');
$this->addSql('ALTER TABLE order_item ADD CONSTRAINT FK_52EA1F096F90D45B FOREIGN KEY (orderid_id) REFERENCES orders (id)');
$this->addSql('CREATE INDEX IDX_52EA1F096F90D45B ON order_item (orderid_id)');
}
}
......@@ -44,7 +44,7 @@ public function viewOrderDetailAction(Request $request , $id)
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('App:Orders')->findOrderbyId($id);
$ordersitems = $em->getRepository('App:OrderItem')->findOrderItemsbyId($id);
return $this->render('orders/order_detail.html.twig', array(
......
......@@ -44,13 +44,14 @@ class OrderItem
private $sum_total;
/**
* @ORM\ManyToOne(targetEntity=Orders::class)
* @ORM\JoinColumn(nullable=false)
* @ORM\ManyToOne(targetEntity=Orders::class, inversedBy="orderItems")
*/
private $orderid;
private $orders;
public function getId(): ?int
{
......@@ -122,17 +123,21 @@ class OrderItem
public function getOrderid(): ?Orders
public function getOrders(): ?Orders
{
return $this->orderid;
return $this->orders;
}
public function setOrderid(?Orders $orderid): self
public function setOrders(?Orders $orders): self
{
$this->orderid = $orderid;
$this->orders = $orders;
return $this;
}
}
......@@ -45,11 +45,17 @@ class Orders
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="orders")
*/
private $orderItems;
public function __construct()
{
$this->Orders = new ArrayCollection();
$this->orderItems = new ArrayCollection();
}
......@@ -130,6 +136,36 @@ class Orders
/**
* @return Collection|OrderItem[]
*/
/**
* @return Collection|OrderItem[]
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): self
{
if (!$this->orderItems->contains($orderItem)) {
$this->orderItems[] = $orderItem;
$orderItem->setOrders($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): self
{
if ($this->orderItems->removeElement($orderItem)) {
// set the owning side to null (unless already changed)
if ($orderItem->getOrders() === $this) {
$orderItem->setOrders(null);
}
}
return $this;
}
......
......@@ -51,7 +51,7 @@ class OrderItemRepository extends ServiceEntityRepository
public function findOrderItemsbyId(int $id )
{
return $this->createQueryBuilder('b')
->where('b.orderid = :u')
->where('b.orders = :u')
->setParameters(['u' => $id ])
->setMaxResults(1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment