Skip to main content

I have solved it With the help of Allah@Hiren. @Hiren give he gives me a lead to use of eva/Model. here

here what i dodid.

CreateCreated file 'Vendor\Module\Block\Options.php;'Vendor\Module\Block\Options.php

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml filephtml file

<?php
$dropdown = $block->getDropdown();
?>
<select id="select_platform">
    <option value="0">Please Select Platform</option>
    <?php
    foreach ($dropdown as $option):
        $value = $option["value"];
        $label = $option["label"];
        echo "<option value='$value'>$label</option>";
    endforeach;
    ?>

I have solved it With the help of Allah. @Hiren give me a lead to use eva/Model. here what i do.

Create file 'Vendor\Module\Block\Options.php;'

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml file

<?php
$dropdown = $block->getDropdown();
?>
<select id="select_platform">
    <option value="0">Please Select Platform</option>
    <?php
    foreach ($dropdown as $option):
        $value = $option["value"];
        $label = $option["label"];
        echo "<option value='$value'>$label</option>";
    endforeach;
    ?>

I have solved it With the help of @Hiren. he gives me a lead to use of eva/Model.

here what i did.

Created file Vendor\Module\Block\Options.php

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

phtml file

<?php
$dropdown = $block->getDropdown();
?>
<select id="select_platform">
    <option value="0">Please Select Platform</option>
    <?php
    foreach ($dropdown as $option):
        $value = $option["value"];
        $label = $option["label"];
        echo "<option value='$value'>$label</option>";
    endforeach;
    ?>
deleted 58 characters in body
Source Link
Ali Raza
  • 203
  • 1
  • 14

I have solved it With the help of Allah. @Hiren give me a lead to use eva/Model. here what i do.

Create file 'Vendor\Module\Block\Options.php;'

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml file

<?php
 
$product$dropdown = $block->getProduct>getDropdown();
?>
if<select ($product->getResource()->getAttribute('platform')->getFrontend()->getValue($product)id="select_platform">
 == 'Magento 2'){ <option value="0">Please Select Platform</option>
    <?>php
    <divforeach class="dropdown_product_logo_magento_2"></div>($dropdown as $option):
    <div class="versions">Magento 2 is Selected</div>$value = $option["value"];
<?php } else { ?>
    <div$label class="dropdown_product_logo_magento_1"></div>= $option["label"];
    <div class="versions">Magento 1 is Selected<echo "<option value='$value'>$label</div>option>";
<?php }   endforeach;
    ?>
  

I have solved it With the help of Allah. @Hiren give me a lead to use eva/Model. here what i do.

Create file 'Vendor\Module\Block\Options.php;'

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml file

<?php
 
$product = $block->getProduct();

if ($product->getResource()->getAttribute('platform')->getFrontend()->getValue($product) == 'Magento 2'){ ?>
    <div class="dropdown_product_logo_magento_2"></div>
    <div class="versions">Magento 2 is Selected</div>
<?php } else { ?>
    <div class="dropdown_product_logo_magento_1"></div>
    <div class="versions">Magento 1 is Selected</div>
<?php }?>
 

I have solved it With the help of Allah. @Hiren give me a lead to use eva/Model. here what i do.

Create file 'Vendor\Module\Block\Options.php;'

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml file

<?php
$dropdown = $block->getDropdown();
?>
<select id="select_platform">
    <option value="0">Please Select Platform</option>
    <?php
    foreach ($dropdown as $option):
        $value = $option["value"];
        $label = $option["label"];
        echo "<option value='$value'>$label</option>";
    endforeach;
    ?>
 
Source Link
Ali Raza
  • 203
  • 1
  • 14

I have solved it With the help of Allah. @Hiren give me a lead to use eva/Model. here what i do.

Create file 'Vendor\Module\Block\Options.php;'

<?php
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Options extends \Magento\Contact\Block\ContactForm
{

    protected $eavAttributeFactory;
    protected $attributeOptionManagement;

    public function __construct(
        \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory,
        \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement,
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
        $this->eavAttributeFactory = $eavAttributeFactory;
        $this->attributeOptionManagement = $attributeOptionManagement;
    }
    public function getDropdown(){
        $magentoAttributeOptions = $this->attributeOptionManagement->getItems(
            'catalog_product','platform');
        return $magentoAttributeOptions;
    }
}

and in phtml file

<?php

$product = $block->getProduct();

if ($product->getResource()->getAttribute('platform')->getFrontend()->getValue($product) == 'Magento 2'){ ?>
    <div class="dropdown_product_logo_magento_2"></div>
    <div class="versions">Magento 2 is Selected</div>
<?php } else { ?>
    <div class="dropdown_product_logo_magento_1"></div>
    <div class="versions">Magento 1 is Selected</div>
<?php }?>