Skip to content

Commit

Permalink
Fixed bug in adding to cart and allowed the wishlist name to be editable
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Nov 5, 2024
1 parent 1f62925 commit 38254b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Controller/AddWishlistToCartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Setono\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
use Sylius\Component\Core\Factory\CartItemFactoryInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Order\Context\CartContextInterface;
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface;
use Sylius\Component\Order\Modifier\OrderModifierInterface;
Expand Down Expand Up @@ -54,7 +55,8 @@ public function __invoke(Request $request, string $uuid): RedirectResponse
));
}

$cartItem = $this->cartItemFactory->createForCart($cart);
/** @var OrderItemInterface $cartItem */
$cartItem = $this->cartItemFactory->createNew();
$cartItem->setVariant($item->getVariant());

$this->orderItemQuantityModifier->modify($cartItem, $item->getQuantity());
Expand Down
5 changes: 5 additions & 0 deletions src/Form/Type/WishlistType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class WishlistType extends AbstractResourceType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'label' => false,
'required' => false,
])
->add('items', CollectionType::class, [
'entry_type' => WishlistItemType::class,
'allow_add' => false,
Expand Down
1 change: 0 additions & 1 deletion src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ setono_sylius_wishlist:
ui:
add_wishlist_to_cart: Add wishlist to cart
copy: Copy
wishlist_header: "Wishlist: %name%"
wishlist_subheader: Here you can edit the quantity of the products in your wishlist. You can also select the variants you want and remove products from your wishlist. Finally you can share your wishlist with others by copying the URL below.
wishlists: Wishlists
wishlists_header: Wishlists
Expand Down
12 changes: 9 additions & 3 deletions src/Resources/views/shop/wishlist/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{ form_errors(form) }}

<h1 class="ui monster section dividing header">
{{ 'setono_sylius_wishlist.ui.wishlist_header'|trans({'%name%' : wishlist.name }) }}
<span data-editable="{{ form_widget(form.name)|e('html_attr') }}">{{ wishlist.name }}</span>
<div class="sub header">{{ 'setono_sylius_wishlist.ui.wishlist_subheader'|trans }}</div>
</h1>

Expand Down Expand Up @@ -111,6 +111,7 @@
{% block javascripts %}
{{ parent() }}

{# todo create a component for this #}
<script>
document.querySelector('.wishlist-url button').addEventListener('click', function() {
const input = document.querySelector(".wishlist-url input");
Expand All @@ -120,12 +121,17 @@
navigator.clipboard.writeText(input.value)
.then(() => {
// Optional: Notify the user that the text has been copied
alert("Copied to clipboard: " + input.value);
console.log("Copied to clipboard: " + input.value);
})
.catch((error) => {
console.error("Could not copy text: ", error);
});
});
document.querySelectorAll('[data-editable]').forEach((element) => {
element.addEventListener('click', () => {
element.innerHTML = element.dataset.editable;
}, {once: true});
});
</script>
{% endblock %}

0 comments on commit 38254b7

Please sign in to comment.