Question

I have an error on bin/magento setup:di:compile on my module:

MiBPHP Fatal error: Cannot declare class A\Cust\Block\Adminhtml\Product\Edit\Tab\Options\Option because the name is already in use in /var/www/html/magento2/app/code/A/Cust/Block/Adminhtml/Product/Edit/Tab/Options/Option.php on line 7

My Files :

etc/module.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="A_Cust" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

etc/di.xml

<?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\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option" type="A\Cust\Block\Adminhtml\Product\Edit\Tab\Options\Option" />
</config>

A\Cust\Block\Adminhtml\Product\Edit\Tab\Options\Option.php

    <?php
    namespace A\Cust\Block\Adminhtml\Product\Edit\Tab\Options;

    use Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option;

    class Option extends Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option
    {
        /**
         * Class constructor
         */
        public function _construct()
        {
            parent::_construct();
            $this->setTemplate('Magento_Catalog::product/edit/options/option.phtml');
        }

        public function getTemplatesHtml()
        {
          ... 
        } 

        public function getOptionValues()
        {
          ...
        }

    }

Thank you for your help,

Was it helpful?

Solution

remove this line use Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option;

<?php
    namespace A\Cust\Block\Adminhtml\Product\Edit\Tab\Options;



    class Option extends \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option
    {
        /**
         * Class constructor
         */
        public function _construct()
        {
            parent::_construct();
            $this->setTemplate('Magento_Catalog::product/edit/options/option.phtml');
        }

        public function getTemplatesHtml()
        {
... 
        } 

        public function getOptionValues()
        {
...
        }

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top