Provide option to only add item to wishlist once.

Created on 10 September 2020, about 4 years ago
Updated 31 August 2023, about 1 year ago

It's quite common with wishlist's to only add the item once.

It would be nice to add an option to do this i.e. click 'Add to wishlist' button, button changes to 'Added to wishlist'. Click the button again and it removes it from your wishlist. This way we can remove the quantity display next to each item in the wishlist and be a better experience for the user.

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom rviner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Assigned to karengrey
  • πŸ‡¬πŸ‡§United Kingdom karengrey
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    36 pass
  • Status changed to Needs review about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom karengrey
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 8 months ago
    36 pass
  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    vmarchuk β†’ made their first commit to this issue’s fork.

  • Pipeline finished with Success
    8 months ago
    Total: 338s
    #124920
  • Pipeline finished with Success
    8 months ago
    Total: 397s
    #125178
  • Pipeline finished with Success
    8 months ago
    Total: 284s
    #125200
  • Pipeline finished with Success
    8 months ago
    Total: 453s
    #125226
  • πŸ‡§πŸ‡ΎBelarus savage1974

    Hi, all
    For complete happiness the only thing missing is an update of the wishlist block via Ajax:
    In commerce_wishlist.module make some changes:
    1. add this row to "commerce_wishlist_add_to_wishlist_form_ajax" function:

    $response->addCommand(new ReplaceCommand('.wishlist-block', getWishlistBlock()));
    

    2. add 2 functions:

     /**
       * Get wishlist block.
       *
       * @return array|NULL
       *   Return render of wishlist block.
       */
       function getWishlistBlock(): ?array {
        $block_id = getWishlistBlockId();
        if ($block_id !== FALSE) {
          $block = Block::load($block_id);
          $render =  \Drupal::entityTypeManager()->getViewBuilder('block')
            ->view($block);
        }
        return $render ?? NULL;
      }
    
      /**
       * Gets the machine name of a commerce wishlist block visible on the current page.
       *
       * Returns only the first Wishlist found.
       *
       * @return string|false
       *   Return id of the first commerce wishlist block found on current page.
       *   Returns FALSE if no commerce wishlist block is visible.
       */
      function getWishlistBlockId(): string|false {
        // Returns an array of regions each with an array of blocks.
        $regions = \Drupal::service('block.repository')->getVisibleBlocksPerRegion();
        // Iterate all visible blocks and regions.
        foreach ($regions as $region) {
          foreach ($region as $block) {
            $plugin_id = $block->get('plugin');
            // Check if this is a commerce wishlist block.
            if ($plugin_id === 'commerce_wishlist') {
              return $block->id();
            }
          }
        }
    
        return FALSE;
      }
    
  • πŸ‡¨πŸ‡­Switzerland Lukas von Blarer

    luksak β†’ made their first commit to this issue’s fork.

  • πŸ‡¨πŸ‡­Switzerland Lukas von Blarer

    Updating the wishlist block via ajax was accidentally removed in this MR. I just added it back.

    Besides that the MR work perfectly for me.

Production build 0.71.5 2024