0

magento 1.9

I want to do a function (maybe it is possible with js, but I'm not good at it yet) that after a customer selects an entry - IN THE FIRST MOMENT - in the select field "UNIDADE" all the products in the cart and the products added afterwards will have the same entry selected by default, the customer will be able to change the selection individually, of course, later if he/she decides to have procedures in different locations but, by default, when he/she selects an entry at first moment all the products will have the same value selected.

In the example below I want that after the SP - TUCURUVI from the first product is selected the same value is selected in the product below it.

enter image description here

My select field is as follows:

 /** @var Mage_Sales_Model_Quote_Item $item */
                $item = $cart->getItemById($_item->getId());

                $options = $_item->getProduct()->getOptions();
                sort($options);

                $optionId = null;
                if (count($options) > 0) {
                    $optionId = $options[0]['option_id'];
                }

                $selectedOption = reset($_item->getOptions());
                $hasSelectedOption = $selectedOption !== false;
                if ($hasSelectedOption) {
                    $selectedOption = unserialize($selectedOption['value']);
                    $selectedOption = reset($selectedOption['options']);
                } else {
                    $selectedOption = '';
                }
            ?>
            <select name="place" location-select data-item-id="<?php echo $_item->getId(); ?>" data-product-id="<?php echo $_item->getProductId(); ?>" data-option-id="<?php echo $optionId; ?>">
                <?php if ($placeList):?>
                    <?php if (is_string($placeList)): ?>
                        <option value="1"><?php echo $placeList ?></option>
                    <?php else: ?>
                        <option value="">Selecione...</option>
                        <?php foreach ($placeList as $key => $place) : ?>
                            <?php $_formatedOptionValue = $this->getFormatedOptionValue($place) ?>

                            <?php if ($_formatedOptionValue['value'] === $selectedOption): ?>
                                <option selected="selected" value="<?php echo $key; ?>">
                                    <?php echo $_formatedOptionValue['value'] ?>
                                </option>
                            <?php else: ?>
                                <option value="<?php echo $key; ?>">
                                    <?php echo $_formatedOptionValue['value'] ?>
                                </option>
                            <?php endif; ?>

                        <?php endforeach; ?>
                    <?php endif; ?>

                <?php else:?>
                    <option value="1">Unidade Padrão</option>
                <?php endif;?>
            </select>
            <i class="fas fa-caret-down"></i>
        </div>

Thanks in advance for the help.

Your Answer

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

Browse other questions tagged or ask your own question.