cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble changing popup modal form options

Having trouble changing popup modal form options

I am struggling to find a way to change the values of a quote form on a modal popup when the customer clicks on the request a quote button. Here is the form.

popuppopuppopup with hints enabledpopup with hints enabled

I went into options.phtml and the code is as follows.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/* @var $block \Magento\Catalog\Block\Product\View\Options */
?>

<?php $_options = $block->decorateArray($block->getOptions()) ?>
<?php $_product = $block->getProduct(); ?>
<?php $_productId = $block->getProduct()->getId() ?>
<?php if (count($_options)):?>
    <script type="text/x-magento-init">
        {
            "#product_addtocart_form": {
                "priceOptions": {
                    "optionConfig": <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>,
                    "controlContainer": ".field",
                    "priceHolderSelector": "[data-product-id='<?= $block->escapeHtml($_productId) ?>'][data-role=priceBox]"
                }
            }
        }
    </script>
    <?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->get($block->getProduct()->getAttributeSetId());
    $attribute_set_name = $attributeSetRepository->getAttributeSetName();
    ?>

    <?php if(($attribute_set_name === "GC Form"or $attribute_set_name === "MS Form" or $attribute_set_name === "HPLC Form") and $attribute_set_name !== "default"): ?>
        <div id="product_modal" class="modal">
            <!-- Modal content -->
            <div class="product_modal-content">
                <span class="close">&times;</span>
                <h3>Quote Request for: <br/><?=  $_product->getName(); ?></h3>
                <p style="color:#c14e4e">Please complete the form below to request more information and pricing.</p>
                <div class="product-add-form">
                    <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $_product->getId() ?>" />
                    <input type="hidden" name="selected_configurable_option" value="" />
                    <input type="hidden" name="item"  value="<?= /* @noEscape */ $block->getRequest()->getParam('id') ?>" />
                    <?= $block->getBlockHtml('formkey') ?>
                    <?= $block->getChildHtml('form_top') ?>
                    <div class="option-in-box" id="option-in-box">
                        <div class="RequestQuote-left">
                            <?php foreach ($_options as $key =>$_option): ?>
                                <?php if(($_option['title'] === "Preferred Manufacturer") or
                                    $_option['title'] === "How Many Samples per Month"):?>
                                    <?= $block->createTextFiled($_option) ?>
                                <?php elseif($_option['title'] === "Budgets"):?>
                                    <?=  $block->createSelect($_option); ?>
                                <?php elseif ($_option['title'] === "Trade-In(s)"):?>
                                    <?= $block->createSubDetailSelect($_option,$_options, array("Describe Your Trade-In information"=>"Yes")); ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </div>
                        <div class="RequestQuote-right">
                            <?php foreach ($_options as $key =>$_option): ?>
                                <?php if($_option->getTitle() == 'Voltage'): ?>
                                    <?=  $block->createDropdown($_option); ?>
                                <?php elseif($_option['title'] === "Choose Your Application"):?>
                                    <?= $block->createSubDetailDropdown($_option, $_options, array("Describe your Application"=>"Other")); ?>
                                <?php elseif($_option['title'] === "Delivery Expected"):?>
                                    <?=  $block->createSelect($_option); ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </div>
                        <?php if($attribute_set_name === "GC Form" or $attribute_set_name === "HPLC Form" or $attribute_set_name === "MS Form"): ?>
                            <div class="modal-more-options" id="modal-more-options" style="display: none;">
                                <?php if($attribute_set_name === "GC Form"): ?>
                                    <div class="RequestQuote-left">
                                        <?php foreach ($_options as $key => $_option):?>
                                            <?php if($_option->getTitle() == "Sampling" or $_option->getTitle() == "Injectors"): ?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif ($_option->getTitle() == "Options"):?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("Please Indicate"=>"Other")); ?>
                                            <?php endif;?>
                                        <?php endforeach;?>
                                    </div>
                                    <div class="RequestQuote-right">
                                        <?php foreach ($_options as $key => $_option):?>
                                            <?php if($_option->getTitle() == "Detectors"): ?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("MSD Options"=>"MSD - Mass Spec Detector","Pump Options"=>"MSD - Mass Spec Detector","Mass Range"=>"MSD - Mass Spec Detector")); ?>
                                            <?php elseif ($_option->getTitle() == "Communications"):?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif ($_option->getTitle() == "Accessories"):?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif ($_option->getTitle() == "Data System Required?"):?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("What Version of Software?"=>"No","What Data System"=>"Yes","Operating System"=>"Yes")); ?>
                                            <?php endif; ?>
                                        <?php endforeach;?>
                                    </div>
                                <?php elseif ($attribute_set_name === "MS Form"):?>
                                    <div class="RequestQuote-left">
                                        <?php foreach ($_options as $key => $_option):?>
                                            <?php if($_option->getTitle() == "Instrument" or $_option->getTitle() == "Accessories"): ?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php endif; ?>
                                        <?php endforeach;?>
                                    </div>
                                    <div class="RequestQuote-right">
                                        <?php foreach ($_options as $_option):?>
                                            <?php if($_option->getTitle() === "Sample Introduction" ):?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("Other Source"=>"Other Source","Specify Model"=>"Existing LC")); ?>
                                            <?php elseif ($_option->getTitle() == "Qualification and Quantification"):?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif ($_option->getTitle() === "Mass Range" ): ?>
                                                <?= $block->createTextFiled($_option) ?>
                                            <?php endif; ?>
                                        <?php endforeach;?>
                                    </div>
                                <?php elseif ($attribute_set_name === "HPLC Form"):?>
                                    <div class="RequestQuote-left">
                                        <?php foreach ($_options as $_option):?>
                                            <?php if($_option->getTitle() === "Stand-Alone System or Front-End" ):?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("Please Indicate Existing MS Model"=>"Front-End")); ?>
                                            <?php elseif ($_option->getTitle() === "Pumps" ): ?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif ($_option->getTitle() === "Autosampler Needed" ): ?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("Options"=>"Yes")); ?>
                                            <?php elseif ($_option->getTitle() === "Data System" ): ?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("What Version of Software?"=>"No","What Data System"=>"Yes","Operating System"=>"Yes")); ?>
                                            <?php endif;?>
                                        <?php endforeach;?>
                                    </div>
                                    <div class="RequestQuote-right">
                                        <?php foreach ($_options as $_option):?>
                                            <?php if ($_option->getTitle() == "Accessories"):?>
                                                <?=  $block->createSelect($_option); ?>
                                            <?php elseif($_option->getTitle() === "Detectors" ):?>
                                                <?= $block->createSubDetailSelect($_option, $_options, array("Qualification and Quantification"=>"MS - Mass Spec","Instrument"=>"MS - Mass Spec","Do you need Exact Mass Capabilities"=>"MS - Mass Spec","Mass Range"=>"MS - Mass Spec")); ?>
                                            <?php endif;?>
                                        <?php endforeach;?>
                                    </div>
                                <?php endif;?>
                            </div>
                        <?php endif;?>
                    </div>
                    <div class="request-quote-button-centered">
                        <?php if($attribute_set_name === "GC Form" or $attribute_set_name === "HPLC Form" or $attribute_set_name === "MS Form"): ?>
                        <button type="button" title="Add to Quote" class="action toquote show-mote-options-btn" id="show-more-options-btn">
                            <span>Show More</span>
                        </button>
                        <?php endif;?>
                        <button type="submit" title="Add to Quote" class="action toquote product-addtoquote-btn" id="product-addtoquote-button">
                            <span>Add to Quote</span>
                        </button>

                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            require(['jquery','mage/mage'],function($){
                $('#show-more-options-btn').on('click', function(){
                    console.log('test');
                    if($('#modal-more-options').css('display') === 'none'){
                        $('#modal-more-options').css('display','block');
                        $('#show-more-options-btn').text('Show Less');
                    }
                    else {
                        $('#modal-more-options').css('display','none');
                        $('#show-more-options-btn').text('Show More');
                    }
                });
            });
            function showOther(id, element,changeValue) {
                if(element.value === changeValue){
                    document.getElementById(id).style.display = 'block';
                }
                else {
                    document.getElementById(id).style.display = 'none';
                }
            }
            function radioCheck(ele){
                var parentEle = document.getElementsByName(ele);
                for(var i =0; i< parentEle.length; i++){
                    var childDivs = parentEle[i].parentElement.getElementsByClassName('sub-item-left');
                    if(parentEle[i].checked ){
                        if(childDivs){
                            for(var k = 0; k< childDivs.length; k++){
                                childDivs[k].style.display = 'block';
                            }
                        }
                    }
                    else {
                        if(childDivs){
                            for(var k = 0; k< childDivs.length; k++){
                                childDivs[k].style.display = 'none';
                            }
                        }
                    }
                }
            }
            var quote_modal = document.getElementById("product_modal");
            var quote_btn = document.getElementById("quote_btn");
            var quote_span = document.getElementsByClassName("close")[0];

            quote_btn.onclick = function() {
                quote_modal.style.display = "block";
            }
            quote_span.onclick = function() {
                quote_modal.style.display = "none";
            }
            window.onclick = function(event) {
                if (event.target === quote_modal) {
                    quote_modal.style.display = "none";
                }
            }
        </script>

    <?php else:?>
        <?php foreach ($_options as $_option): ?>
            <?= $block->getOptionHtml($_option) ?>
        <?php endforeach; ?>
    <?php endif;?>

<?php endif;?>

I was told that the values are modified in another file Productoptions.php which after modifying no changes take place to the modal popup.I am trying to change the budget currently.

1 REPLY 1

Re: Having trouble changing popup modal form options

Here is the Productoptions.php that i couldn't insert due to message size. I had to truncate the end of the file as it is too long.

<?php
namespace GTS\CustomOptions\Observer;
use Magento\Framework\Event\ObserverInterface;

class Productoptions implements ObserverInterface
{
    protected $productRepository;
    public function __construct(
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
    ) {
        $this->productRepository = $productRepository;
    }
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getProduct();
        $attributeSet = $product->getAttributeSetId();
        $_productQuotable = $product->getResource()->getAttribute('cart2quote_quotable')->getFrontend()->getValue($product);

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $sku = $product->getSku();
        $productId = $product->getId();
        $storeId = $product->getStoreId();
        $product = $this->productRepository->get($sku);

        if (!$product->getHasOptions() and $_productQuotable == 'Yes') {
            $options = [];
            switch ($attributeSet){
                case '11':
                    $options = array_merge($this->get_QuoteAble_data(),$this->get_GC_data());
                    break;
                case '12':
                    $options = array_merge($this->get_QuoteAble_data(),$this->get_MS_data());
                    break;
                case '13':
                    $options = array_merge($this->get_QuoteAble_data(),$this->get_HPLC_data());
                    break;
//                case '14':
//                    $options = $this->get_QuoteAble_data();
//                    break;
            }
            if(!empty($options)){
                foreach ($options as $arrayOptions) {
                    $product->setHasOptions(1);
                    $optionObj = $objectManager->create('\Magento\Catalog\Model\Product\Option');
                    $customOption = $optionObj
                        ->setProductId($productId)
                        ->setStoreId($storeId)
                        ->addData($arrayOptions);
                    $customOption->save();
                    $product->addOption($customOption);
                    $this->productRepository->save($product);
                }
            }
        }
    }

    private function get_QuoteAble_data(){
        $basic = [
            '0' => [
                'title' => 'Preferred Manufacturer',
                'type' => 'field',
                'is_require' => 0,
                'sort_order' => 0,
                'price' => '0.00',
                'price_type' => 'fixed',
                'max_characters' => '0',
                'sku' => ''
            ],
            '1' => [
                'title' => 'How Many Samples per Month',
                'type' => 'field',
                'is_require' => 0,
                'sort_order' => 1,
                'price' => '0.00',
                'price_type' => 'fixed',
                'max_characters' => '0',
                'sku' => ''
            ],
            '2' => [
                'title' => "Voltage",
                'type' => 'drop_down',
                'is_require' => 0,
                'sort_order' => 2,
                'values' => [
                    '1' => [
                        'title' => '110',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 1,
                    ],
                    '2' => [
                        'title' => '220',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 2,
                    ],
                    '3' => [
                        'title' => 'Unknown',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 3,
                    ],
                ]
            ],
            '3' => [
                'title' => "Choose Your Application",
                'type' => 'drop_down',
                'is_require' => 0,
                'sort_order' => 3,
                'values' => [
                    '1' => [
                        'title' => 'Biological',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 1,
                    ],
                    '2' => [
                        'title' => 'Cannabis',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 2,
                    ],
                    '3' => [
                        'title' => 'Clinical',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 3,
                    ],
                    '4' => [
                        'title' => 'Pharmaceutical',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 4,
                    ],
                    '5' => [
                        'title' => 'Environmental',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 5,
                    ],
                    '6' => [
                        'title' => 'Forensic',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 6,
                    ],
                    '7' => [
                        'title' => 'Materials',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 7,
                    ],
                    '8' => [
                        'title' => 'Other',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 8,
                    ],
                ]
            ],
            '4' => [
                'title' => 'Describe your Application',
                'type' => 'field',
                'is_require' => 0,
                'sort_order' => 4,
                'price' => '0.00',
                'price_type' => 'fixed',
                'max_characters' => '0',
                'sku' => ''
            ],
            '5' => [
                'title' => 'Budgets',
                'type' => 'radio',
                'is_require' => 1,
                'sort_order' => 5,
                'values' => [
                    '1' => [
                        'title' => '$2,000 - $5,000',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 1,
                    ],
                    '2' => [
                        'title' => '$5,000 - $15,000',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 2,
                    ],
                    '3' => [
                        'title' => '$15,000 - $20,000',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 3,
                    ],
                    '4' => [
                        'title' => '$20,000 - $35,000',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 4,
                    ],
                    '5' => [
                        'title' => '$35,000+',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 5,
                    ],
                ]
            ],
            '6' => [
                'title' => 'Trade-In(s)',
                'type' => 'radio',
                'is_require' => 0,
                'sort_order' => 6,
                'values' => [
                    '1' => [
                        'title' => 'No',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 1,
                    ],
                    '2' => [
                        'title' => 'Yes',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 2,
                    ],
                ]
            ],
            '7' => [
                'title' => 'Describe Your Trade-In information',
                'type' => 'field',
                'is_require' => 0,
                'sort_order' => 7,
                'price' => '0.00',
                'price_type' => 'fixed',
                'max_characters' => '0',
                'sku' => ''
            ],
            '8' => [
                'title' => 'Delivery Expected',
                'type' => 'radio',
                'is_require' => 1,
                'sort_order' => 8,
                'values' => [
                    '1' => [
                        'title' => 'Immediately',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 1,
                    ],
                    '2' => [
                        'title' => '1 - 2 Months',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 2,
                    ],
                    '3' => [
                        'title' => '3 - 6 Months',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 3,
                    ],
                    '4' => [
                        'title' => '6 - 12 Months',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 4,
                    ],
                    '5' => [
                        'title' => 'Budgetary Quote',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 5,
                    ],
                    '6' => [
                        'title' => 'Rental',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 6,
                    ],
                    '7' => [
                        'title' => 'Info Only',
                        'price' => 0,
                        'price_type' => 'fixed',
                        'sku' => '',
                        'sort_order' => 7,
                    ],
                ]
            ],

        ];
        return $basic;
    }