Skip to content

Commit

Permalink
Merge pull request #227 from mamazu/making_the_wishlist_timestampable
Browse files Browse the repository at this point in the history
Making the wishlist timestampable
  • Loading branch information
senghe authored Oct 30, 2023
2 parents 4124f89 + de6231c commit 8d09078
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Entity/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Resource\Model\TimestampableTrait;

class Wishlist implements WishlistInterface
{
use TimestampableTrait;

protected ?int $id = null;

protected ?string $name;
Expand All @@ -38,6 +41,8 @@ public function __construct()
$this->wishlistProducts = new ArrayCollection();
$this->token = new WishlistToken();
$this->id = null;

$this->createdAt = new \DateTime();
}

public function getId(): ?int
Expand Down
32 changes: 32 additions & 0 deletions src/Migrations/Version20231015123538.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20231015123538 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adding timestampable columns to track creating and updating a wishlist';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE bitbag_wishlist ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE bitbag_wishlist DROP created_at, DROP updated_at');
}
}
8 changes: 8 additions & 0 deletions src/Resources/config/doctrine/Wishlist.orm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
Expand Down Expand Up @@ -30,6 +31,13 @@
<join-column name="channel_id" on-delete="CASCADE" />
</many-to-one>

<field name="createdAt" column="created_at" type="datetime">
<gedmo:timestampable on="create"/>
</field>
<field name="updatedAt" column="updated_at" type="datetime" nullable="true">
<gedmo:timestampable on="update"/>
</field>

<indexes>
<index name="token_idx" columns="token"/>
<index name="channel_shop_user_token_idx" columns="channel_id,shop_user_id,token"/>
Expand Down
1 change: 1 addition & 0 deletions tests/Behat/Context/Api/WishlistContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function userHasAWishlist(): void
$this->getOptions(self::POST, [])
);

Assert::eq($response->getStatusCode(), 201);
$jsonBody = json_decode((string) $response->getBody());

/** @var WishlistInterface $wishlist */
Expand Down

0 comments on commit 8d09078

Please sign in to comment.