From 5ccfa338ce99294e6f92f73449dd3d410acc616c Mon Sep 17 00:00:00 2001 From: Hieu Luong Date: Thu, 16 Dec 2021 15:36:28 +0700 Subject: [PATCH] Add id column --- src/DAL/RecentlyViewedProductDefinition.php | 3 +++ src/DAL/RecentlyViewedProductEntity.php | 3 +++ .../Migration1600098518CreateRecentlyViewedProductTable.php | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/DAL/RecentlyViewedProductDefinition.php b/src/DAL/RecentlyViewedProductDefinition.php index 1a27a55..5b19966 100644 --- a/src/DAL/RecentlyViewedProductDefinition.php +++ b/src/DAL/RecentlyViewedProductDefinition.php @@ -3,7 +3,9 @@ namespace RecentlyViewedProduct\DAL; use RecentlyViewedProduct\DAL\Field\RecentProductField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required; +use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField; use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\MappingEntityDefinition; @@ -35,6 +37,7 @@ public function defaultFields(): array protected function defineFields(): FieldCollection { return new FieldCollection([ + (new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()), (new StringField('token', 'token'))->setFlags(new Required()), new RecentProductField('recent_product', 'recentProduct', [], []), ]); diff --git a/src/DAL/RecentlyViewedProductEntity.php b/src/DAL/RecentlyViewedProductEntity.php index b81da0e..7ddc4f6 100644 --- a/src/DAL/RecentlyViewedProductEntity.php +++ b/src/DAL/RecentlyViewedProductEntity.php @@ -4,9 +4,12 @@ use RecentlyViewedProduct\Struct\RecentProductCollection; use Shopware\Core\Framework\DataAbstractionLayer\Entity; +use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait; class RecentlyViewedProductEntity extends Entity { + use EntityIdTrait; + /** * @var string */ diff --git a/src/Migration/Migration1600098518CreateRecentlyViewedProductTable.php b/src/Migration/Migration1600098518CreateRecentlyViewedProductTable.php index 2822665..2a6902c 100644 --- a/src/Migration/Migration1600098518CreateRecentlyViewedProductTable.php +++ b/src/Migration/Migration1600098518CreateRecentlyViewedProductTable.php @@ -16,8 +16,10 @@ public function update(Connection $connection): void { $connection->executeUpdate(' CREATE TABLE IF NOT EXISTS `recently_viewed_product` ( - `token` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE, - `recent_product` JSON NULL + `id` BINARY(16) NOT NULL, + `token` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE, + `recent_product` JSON NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; '); }