2

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,

1

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()
        {
...
        }

    }
  • thank for your answer. when I remove the line I have another error : Class 'A\Cust\Block\Adminhtml\Product\Edit\Tab\Options\Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option' not found in /var/www/html/magento2/app/code/A/Cust/Block/Adminhtml/Product/Edit/Tab/Options/Option.php on line 5 – Alexglvr Nov 10 '16 at 11:03
  • @Alexglvr update the code their was \ missing in start – Fme Extensions Nov 10 '16 at 11:05
  • Thanks, it compiles now... My custom product option page does not display defined options any more now... and don't work...I have to search why now (next step). Going from magento 1 to magento 2 is not so easy... Thanks Again – Alexglvr Nov 10 '16 at 11:15
  • @Alexglvr if you find this answer helpful kindly accept it. you are missing the point here don't stick with magento1 $this->setTemplate('Magento_Catalog::product/edit/options/option.phtml'); just add ` protected $_template = 'Namespace_Modulename::product/edit/options/option.phtml; in your class – Fme Extensions Nov 10 '16 at 11:21
  • I still have no options displayed in backend product Custom options as soon as I add the <preference for="Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option" type="A\Cust\Block\Adminhtml\Product\Edit\Tab\Options\Option" /> in di.xml... As soon as I remove this line, my product options appear...I also wanted to define my phtmls in a layout .xml file somewhere, but while searching in the core layout xml files, I did not find the original declaration of adminhtml Options/Option.phtml and Options/Type/xxx.phtml in any layout files... – Alexglvr Nov 11 '16 at 10:23

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.