R
R
retrojdev2016-01-08 13:58:21
opencart
retrojdev, 2016-01-08 13:58:21

How to display the first option price on the main OpenCart?

The main price of the product I have is options, and the main price of the OS is equal to 0. How can I correctly derive the cost of the product from the option?
This is responsible for the price on the main page:

<?php if ($product['price']) { ?>
        <div class="price">
          <?php if (!$product['special']) {  ?>
            <span class="price-new"><?php echo $product['price']; ?></span>
            <?php if( preg_match( '#(\d+).?(\d+)#',  $product['price'], $p ) ) { ?> 
            <?php } ?>
          <?php } else { ?>
            <span class="price-new"><?php echo $product['special']; ?></span><br>
            <span class="price-old"><?php echo $product['price']; ?></span> 
            <?php if( preg_match( '#(\d+).?(\d+)#',  $product['special'], $p ) ) { ?> 
            <?php } ?>

          <?php } ?>
        </div>
        <?php } ?>

And this is how I have it inside the product:
<div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
                            <label class="control-label" for="input-option<?php echo $option['product_option_id']; ?>"><?php echo $option['name']; ?></label>
                            <select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control">
                                <?php foreach ($option['product_option_value'] as $option_value) { ?>
                                    <option value="<?php echo $option_value['product_option_value_id']; ?>"  points="<?php echo (isset($option_value['points_value']) ? $option_value['points_value'] : 0); ?>" price_prefix="<?php echo $option_value['price_prefix']; ?>" price="<?php echo $option_value['price_value']; ?>"><?php echo $option_value['name']; ?>
                                        <?php if ($option_value['price']) { ?>
                                          <?php
                                          if ($option_value['price_prefix'] == '*') {
                                            if ($option_value['price_value'] != 1.0) 
                                              printf("(%+d%%)", round(($option_value['price_value'] * 100) - 100) );
                                          } else {
                                            echo "(".$option_value['price'].")"; 
                                          }
                                          ?>
                                        <?php } ?>
                                    </option>
                                <?php } ?>
                            <option value=""><?php echo $text_select; ?></option>
                            </select>
                        </div>
                    <?php } ?>

How to correctly display the main price of an option on the main page? I do it with the help of:
<?php echo $option_value['price']; ?>
It turns out just emptiness, without a price ...)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-01-08
@Sanasol

$option['product_option_value'][0]['price']

D
Dmitry Evgrafovich, 2016-01-10
@Tantacula

You will output via print_r or var_dump the entire contents of the $option['product_option_value'] variable and see where the first price is. It is difficult to navigate through such a code - you have already lost the habit of a mixture of php and html.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question