0

Newbie question. How do I extend the appearance of an extension?

I would like this extension/view:

enter image description here

to add in here:

enter image description here

Here are my default Catalog_category_view.xml

        <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                <container name="category.product.list.additional" as="additional" />
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="category.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
            </block>
            
        </block>
        <block class="Magento\Cookie\Block\RequireCookie" name="require-cookie" template="Magento_Cookie::require_cookie.phtml">
            <arguments>
                <argument name="triggers" xsi:type="array">
                    <item name="compareProductLink" xsi:type="string">.action.tocompare</item>
                </argument>
            </arguments>
        </block>
    </referenceContainer>

and here's the also the default extension's xml:

        <referenceContainer name="product.info.form.content">
        <block class="Amasty\RecurringPayments\Block\Product\View\RecurringPayments"
               name="product.info.recurring.payments"
               before="product.info.addtocart"
               template="Amasty_RecurringPayments::product/view/subscriptions.phtml"/>
    </referenceContainer>

the list.phtml is where I'd like to extend the extension's appearance/view

here's what I've added but couldn't work (below the line with the exclamation points!):

        <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                <container name="category.product.list.additional" as="additional" />
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="category.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
                <!!!!!!!!what I've added!!!!!!!!!!!!!!>
                <block class="Amasty\RecurringPayments\Block\Product\View\RecurringPayments"
                name="product.info.recurring.payments"
                before="product.info.addtocart"
                template="Magento_Catalog::product/list.phtml"/>
            </block>
            
        </block>
        <block class="Magento\Cookie\Block\RequireCookie" name="require-cookie" template="Magento_Cookie::require_cookie.phtml">
            <arguments>
                <argument name="triggers" xsi:type="array">
                    <item name="compareProductLink" xsi:type="string">.action.tocompare</item>
                </argument>
            </arguments>
        </block>
    </referenceContainer>

and here's my list.phtml code and the inserted code that I get from the extension's phtml file:

enter link description here

0

1 Answer 1

0

The change you are asking is from a block in the product view page , for more info i need you get the block name from the layout path and you can use that block name in the layout file = catalog_category_view.xml file in your custom module or theme and place the block in that to show this content.

For example , please see the below code i have used to print a "Block you want" content in the category view page using the layout handle file = catalog_category_view.xml file and have over-ride a block called "category.product.addto.wishlist" and in that block's template have appended my content also ,i know there are many approaches but by far this is the best i have arrived to and it requires minimum level of coding and over-riding the file also, below is the code

If this code snippet helps you please do give me a like , this helps me motivate to post more answers , have a nice day.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="category.product.addto.wishlist"
                   template="OX_PrintSampleContent::wishlist.phtml"/>
        </referenceContainer>
    </body>
</page>

Below is the phtml file

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

/** @var Magento\Wishlist\Block\Catalog\Product\ProductList\Item\AddTo\Wishlist $block */
?>
<h1>Block you want here</h1>
<?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">
        <span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
    </a>
<?php endif; ?>

Below is the screenshot

enter image description here

3
  • Hi @harathKumarJ Thanks for this. I know that you answered my question, but the connection between my module catalog and the extension's xml, php, and phtml files is giving me trouble. Is there a way I can contact you? I looked at your LinkedIn page; perhaps we can talk there. Thank you. Commented Sep 15, 2022 at 19:29
  • Hi Yes, please ask your queries here, I'll help out as much as possible.Thank you Commented Sep 16, 2022 at 4:36
  • Hi @bharath Kumar J- Please check my updated post, about this. Thank you. Commented Sep 16, 2022 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.