theming – Adding Drupal 8/9 Commerce Wishlist Share Mail Template Variables from Form

I am trying to add 2 additional form fields to the Wishlist Share form where the user input will be rendered in the email. I have been able to add the fields to the form, but I am not sure how to add the user’s input in the email twig template.

Here is how I have updated the form() function:

  public function form(array $form, FormStateInterface $form_state) {
    $form('#tree') = TRUE;
    $form('#attached')('library')() = 'core/drupal.dialog.ajax';
    // Workaround for core bug #2897377.
    $form('#id') = Html::getId($form_state->getBuildInfo()('form_id'));

    $form('to') = (
      '#type' => 'email',
      '#title' => $this->t('Recipient Email'),
      '#required' => TRUE,
    );

// COMBAK my edit

    $form('sender_name') = (
      '#type' => 'textfield',
      '#title' => $this->t('Your Name'),
      '#required' => FALSE,
    );

    $form('sender_message') = (
      '#type' => 'textarea',
      '#title' => $this->t('Your Message'),
      '#required' => FALSE,
    );

// COMBAK eo my edit

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function actions(array $form, FormStateInterface $form_state) {
    $actions('submit') = (
      '#type' => 'submit',
      '#value' => $this->t('Send email'),
      '#submit' => ('::submitForm'),
    );
    if ($this->isAjax()) {
      $actions('submit')('#ajax')('callback') = '::ajaxSubmit';
    }

    return $actions;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var Drupalcommerce_wishlistEntityWishlistInterface $wishlist */
    $wishlist = $this->entity;
    $to = $form_state->getValue('to');

    // COMBAK: my added vars
    $sender_name = $form_state->getValue('sender_name');
    $sender_message = $form_state->getValue('sender_message');

    $this->wishlistShareMail->send($wishlist, $to, $sender_name, $sender_message);

    $this->messenger()->addStatus($this->t('Shared the wishlist to @recipient.', (
      '@recipient' => $to,
    )));
    $form_state->setRedirectUrl($wishlist->toUrl('user-form'));
  }

This is the function that calls the mailHandler that I have updated:

public function send(WishlistInterface $wishlist, $to, $sender_name, $sender_message) {
    $owner = $wishlist->getOwner();

    $subject = $this->t('Check out my @site-name wishlist', (
      '@site-name' => $this->configFactory->get('system.site')->get('name'),
    ));
    $body = (
      '#theme' => 'commerce_wishlist_share_mail',
      '#wishlist_entity' => $wishlist,
      // COMBAK: my added vars
      '#sender_name' => $sender_name,
      '#sender_message' => $sender_message,
    );
    $params = (
      'id' => 'wishlist_share',
      'from' => $owner->getEmail(),
      'wishlist' => $wishlist,
    );

    return $this->mailHandler->sendMail($to, $subject, $body, $params);
  }

And this is the preprocees function provided by the commerce wishlist module:

function template_preprocess_commerce_wishlist_share_mail(array &$variables) {
  /** @var Drupalcommerce_wishlistEntityWishlistInterface $wishlist */
  $wishlist = $variables('wishlist_entity');
  $wishlist_url = $wishlist->toUrl('canonical', ('absolute' => TRUE));

  $variables('wishlist_url') = $wishlist_url->toString();

  // COMBAK: my added vars
  //$sender_name = $variables('sender_name');
}

And finally the twig template for the email itself:

{#
/**
 * @file
 * Template for the wishlist share email.
 *
 * Available variables:
 * - wishlist_entity: The wishlist entity.
 * - wishlist_url: The wishlist url.
 *
 * @ingroup themeable
 */
#}
<p>
  {% trans %}Check out my wishlist!{% endtrans %}
</p>

<p>
  {% trans %}I use my wishlist for keeping track of items I am interested in.{% endtrans %} <br>
  {% trans %}To see the list in the store and buy items from it, <a href="{{ wishlist_url }}">click here</a>.{% endtrans %}
</p>

<p>
  {% trans %}Thanks for having a look!{% endtrans %}
</p>

I haven’t been able to figure out how to access the variables I added to the body() array in the twig template.

Any help would be greatly appreciated.

Thanks!

Magento2 get the latest wishlist collection

How we can get the latest wishlist collection for a particular login customer without cache clean in Magento2?

magento2 – Magento 2.3 Wishlist API free extension needed

This is continuation for the following closed question:

Magento 2.3 Wishlist API free extension

As you can see I extremely sad about some god that closed a good question.

Well let us go again…


I need to add, and remove products from a client’s wishlist via Magento REST API. But Magento 2 core code does not have it.

… Anyone can help me with free wishlist API extensions compatible with Magento 2.3 ?

I could make this by my own but it take me a couple of days coding….

Thanks…. and electricity binary bits empowered god I praise please don’t close good questions again lol…

Magento 2.3 Wishlist API free extension

Anyone can help me with free wishlist API extensions compatible with Magento 2.3 ?

Thanks !!

wishlist – How to move Wish List next to Qty input box in product detail page?

To move the element next to the input box you have to create these files in your local theme:

app/design/frontend/Custom/default/Magento_Wishlist/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="view.addto.wishlist" remove="true"/>
        <referenceBlock name="product.info.addtocart">
            <block class="MagentoWishlistBlockCatalogProductViewAddToWishlist" name="add-to-wishlist" template="Magento_Wishlist::catalog/product/view/addto/wishlist.phtml"/>
        </referenceBlock>
    </body>
</page>

app/design/frontend/Custom/default/Magento_Catalog/templates/product/view/addtocart.phtml

<?php
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()) :?>
<div class="box-tocart">
    <div class="fieldset">
        <?php if ($block->shouldRenderQuantity()) :?>
        <div class="field qty">
            <label class="label" for="qty"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
            <div class="control">
                <input type="number"
                       name="qty"
                       id="qty"
                       min="0"
                       value="<?= $block->getProductDefaultQty() * 1 ?>"
                       title="<?= $block->escapeHtmlAttr(__('Qty')) ?>"
                       class="input-text qty"
                       data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                       />
                <span class="product-social-links">
                    <span clas="product-addto-links" data-role="add-to-links">
                        <?= $block->getBlockHtml('add-to-wishlist') ?>
                    </span>
                </span>

            </div>

        </div>

        <?php endif; ?>
        <div class="actions">
            <button type="submit"
                    title="<?= $block->escapeHtmlAttr($buttonTitle) ?>"
                    class="action primary tocart"
                    id="product-addtocart-button" disabled>
                <span><?= $block->escapeHtml($buttonTitle) ?></span>
            </button>
            <?= $block->getChildHtml('', true) ?>
        </div>
    </div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {}
        }
    }
</script>

The wishlist block will then appear next to the input field in the dom. You will have to use css for the finishing touch:

enter image description here

Ajax Add to cart in wishlist page magento 2.4

I’m looking for a way to add ajax functionality to the wishlist page. So when I add a product to the cart in my wishlist page it utilizes ajax.

How would I approach this?

Hope for an answer. Thanks in advance.

magento2 – Replace My Wishlist Text with Icon

I want to know how to replace the “My Wish List” text in toplinks with an icon. I don’t want an Icon with pseudo code like “::before”. Adding a <i> </i>– tag in the code should be the solution.

The text of My Wish List we can edit in “getLabel()” function of “Link.php” in module-wishlist. But I don’t want any text. Only the Icon should be in storefront visible. If I set the return value to an empty string in getLabel() function then in mobile view it is not visible.

Where I can do that?
I think we need to create an own module and overwrite the files. But which file and what exactly?

enter image description here

static block – Show wishlist counter on header when it doesnt have items

I need to display cart and wishlist counters on my own header block. For the first one i’ve just modified the CSS to display block.
enter image description here

But I can’t find how the wish list counter works, so it will show 0 when it has no items.
enter image description here

Thank you very much for your help.

Magento 2 : How to generate programmatically wishlist sharing code

i have Magento 2.3 and i want to manage customer wishlist via database.
I understand how it works but i don’t know how can i generate sharing_code on my php script.

Thanks

Antonello

Item not added to the Wishlist if the user is not logged in Magento 2.3.4

Item is not adding to wishlist if user is not logged-in.

Scenario:

  1. User is not logged-in
  2. Click on Wishlist Button
  3. Redirect to login page and showing error message to login.
  4. After login customer redirect to My account Dashboard but product is not adding to wishlist.

How can I fixed the issue? I am using magento 2.3