magento2.4 – Magento 2: why we use cache mechanism at a block level?

I have a doubt that I see some cache codes in layout xml like below

 <referenceContainer name="store.menu">
            <block class="VendorMegamenuBlockMegamenu"
                name="megamenu"
                template="Vendor_Megamenu::Vendor/Megamenu/megamenu.phtml"
                before="-" ttl="3600">
                 <arguments>
                    <argument name="cache_lifetime" xsi:type="number">3600</argument>
                </arguments>
             </block>
        </referenceContainer>

So I do not define cache at block level so Magento 2 Full page mechanism will get that block in cache automatically ,so My question is if Magento 2 already do full page in cache blocks so why we define block level cache ?

magento2.4 – How to stop redirect on-click wishlist icon

My wishlist code:

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var MagentoWishlistBlockCatalogProductProductListItemAddToWishlist $block */
?>
<?php if ($block->getWishlistHelper()->isAllow()) : ?>


<a href="#"
class="action towishlist"
title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>"
aria-label="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>"
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($block->getProduct()) ?>'
data-action="add-to-wishlist"
role="button">
<img class="whislist-icon product-id-<?php echo $block->getProduct()->getId();?>" src="https://magento.stackexchange.com/<?php /* @escapeNotVerified */ echo $block->getViewFileUrl("images/whislist_icon.jpg'); ?>" />
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
</a>

<?php endif; ?>
<?php
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $_objectManager->get('MagentoStoreModelStoreManagerInterface');
$currentStore = $storeManager->getStore();
$mediaUrl = $currentStore->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$wishimage = $mediaUrl."after_added.jpg";
?>

<script>
require(('jquery'), function($){
jQuery.ajax({
url: '<?php echo $this->getUrl('addtowish/index/wishlist') ?>',
method: 'get',
dataType: 'json',
success: function(data) {
var wislistAddesCheckData = data;
var itemLenth = wislistAddesCheckData.items.length;
for(i=0;i<itemLenth; i++){
var wislistAddedProductId = wislistAddesCheckData.items(i).product_id;
$(".product-id-"+wislistAddedProductId).attr('src','<?php echo $wishimage ; ?>');
}
}
});
});
</script>

Now, if click wishlist icon its redirect to the wishlist landing page, how to stop that?

magento2.4 – Magento2 – Customer dashboard is accessible but checkout request to log in

on Magento 2.4 i’m facing this strange situation: Yesterday i’ve normally logged in to my store, today i came back to the store and i can access my customer dashboard but when i try to reach checkout page magento show me the authentication popup. It seem like i’m half logged in and half not.
It is the checkout session expired? How can i extend it? I would like to access checkout page avoiding a new log in.
Thanks

magento2.4 – Magento with Varnish – var/cache folder still being used

I have a Magento store configured with Varnish. When everything is up to date site is fast. If I change something in the backend it doesn’t get reflected on frontend unless I manually delete var/cache/mage–* folders.

By the looks of the documentation, this folder should be empty after I configured Varnish.

How do I debug this?

There was an error loading payments.Please refresh or try again later. PWA Venia Theme Magento2.4 issue coming on

I have installed PWA Venia Theme with magento2.4.1 EE but on checkout, no payment methods are loading.
Error Getting: There was an error loading payments. Please refresh or try again later.
Attached the image below Is anyone faced the same issue? or anyone has any information regarding this issue?

magento2.4 – Product image files being added more than once (_1, _2, _3, etc.)

So this is odd. I’ve noticed this since 2.3.x (I’m now on 2.4.1) but it is getting annoying and I’m wondering if anyone knows why it does this (and hopefully a fix? Or how to stop it from doing this).

While creating a product and adding an image to the ‘Color – Red’ variation, the same exact image (original filename: Product_Red_Front.jpg) gets duplicated as

  • Product_Red_Front_1.jpg (12.81kb)
  • Product_Red_Front_2.jpg (12.81kb)
  • Product_Red_Front_3.jpg (12.81kb)
  • Product_Red_Front_4.jpg (12.81kb)
  • Product_Red_Front_5.jpg (12.81kb)

My guess it’s for each product ‘size’, because if I have S-XXL sizes that’s 5 sizes = 5 files made. I’m only selecting “Apply unique images by attribute to each SKU” and selecting “Color”.

But that turns a set of ~35kb images on my server into ~200kb. For_no_reason. Just takes up space for no reason. And makes it a headache to manage (say if I want to optimize the files in the future, I would have to optimize 5 files (and rename them as such) for each product side for every…color…)

I’ve added a picture for an example. For 1 color, 3 sides (so it ‘should’ be 3 files only per color) it created 15 files. From 35kb to 200kb. Just makes no sense, hopefully someone will know why it is doing this? Imagine having 4 or 5 sides…ugh. 30+ images for one color…lol

Just to prove this is pointless, I could export the products (as csv), change the image it uses to simply red_front.jpg, red_side.jpg, red_back.jpg for each product and it would work fine. (but obviously I’m not trying to do this, waste time, as it shouldn’t be doing this to begin with – it’s not like it’s resizing the images or anything special, just duplicating them)

I saw this topic: Strange Issue product image filename adding _1 to the filename but the answer didn’t work for me, I didn’t have anything in the ‘tmp’ folder :/

Thank you for your time, it is much appreciated.

enter image description here

magento2.4 – Magento 2 How add Magento ReCaptcha to sales/guest/form?

How i can add reCaptcha to Sales Guest Form like Contact Us and etc?
I want to copy method like magento/module-re-captcha-contact (Magento_ReCaptchaContact) (Google reCAPTCHA integration for Magento2)

My system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <section id="recaptcha_frontend">
        <group id="type_for">
            <field id="guest_form" translate="label" type="select" sortOrder="180" showInDefault="1"
                   showInWebsite="1" showInStore="0" canRestore="1">
                <label>Enable for Sales Guest Form</label>
                <source_model>MagentoReCaptchaAdminUiModelOptionSourceType</source_model>
            </field>
        </group>
    </section>
</system>

My sales_guest_form.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="guest.form">
                <block class="MagentoReCaptchaUiBlockReCaptcha"
                       name="recaptcha"
                       after="-"
                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
                       ifconfig="recaptcha_frontend/type_for/guest_form">
                    <arguments>
                        <argument name="recaptcha_for" xsi:type="string">guest_form</argument>
                        <argument name="jsLayout" xsi:type="array">
                            <item name="components" xsi:type="array">
                                <item name="recaptcha" xsi:type="array">
                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
                                </item>
                            </item>
                        </argument>
                    </arguments>
                </block>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>

My config.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <recaptcha_frontend>
            <type_for>
                <guest_form/>
            </type_for>
        </recaptcha_frontend>
    </default>
</config>

But i can’t found place for observer event Sales Quest Form like:
vendor/magento/module-re-captcha-contact/etc/frontend/events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_contact_index_post">
        <observer name="recaptcha_on_contact_form" instance="MagentoReCaptchaContactObserverContactFormObserver"/>
    </event>
</config>

Can you help me with finding a place where I can also use the observer or share my experience of adding captcha to this form?