Answer the question
In order to leave comments, you need to log in
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 } ?>
<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 } ?>
<?php echo $option_value['price']; ?>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question