A
A
Alpha122019-12-15 00:09:11
opencart
Alpha12, 2019-12-15 00:09:11

How to remove extra zeros in the price, opencart 2?

Good afternoon, I display product options in a category
with this code

categories.php

// Function Products Options in category

  $options = array();

      foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
        $product_option_value_data = array();

        foreach ($option['product_option_value'] as $option_value) {
          if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
            if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
              $opt_price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
            } else {
              $opt_price = false;
            }

            $product_option_value_data[] = array(
              'product_option_value_id' => $option_value['product_option_value_id'],
              'option_value_id'         => $option_value['option_value_id'],
              'name'                    => $option_value['name'],
              'image'                   => $option_value['image'] ? $this->model_tool_image->resize($option_value['image'], 50, 50) : '',
              'price'                   => $opt_price,
              'price_prefix'            => $option_value['price_prefix']
            );
          }
        }

        $options= array(
          'product_option_id'    => $option['product_option_id'],
          'product_option_value' => $product_option_value_data,
          'option_id'            => $option['option_id'],
          'name'                 => $option['name'],
          'type'                 => $option['type'],
          'value'                => $option['value'],
          'required'             => $option['required']
        );
      }


// END Function


To array I write
$data['products'][] = array(
'options'   => $this->model_catalog_product->getProductOptions($result['product_id']), // Add option to $result products.

In the front I bring out like this
category.tpl

<?php if ($product['options']) { ?>
  <?php $i= 0; ?>
<?php foreach ($product['options'] as $option) { ?>

   <?php if ($option['type'] == 'radio') { ?>
            <div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
             
              <div id="input-option<?php echo $option['product_option_id']; ?>">
                <?php foreach ($option['product_option_value'] as $option_value) { ?>
                <?php $i++;?>

                <div class="radio">
                  <label>
                  <?php if($i== 1) {?>
                    <input checked type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" />
                    <?php } else {?>
                                          <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" />

                      <?php } ?>
                    <?php if ($option_value['image']) { ?>
                    <img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" class="img-thumbnail" /> 
                    <?php } ?>                    
                    <?php echo $option_value['name']; ?>
                    <?php if ($option_value['price']) { ?>
                    (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                    <?php } ?>
                  </label>
                </div>
                <?php } ?>
              </div>
            </div>
            <?php } ?>
<?php } ?>
<?php } ?>


And here the problem is it displays the price in this format
Large (+30.0000)

What should I do ... I did everything by analogy with the card file, the price is normally displayed there.
Site
https://www.pizzaritta.ru/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2019-12-15
@IceRD

Especially for you, we came up with the $this->currency->format method, taking into account taxes $this->tax->calculate, so that the user does not climb into the code, but sets the number of characters after the comma from the admin panel.

$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question