Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dc6e38f
Fix: specify the selected wishlist when bookmarking a product
ahmedazizabbassi Jan 10, 2025
7c79398
chore: Update vendor name for packagist deployment
ahmedazizabbassi Jan 10, 2025
c921aac
Fix: do not add product more then once in wishlist
ahmedazizabbassi Jan 10, 2025
43198dc
Fix: Refactor AddProductToSelectedWishlistInterface for better API ha…
ahmedazizabbassi Jan 10, 2025
2831b4e
Fix: add product to wishlist constructor initialization
ahmedazizabbassi Jan 10, 2025
b494069
Fix: AddProductToSelectedWishlist serialized constructor
ahmedazizabbassi Jan 10, 2025
4b4e22e
Fix: AddProductToSelectedWishlist swap parameters
ahmedazizabbassi Jan 10, 2025
993eb49
Fix: AddProductToSelectedWishlist swap constructor parameters
ahmedazizabbassi Jan 10, 2025
57beab5
Fix: AddProductToSelectedWishlist parameter name in route
ahmedazizabbassi Jan 10, 2025
4938fec
Fix: typo in AddProductToSelectedWishlist route parameter
ahmedazizabbassi Jan 10, 2025
714cf23
Fix: identifier value or configuration
ahmedazizabbassi Jan 10, 2025
b352a13
Fix: serialization
ahmedazizabbassi Jan 10, 2025
0b02934
Fix: let api-platform aware that token param is in path
ahmedazizabbassi Jan 13, 2025
8256833
Fix: create a new ApiPlatform action to add product to wishlist
ahmedazizabbassi Jan 13, 2025
578be35
Fix: import the AddProductToSelectedWishlistAction class properly
ahmedazizabbassi Jan 13, 2025
d741ea2
Fix: remove whitespaces around controller id in order to be read prop…
ahmedazizabbassi Jan 13, 2025
15be664
Fix: Get the productId from paramas not attributes
ahmedazizabbassi Jan 13, 2025
a7a947d
Fix: typo in params should be parameters
ahmedazizabbassi Jan 13, 2025
7ad57c6
Fix: Usage of attributes instead of pramas
ahmedazizabbassi Jan 13, 2025
a8d1bb0
Fix: update swagger docs
ahmedazizabbassi Jan 13, 2025
bdfdf0d
Fix: add productId to swagger and fix syntax
ahmedazizabbassi Jan 13, 2025
a434a23
Fix: use write equals to false config
ahmedazizabbassi Jan 13, 2025
c9314a9
Fix: try to remove denormalization context group to avoid validation
ahmedazizabbassi Jan 13, 2025
1d8554c
Fix: use an empty denormalization context group
ahmedazizabbassi Jan 13, 2025
78c4f23
Fix: remove add product to selected wishlist command serialization co…
ahmedazizabbassi Jan 13, 2025
6e51d77
Fix: go back to try getting productId from request body
ahmedazizabbassi Jan 13, 2025
420417d
Fix: get productId from request body
ahmedazizabbassi Jan 13, 2025
5c92102
Fix: update swagger docs
ahmedazizabbassi Jan 13, 2025
93185f0
Fix: remove unnecessary config
ahmedazizabbassi Jan 13, 2025
5edeb4c
Fix: wrong conflict logic and thrown exception
ahmedazizabbassi Jan 13, 2025
464b21d
Fix: Exception not found
ahmedazizabbassi Jan 13, 2025
9bdf6a7
Fix: Exception not found
ahmedazizabbassi Jan 13, 2025
e7801a7
Fix: update wishlist API documentation
ahmedazizabbassi Mar 19, 2025
cb154fa
Chore: update .gitignore file
ahmedazizabbassi Mar 19, 2025
ac5af6d
Chore: reset package managers to initial state
ahmedazizabbassi Mar 19, 2025
c0a1be8
show vendor
ahmedazizabbassi Jul 8, 2025
82be8cc
Enhance: add on-delete CASCADE to WishlistProduct associations
ahmedazizabbassi Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor/
/node_modules/
/node_modules
/composer.lock
/phpspec.yml

Expand All @@ -8,3 +8,6 @@

/behat.yml
/phpunit.xml

/.idea
package-lock.json
1 change: 0 additions & 1 deletion node_modules

This file was deleted.

13 changes: 7 additions & 6 deletions src/Command/Wishlist/AddProductToSelectedWishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
final class AddProductToSelectedWishlist implements AddProductToSelectedWishlistInterface
{
public function __construct(
private WishlistInterface $wishlist,
private ProductInterface $product,
private string $token,
private int $productId,

) {
}

public function getWishlist(): WishlistInterface
public function getWishlistToken(): string
{
return $this->wishlist;
return $this->token;
}

public function getProduct(): ProductInterface
public function getProductId(): int
{
return $this->product;
return $this->productId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

interface AddProductToSelectedWishlistInterface extends WishlistSyncCommandInterface
{
public function getWishlist(): WishlistInterface;
public function getWishlistToken(): string;

public function getProduct(): ProductInterface;
public function getProductId(): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,61 @@
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToSelectedWishlistInterface;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Exception\ProductNotFoundException;
use BitBag\SyliusWishlistPlugin\Exception\ProductFoundException;
use BitBag\SyliusWishlistPlugin\Exception\WishlistNotFoundException;
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface;
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;


#[AsMessageHandler]
final class AddProductToSelectedWishlistHandler
{
public function __construct(
private ProductRepositoryInterface $productRepository,
private RepositoryInterface $wishlistProductRepository,
private WishlistProductFactoryInterface $wishlistProductFactory,
private WishlistRepositoryInterface $wishlistRepository,
) {
}

public function __invoke(AddProductToSelectedWishlistInterface $addProductToSelectedWishlist): void
{
$product = $addProductToSelectedWishlist->getProduct();
$wishlist = $addProductToSelectedWishlist->getWishlist();
$productId = $addProductToSelectedWishlist->getProductId();
$token = $addProductToSelectedWishlist->getWishlistToken();

/** @var ?ProductInterface $product */
$product = $this->productRepository->find($productId);

/** @var ?WishlistInterface $wishlist */
$wishlist = $this->wishlistRepository->findByToken($token);

/** @var ?WishlistProductInterface $wishlistProduct */
$wishlistProduct = $this->wishlistProductRepository->findOneBy(['product' => $product, 'wishlist' => $wishlist]);

if (null === $product) {
throw new ProductNotFoundException(
sprintf('The Product %s does not exist', $productId),
);
}

if (null === $wishlist) {
throw new WishlistNotFoundException(
sprintf('The Wishlist %s does not exist', $token),
);
}

if (null !== $wishlistProduct) {
throw new ProductFoundException(
sprintf('The Product %s already exists in wishlist', $productId)
);
}

/** @var WishlistProductInterface $wishlistProduct */
$wishlistProduct = $this->wishlistProductFactory->createForWishlistAndProduct($wishlist, $product);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file has been created by developers from Softylines.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://softylines.com and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Controller\Action\ApiPlatform;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToSelectedWishlist;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;

final class AddProductToSelectedWishlistAction
{
private MessageBusInterface $messageBus;

public function __construct(MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}

public function __invoke(Request $request): JsonResponse
{
$wishlistToken = (string) $request->attributes->get('token');
$productId = (int) $request->toArray()['productId'];

$addProductToSelectedWishlist = new AddProductToSelectedWishlist($wishlistToken, $productId);
$this->messageBus->dispatch($addProductToSelectedWishlist);

return new JsonResponse([], Response::HTTP_NO_CONTENT);
}
}
18 changes: 18 additions & 0 deletions src/Exception/ProductFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file has been created by developers from Softylines.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://softylines.com and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Exception;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

final class ProductFoundException extends NotFoundHttpException
{
}
11 changes: 9 additions & 2 deletions src/Resources/config/api_resources/Wishlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@
<itemOperation name="shop_add_product_to_wishlist">
<attribute name="method">PATCH</attribute>
<attribute name="path">/shop/wishlists/{token}/product</attribute>
<attribute name="messenger">input</attribute>
<attribute name="input">BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToWishlist</attribute>
<attribute name="controller">softylines_sylius_wishlist_plugin.controller.action.api_platform.add_product_to_selected_wishlist</attribute>
<attribute name="denormalization_context">
<attribute name="groups">shop:wishlist:add_product</attribute>
</attribute>
<attribute name="openapi_context">
<attribute name="summary">Adds product to wishlist</attribute>
<attribute name="parameters">
<attribute name="name">productId</attribute>
<attribute name="in">body</attribute>
<attribute name="required">true</attribute>
<attribute name="schema">
<attribute name="type">integer</attribute>
</attribute>
</attribute>
</attribute>
<attribute name="security">is_granted('update', object)</attribute>
</itemOperation>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/doctrine/WishlistProduct.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
</many-to-one>

<many-to-one field="product" target-entity="Sylius\Component\Product\Model\ProductInterface">
<join-column name="product_id" referenced-column-name="id" nullable="true"/>
<join-column name="product_id" referenced-column-name="id" nullable="true" on-delete="CASCADE"/>
</many-to-one>

<many-to-one field="variant" target-entity="Sylius\Component\Product\Model\ProductVariantInterface">
<join-column name="variant_id" referenced-column-name="id" nullable="true" />
<join-column name="variant_id" referenced-column-name="id" nullable="true" on-delete="CASCADE"/>
</many-to-one>

</mapped-superclass>
Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion src/Resources/config/serialization/Product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Component\Core\Model\Product">
<class name="BitBag\OpenMarketplace\Component\Product\Entity\Product">
<attribute name="id">
<group>shop:wishlist:read</group>
<group>shop:wishlist:create</group>
</attribute>
<attribute name="vendor">
<group>shop:wishlist:read</group>
</attribute>
</class>
</serializer>
6 changes: 6 additions & 0 deletions src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="softylines_sylius_wishlist_plugin.controller.action.api_platform.add_product_to_selected_wishlist"
class="BitBag\SyliusWishlistPlugin\Controller\Action\ApiPlatform\AddProductToSelectedWishlistAction">
<argument type="service" id="api_platform.message_bus"/>
<tag name="controller.service_arguments"/>
</service>

<service id="bitbag_sylius_wishlist_plugin.controller.action.api_platform.remove_product_from_wishlist_action" class="BitBag\SyliusWishlistPlugin\Controller\Action\ApiPlatform\RemoveProductFromWishlistAction">
<argument type="service" id="api_platform.message_bus"/>
<tag name="controller.service_arguments"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/message_handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
</service>

<service id="bitbag_sylius_wishlist_plugin.command_handler.wishlist.add_product_to_selected_wishlist_handler" class="BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist\AddProductToSelectedWishlistHandler">
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="bitbag_sylius_wishlist_plugin.repository.wishlist_product" />
<argument type="service" id="bitbag_sylius_wishlist_plugin.factory.wishlist_product"/>
<argument type="service" id="bitbag_sylius_wishlist_plugin.repository.wishlist"/>
<tag name="messenger.message_handler"/>
Expand Down