0

I am creating a module with namespace 'Camping' to customize wishlist. I have copied 'wishlist_index_index.xml' to my module and changed as per need. but its not yet working. When I change the namespace to any other name, my custom wishlist start working.

my module structure is Camping/Wishlist/

Can any one tell why its not working with namespace 'Camping' ????

this is my wishlist_index_index.xml file located in Camping/Wishlist/view/frontend/layout

<?xml version="1.0"?>

<update handle="customer_account"/>
<body>
    <referenceBlock name="head.components">
        <block class="Magento\Framework\View\Element\Js\Components" name="wishlist_head_components" template="Magento_Wishlist::js/components.phtml"/>
    </referenceBlock>
    <referenceContainer name="content">
        <block class="Magento\Wishlist\Block\Customer\Wishlist" name="customer.wishlist" template="view.phtml" cacheable="false">
            <block class="Magento\Wishlist\Block\Rss\Link" name="wishlist.rss.link" template="rss/wishlist.phtml"/>
            <block class="Magento\Wishlist\Block\Customer\Wishlist\Items" name="customer.wishlist.items" as="items" template="item/list.phtml" cacheable="false">
                <block class="Camping\Wishlist\Block\Customer\Wishlist\Item\Column\Image" name="customer.wishlist.item.image" template="item/column/image.phtml" cacheable="false"/>
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info" name="customer.wishlist.item.name" template="item/column/name.phtml" cacheable="false"/>
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart" name="customer.wishlist.item.price" template="item/column/price.phtml" cacheable="false">
                    <block class="Magento\Catalog\Pricing\Render" name="product.price.render.wishlist">
                        <arguments>
                            <argument name="price_render" xsi:type="string">product.price.render.default</argument>
                            <argument name="price_type_code" xsi:type="string">configured_price</argument>
                            <argument name="price_label" xsi:type="boolean">false</argument>
                            <argument name="zone" xsi:type="string">item_list</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Options" name="customer.wishlist.item.options" cacheable="false"/>
                </block>
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Actions" name="customer.wishlist.item.inner" template="item/column/actions.phtml" cacheable="false">
                    <arguments>
                        <argument name="css_class" xsi:type="string">product-item-inner</argument>
                    </arguments>
                    <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Comment" name="customer.wishlist.item.comment" template="item/column/comment.phtml" cacheable="false">
                        <arguments>
                            <argument name="title" translate="true" xsi:type="string">Product Details and Comment</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart" name="customer.wishlist.item.cart" template="item/column/cart.phtml" cacheable="false">
                        <arguments>
                            <argument name="title" translate="true" xsi:type="string">Add to Cart</argument>
                        </arguments>
                    </block>

                    <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Actions" name="customer.wishlist.item.actions" template="item/column/actions.phtml" cacheable="false">
                        <arguments>
                            <argument name="css_class" xsi:type="string">product-item-actions</argument>
                        </arguments>
                        <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Edit" name="customer.wishlist.item.edit" template="item/column/edit.phtml" before="-" cacheable="false"/>
                        <block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Remove" name="customer.wishlist.item.remove" template="item/column/remove.phtml" cacheable="false"/>
                    </block>
                </block>
            </block>
            <container name="customer.wishlist.buttons" as="control_buttons" label="Wishlist Control Buttons">
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Button" name="customer.wishlist.button.update" template="button/update.phtml" cacheable="false"/>
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Button" name="customer.wishlist.button.share" template="button/share.phtml" cacheable="false"/>
                <block class="Magento\Wishlist\Block\Customer\Wishlist\Button" name="customer.wishlist.button.toCart" template="button/tocart.phtml" cacheable="false"/>
            </container>
        </block>
    </referenceContainer>
</body>

I have created my own block named Image.php and image.phtml also with custom code.

  • Module works after changed namespace or both namespace and module name ? – Suresh Chikani Apr 20 '16 at 6:53
  • if I use Camping as namespace, its not working i have not changed my module name – Abhimanyu Singh Apr 20 '16 at 6:55
  • plz show your full xml file – Rakesh Jesadiya Apr 20 '16 at 7:06
  • I have just copy and paste the xml file and was trying to change as per the requirement. but its not working. The issue is I have to use this namespace only 'Camping'. I have defined in composer.json , registration.php and module.xml also. – Abhimanyu Singh Apr 20 '16 at 7:14
0

In your case you have to just override block file. You have to do it using override wishlist block with your custom block. So you doesn't need to do override wishlist_index_index.xml file.

Remove wishlist_index_index.xml file from layout.

Just do below to works:

add di.xml file inside etc folder.

etc/di.xml file code,

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image" type="Camping\Wishlist\Block\Customer\Wishlist\Item\Column\Image" />
</config>

Block file path (add Image.php inside below folder),

Camping\Wishlist\Block\Customer\Wishlist\Item\Column 

now code for block file,

<?php    
namespace Camping\Wishlist\Block\Customer\Wishlist\Item\Column;

class Image extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image
{
    protected $_template = 'item/column/image.phtml';

    protected function _toHtml()
    {
        //echo 'tests';exit;
        if ($this->isEnabled()) {
            if (!$this->getLayout()) {
                return '';
            }
            foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $child) {
                if ($child) {
                    $child->setItem($this->getItem());
                }
            }
            return parent::_toHtml();
        }
        return '';
    }
}

You can override image.phtml file inside app/code/Camping/Wishlist/view/frontend/templates/item/column/image.phtml

view file,

<?php
/* @var \Magento\Wishlist\Model\Item $item */
$item = $block->getItem();
$product = $item->getProduct();
?>
This is override file called.
<a class="product-item-photo" href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($item) ?>" title="<?php echo $block->escapeHtml($product->getName()) ?>">
    <?php echo $block->getImage($product, 'wishlist_thumbnail')->toHtml(); ?>
</a>

please let me know if any issue occurs,

Thanks.

  • I have tried this also but its not working. – Abhimanyu Singh Apr 20 '16 at 18:39
  • <block class="Camping\Wishlist\Block\Customer\Wishlist\Item\Column\Image" name="camping.wishlist.item.image" template="Camping_Wishist::item/column/image.phtml" cacheable="false"/> – Abhimanyu Singh Apr 20 '16 at 18:39
  • Any help please....... – Abhimanyu Singh Apr 21 '16 at 7:15
  • i need to change design and functionality of wishlist page. like changing the css and other with extra functionality. i have overrided wishlist,item,image,price and other blocks, just by placing my block and template in layout xml filie. I have done all changes but with other namespace as 'Test'. but my client need only ''Camping" as namespace as many other modules are built inside that namespace. which i am not able to complete. – Abhimanyu Singh Apr 21 '16 at 7:34
  • plz check for updated answer. – Rakesh Jesadiya Apr 21 '16 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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