Skip to content

Commit

Permalink
Making the wishlist timestampable
Browse files Browse the repository at this point in the history
Adding `createdAt` and `updatedAt` fields to track if the wishlist is old and can be deleted.
  • Loading branch information
mamazu committed Oct 15, 2023
1 parent c34dd8b commit 8b54f9b
Show file tree
Hide file tree
Showing 2 changed files with 12 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
7 changes: 7 additions & 0 deletions src/Resources/config/doctrine/Wishlist.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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

0 comments on commit 8b54f9b

Please sign in to comment.