diff --git a/migrations/Version20240816193410.php b/migrations/Version20240816193410.php
new file mode 100644
index 0000000..dbcb6e8
--- /dev/null
+++ b/migrations/Version20240816193410.php
@@ -0,0 +1,35 @@
+addSql('ALTER TABLE food_vendor ADD COLUMN menu_link VARCHAR(255) DEFAULT NULL');
+ }
+
+ public function down(Schema $schema): void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, id FROM food_vendor');
+ $this->addSql('DROP TABLE food_vendor');
+ $this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, id BLOB NOT NULL, PRIMARY KEY(id))');
+ $this->addSql('INSERT INTO food_vendor (name, id) SELECT name, id FROM __temp__food_vendor');
+ $this->addSql('DROP TABLE __temp__food_vendor');
+ }
+}
diff --git a/src/Entity/FoodVendor.php b/src/Entity/FoodVendor.php
index e05d777..e4e430a 100644
--- a/src/Entity/FoodVendor.php
+++ b/src/Entity/FoodVendor.php
@@ -28,6 +28,9 @@ class FoodVendor
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $menuItems;
+ #[ORM\Column(length: 255, nullable: true)]
+ private string|null $menuLink = null;
+
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
@@ -116,4 +119,16 @@ class FoodVendor
return $this;
}
+
+ public function getMenuLink(): string|null
+ {
+ return $this->menuLink;
+ }
+
+ public function setMenuLink(string|null $menuLink): static
+ {
+ $this->menuLink = $menuLink;
+
+ return $this;
+ }
}
diff --git a/src/Form/FoodVendorType.php b/src/Form/FoodVendorType.php
index fcbdce4..9c155f6 100644
--- a/src/Form/FoodVendorType.php
+++ b/src/Form/FoodVendorType.php
@@ -15,6 +15,7 @@ final class FoodVendorType extends AbstractType
{
$builder
->add('name')
+ ->add('menuLink')
;
}
diff --git a/templates/food_vendor/show.html.twig b/templates/food_vendor/show.html.twig
index a063d4c..c4f76b4 100644
--- a/templates/food_vendor/show.html.twig
+++ b/templates/food_vendor/show.html.twig
@@ -11,6 +11,10 @@
Name |
{{ food_vendor.name }} |
+
+ Menu |
+ {{ food_vendor.menuLink }} |
+
diff --git a/templates/order_item/new.html.twig b/templates/order_item/new.html.twig
index 53aff8d..0bcddd5 100644
--- a/templates/order_item/new.html.twig
+++ b/templates/order_item/new.html.twig
@@ -7,6 +7,14 @@
{{ include('order_item/_form.html.twig') }}
+
+
+ {% if food_order.foodVendor.menuLink != '' %}
+
+ External link to Menu
+
+ {% endif %}
+
click a button to select a given menuitem
diff --git a/tests/Controller/FoodVendorControllerTest.php b/tests/Controller/FoodVendorControllerTest.php
index 9f75673..6c4c52b 100644
--- a/tests/Controller/FoodVendorControllerTest.php
+++ b/tests/Controller/FoodVendorControllerTest.php
@@ -38,6 +38,7 @@ final class FoodVendorControllerTest extends DbWebTest
{
$fixture = new FoodVendor;
$fixture->setName('My Title');
+ $fixture->setMenuLink('https://example.com/');
$this->manager->persist($fixture);
$this->manager->flush();
@@ -45,9 +46,17 @@ final class FoodVendorControllerTest extends DbWebTest
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->assertResponseIsSuccessful();
+
$nameNode = $crawler->filter('td')
->last();
- $this->assertSame('My Title', $nameNode->text());
+ $nameNode = $crawler->filter(
+ '.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
+ )->text();
+ $menuLinkNode = $crawler->filter(
+ '.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(1)'
+ )->text();
+ $this->assertSame('My Title', $nameNode);
+ $this->assertSame('https://example.com/', $menuLinkNode);
}
public function testShowMenuItems(): void
@@ -91,9 +100,10 @@ final class FoodVendorControllerTest extends DbWebTest
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->assertResponseIsSuccessful();
- $nameNode = $crawler->filter('td')
- ->last();
- $this->assertSame('My Title', $nameNode->text());
+ $nameNode = $crawler->filter(
+ '.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
+ )->text();
+ $this->assertSame('My Title', $nameNode);
$itemNodes = $crawler->filter('li');
@@ -112,6 +122,7 @@ final class FoodVendorControllerTest extends DbWebTest
$this->client->submitForm('Update', [
'food_vendor[name]' => 'Something New',
+ 'food_vendor[menuLink]' => 'https://example.com/',
]);
self::assertResponseRedirects('/food/vendor/');
@@ -119,6 +130,7 @@ final class FoodVendorControllerTest extends DbWebTest
$fixture = $this->repository->findAll();
self::assertSame('Something New', $fixture[0]->getName());
+ self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
}
#[Override]