-
-
Notifications
You must be signed in to change notification settings - Fork 11
[MAINTENANCE] Wishlist refactor #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.0
Are you sure you want to change the base?
Conversation
src/Twig/Component/Common/AddToWishlist/AddToSelectedWishlistButtonComponent.php
Outdated
Show resolved
Hide resolved
src/Twig/Component/Common/AddToWishlist/AddToSelectedWishlistButtonComponent.php
Outdated
Show resolved
Hide resolved
| <button type="button" | ||
| class="{{ btn_class }}" | ||
| {{ sylius_test_html_attribute('wishlist-add-selected-to-cart') }} | ||
| onmousedown="(function(btn){try{var root=btn.closest('[data-controller]'); var elSel=document.getElementById('wishlist_selected_indices'); var json = (elSel && elSel.value) ? elSel.value : '[]'; btn.setAttribute('data-live-param-selection-value', json); if(root){ var el=root.querySelector('#bulk_selection_holder'); if(el){ el.value=json; el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true})); } }}catch(e){console.error(e);}})(this)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be extracted to a js file, same case below
| > | ||
| class="{{ btn_class }}" | ||
| {{ sylius_test_html_attribute('wishlist-copy-to-wishlist') }} | ||
| onclick="(function(btn){try{var json=(document.getElementById('wishlist_selected_indices')||{value:'[]'}).value; var indices=[]; try{indices=JSON.parse(json)||[];}catch(_){} var ids=[]; indices.forEach(function(idx){ var hid=document.querySelector('input[name=\'wishlist_collection[items]['+idx+'][variant]\']'); if(hid){ ids.push(parseInt(hid.value)); } }); btn.setAttribute('data-live-param-selection-value', JSON.stringify(ids)); var root=btn.closest('[data-controller]'); if(root){ var el=root.querySelector('#copy_preselected_holder'); if(el){ el.value=JSON.stringify(ids); el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true})); } }}catch(e){console.error(e);}})(this)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
| <button type="button" | ||
| class="{{ btn_class }}" {{ sylius_test_html_attribute('wishlist-export-to-pdf-from-wishlist') }} | ||
| formaction="{{ path('sylius_wishlist_plugin_shop_locale_wishlist_export_to_pdf', { wishlistId: wishlist.id }) }}"> | ||
| onmousedown="(function(root){try{var json=(document.getElementById('wishlist_selected_indices')||{value:'[]'}).value; var el=root.querySelector('#export_pdf_selection_holder'); el.value=json; el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true}));}catch(e){console.error(e);}})(this.closest('[data-controller]'))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
| type="button" | ||
| data-bb-toggle="wishlist-save" | ||
| {{ sylius_test_html_attribute('wishlist-save-changes') }} | ||
| onclick="(function(root){try{var inputs=document.querySelectorAll('input[name^=\'wishlist_collection[items]\'][name$=\'[cartItem][cartItem][quantity]\']');var map={};inputs.forEach(function(inp){var m=inp.name.match(/items\]\[(\d+)\]/); if(m){map[m[1]]=parseInt(inp.value||'0')||0;}}); var holder=root.querySelector('#quantities_holder'); if(holder){ holder.value=JSON.stringify(map); holder.dispatchEvent(new Event('input',{bubbles:true})); }}catch(e){console.error(e);}})(this.closest('[data-controller]'))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just extract all of them
|
|
||
| $selectionJson = (string) $request->request->get('selection', '[]'); | ||
| $indices = $this->decodeSelection($selectionJson); | ||
| $wishlistName = trim((string) $request->request->get('wishlistName', 'wishlist')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the wishlist name not included in the wishlist itself? Why is the value taken from the request?
| private function buildSelectedWishlistItems(Collection $wishlistProducts, array $indices): ArrayCollection | ||
| { | ||
| $cart = $this->cartContext->getCart(); | ||
| $collection = new ArrayCollection(); | ||
| foreach ($indices as $index) { | ||
| $wp = $wishlistProducts->get((int) $index); | ||
| if (null === $wp) { | ||
| continue; | ||
| } | ||
| $wi = new WishlistItem(); | ||
| $wi->setWishlistProduct($wp); | ||
| /** @var OrderItemInterface $cartItem */ | ||
| $cartItem = $this->cartItemFactory->createForProduct($wp->getProduct()); | ||
| $cartItem->setVariant($wp->getVariant()); | ||
| $this->orderItemQuantityModifier->modify($cartItem, $wp->getQuantity()); | ||
| $wi->setCartItem($this->addToCartCommandFactory->createWithCartAndCartItem($cart, $cartItem)); | ||
| $collection->add($wi); | ||
| } | ||
|
|
||
| return $collection; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, is this really needed for exporting?
| use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
|
||
| #[AsLiveComponent] | ||
| final class AddAllToCartComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| final class AddAllToCartComponent | |
| final class AddWishlistToCartComponent |
or
| final class AddAllToCartComponent | |
| final class AddWishlistedProductsToCartComponent |
?
| public function toggleAll(): void | ||
| { | ||
| $all = []; | ||
| for ($i = 0; $i < $this->itemsCount; ++$i) { | ||
| $all[$i] = !($this->selection[$i] ?? false); | ||
| } | ||
| $this->selection = $all; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this either select/deselect all? ATM, it seems to flip the current selection
| } | ||
|
|
||
| try { | ||
| $this->messageBus->dispatch(new UpdateWishlistName($newName, $wishlist)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the action of changing a name really need a separate command?
| <?php | ||
|
|
||
| declare(strict_types=1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license, in a lot of other classes as well
No description provided.