0

I'm using a plugin Gift Registry I want to add the Gift Registry button in my product list view. Right now the plugin only shows in the Product View Page. But we want to show it in the Product List View. But I keep getting an error of

enter image description here

I added this in the Magento_Catalog/layout/default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magenest\GiftRegistry\Block\Product\View" name="product.info.additem" as="additem" template="Magenest_GiftRegistry::item/configure/addto.phtml" after="-"/>
        </referenceContainer>
    </body>
</page>

It seems that it's throwing an error because the plugin is expecting an ID for the product page but since this is a product list so its not really targeting the exact product but a list. How can I fix this?

Update:

I tried to add this in the Magento_Catalog/layut/catalog_category_view.xml and added this code

enter image description here

As you can see the highlighted below is pointing to a block in Magenest\GiftRegistry\Block\Product\View but when running the site it's giving me this error

enter image description here

As seen here. It's pointing to the magento-catalog/Block/Product/View instead in Magenest\GiftRegistry\Block\Product\View. How do I let the layout loads the correct block?

4
  • step 1. You should extend from layout "vendor/magento/module-catalog/view/frontend/layout/catalog_category_view.xml" step 2. Then, referenceBlock has identifier : as="product_list" and add your block in here. Suppose: <referenceBlock name="product_list" ifconfig="example/gift_registry/enabled"> <block class="ClassA" name="gift__button-add" template="Example_Gift::list/button-add.phtml"/> </referenceBlock> step 3. note: ClassA need to extends class "\Magento\Catalog\Block\Product\ProductList\Item\Block" Commented Mar 5, 2020 at 14:04
  • @@ quite confusing, ... You should read layout "catalog_category_view.xml" to know more. :(( Hope, it will help you. Commented Mar 5, 2020 at 14:07
  • @NguyễnHoàngTuấn yeah a little confusing. If you can provide any tutorial that would be much appreciated Commented Mar 5, 2020 at 14:31
  • ok. pls wait me Commented Mar 6, 2020 at 6:37

1 Answer 1

0

You can chose this way:
step 1: Override layout & add new block in layout enter image description here

step 2: Create class ButtonRegistry enter image description here

note: This class need to extends Magento\Catalog\Block\Product\ProductList\Item\Block because, it contain 2methods setProduct() & getProduct(). They will help you get data at template. You can extends AbstractProduct but not recommended.
step 3: Override template of class "Magento\Catalog\Block\Product\ListProduct" enter image description here In list.phtml, add code to render template "add-button-registry" enter image description here
And here is regítry.phtml template enter image description here



Finally, this's our result enter image description here

1

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.