Skip to content

Commit

Permalink
Merge pull request #3 from lchhieu/add-id-to-recently_viewed_product-…
Browse files Browse the repository at this point in the history
…table

Add id column
  • Loading branch information
vienthuong authored Dec 16, 2021
2 parents 4e03395 + 5ccfa33 commit 0cdc724
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/DAL/RecentlyViewedProductDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', [], []),
]);
Expand Down
3 changes: 3 additions & 0 deletions src/DAL/RecentlyViewedProductEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
');
}
Expand Down

0 comments on commit 0cdc724

Please sign in to comment.