Skip to content

Commit

Permalink
Fixed more todos
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 3, 2024
1 parent 7ea37de commit fc05b68
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 28 deletions.
11 changes: 5 additions & 6 deletions src/Controller/RemoveWishlistItemAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Persistence\ManagerRegistry;
use Setono\Doctrine\ORMTrait;
use Setono\SyliusWishlistPlugin\Model\UserWishlistInterface;
use Setono\SyliusWishlistPlugin\Model\WishlistInterface;
use Setono\SyliusWishlistPlugin\Provider\WishlistProviderInterface;
use Setono\SyliusWishlistPlugin\Security\Voter\WishlistVoter;
Expand All @@ -24,20 +23,20 @@ public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly Security $security,
ManagerRegistry $managerRegistry,
/** @var class-string<UserWishlistInterface> $userWishlistClass */
private readonly string $userWishlistClass,
/** @var class-string<WishlistInterface> $wishlistClass */
private readonly string $wishlistClass,
) {
$this->managerRegistry = $managerRegistry;
}

public function __invoke(string $uuid, int $id): RedirectResponse
{
$manager = $this->getManager($this->userWishlistClass);
$manager = $this->getManager($this->wishlistClass);

/** @var UserWishlistInterface|null $wishlist */
/** @var WishlistInterface|null $wishlist */
$wishlist = $manager->createQueryBuilder()
->select('o')
->from($this->userWishlistClass, 'o')
->from($this->wishlistClass, 'o')
->andWhere('o.uuid = :uuid')
->setParameter('uuid', $uuid)
->getQuery()
Expand Down
6 changes: 6 additions & 0 deletions src/Factory/WishlistItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function createWithProduct(ProductInterface $product, int $quantity = 1):
$wishlistItem->setProduct($product);
$wishlistItem->setQuantity($quantity);

if ($product->isSimple()) {
$variant = $product->getVariants()->first();
Assert::isInstanceOf($variant, ProductVariantInterface::class);
$wishlistItem->setVariant($variant);
}

return $wishlistItem;
}

Expand Down
22 changes: 14 additions & 8 deletions src/Form/Type/WishlistItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
Expand All @@ -33,15 +34,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
return;
}

// todo handle simple products

$form = $event->getForm();
$form->add('variant', ProductVariantChoiceType::class, [
'choice_label' => fn (ProductVariantInterface $variant) => implode(', ', array_map(static fn ($optionValue) => sprintf('%s: %s', (string) $optionValue->getOption()?->getName(), (string) $optionValue->getValue()), $variant->getOptionValues()->toArray())),
'placeholder' => 'setono_sylius_wishlist.ui.select_variant',
'product' => $product,
'expanded' => false,
]);

if ($product->isSimple()) {
$form->add('variant', TextType::class, [
'disabled' => true,
]);
} else {
$form->add('variant', ProductVariantChoiceType::class, [
'choice_label' => fn (ProductVariantInterface $variant) => implode(', ', array_map(static fn ($optionValue) => sprintf('%s: %s', (string) $optionValue->getOption()?->getName(), (string) $optionValue->getValue()), $variant->getOptionValues()->toArray())),
'placeholder' => 'setono_sylius_wishlist.ui.select_variant',
'product' => $product,
'expanded' => false,
]);
}
});
}

Expand Down
10 changes: 8 additions & 2 deletions src/Provider/CompositeWishlistProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public function getWishlists(): array

public function getPreSelectedWishlists(): array
{
// todo implement
return $this->getWishlists();
foreach ($this->services as $service) {
$wishlists = $service->getPreSelectedWishlists();
if ([] !== $wishlists) {
return $wishlists;
}
}

return [];
}
}
4 changes: 0 additions & 4 deletions src/Resources/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ setono_sylius_wishlist_shop:
prefix: /{_locale}
requirements:
_locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$

setono_sylius_wishlist_admin:
resource: "@SetonoSyliusWishlistPlugin/Resources/config/routes/admin.yaml"
prefix: /admin
1 change: 0 additions & 1 deletion src/Resources/config/routes/admin.yaml

This file was deleted.

6 changes: 1 addition & 5 deletions src/Resources/config/routes_no_locale.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# By default Sylius uses urls like https://example.com/en_US/, but Sylius also offers the option to disable
# By default, Sylius uses urls like https://example.com/en_US/, but Sylius also offers the option to disable
# localized URLs (see https://docs.sylius.com/en/latest/cookbook/shop/disabling-localised-urls.html).
# To accommodate this in your plugin, provide a routes file for non localized stores and tell this in the README.md

setono_sylius_wishlist_shop:
resource: "@SetonoSyliusWishlistPlugin/Resources/config/routes/shop.yaml"

setono_sylius_wishlist_admin:
resource: "@SetonoSyliusWishlistPlugin/Resources/config/routes/admin.yaml"
prefix: /admin
2 changes: 1 addition & 1 deletion src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<argument type="service" id="router"/>
<argument type="service" id="Symfony\Bundle\SecurityBundle\Security"/>
<argument type="service" id="doctrine"/>
<argument>%setono_sylius_wishlist.model.user_wishlist.class%</argument>
<argument>%setono_sylius_wishlist.model.wishlist.class%</argument>
</service>

<service id="Setono\SyliusWishlistPlugin\Controller\AddWishlistToCartAction" public="true">
Expand Down
12 changes: 11 additions & 1 deletion src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="setono_sylius_wishlist.form.type.wishlist.validation_groups" type="collection">
<parameter>setono_sylius_wishlist</parameter>
</parameter>

<parameter key="setono_sylius_wishlist.form.type.wishlist_item.validation_groups" type="collection">
<parameter>setono_sylius_wishlist</parameter>
</parameter>
</parameters>
<services>
<!-- TODO: Add validation groups -->
<service id="Setono\SyliusWishlistPlugin\Form\Type\WishlistType">
<argument>%setono_sylius_wishlist.model.wishlist.class%</argument>
<argument>%setono_sylius_wishlist.form.type.wishlist.validation_groups%</argument>

<tag name="form.type"/>
</service>

<service id="Setono\SyliusWishlistPlugin\Form\Type\WishlistItemType">
<argument>%setono_sylius_wishlist.model.wishlist_item.class%</argument>
<argument>%setono_sylius_wishlist.form.type.wishlist_item.validation_groups%</argument>

<tag name="form.type"/>
</service>
Expand Down

0 comments on commit fc05b68

Please sign in to comment.