Post by htwp » Tue Nov 12, 2024 10:49 pm

Hello,
I need assistance with displaying the price of product options on the Admin Order Product page in OpenCart. Currently, when viewing the order details in the Admin panel, the product options are listed, but the price of each option is not shown next to the option name. I would like to show the price of each selected option as part of the product title or in a separate column, if possible.

Until now I have done the following:

admin/model/sale/order.php

Code: Select all

public function getOrderOptions($order_id, $order_product_id) {
    $query = $this->db->query("SELECT oo.name, oo.value, oo.type, pov.price, pov.price_prefix 
        FROM " . DB_PREFIX . "order_option oo
        LEFT JOIN " . DB_PREFIX . "product_option_value pov ON (oo.product_option_value_id = pov.product_option_value_id)
        WHERE oo.order_id = '" . (int)$order_id . "' AND oo.order_product_id = '" . (int)$order_product_id . "'");

    return $query->rows;
}
admin/controller/sale/order.php

Code: Select all

// Products
$data['order_products'] = array();

$products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);

foreach ($products as $product) {
    // Get options and include price
    $product_options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
    $options_with_price = array();

    foreach ($product_options as $option) {
        $options_with_price[] = array(
            'name'  => $option['name'],
            'value' => $option['value'],
            'type'  => $option['type'],
            'price' => isset($option['price']) ? $this->currency->format($option['price'], $this->config->get('config_currency')) : null
        );
    }

    $data['order_products'][] = array(
        'product_id' => $product['product_id'],
        'name'       => $product['name'],
        'model'      => $product['model'],
        'option'     => $options_with_price, // Use options with price here
        'quantity'   => $product['quantity'],
        'price'      => $product['price'],
        'total'      => $product['total'],
        'reward'     => $product['reward']
    );
}
and finally in the order_info.twig file

Code: Select all

<td class="text-left">
    <a href="{{ product.href }}">{{ product.name }}</a>
    {% for option in product.option %}
        <br />
        {% if option.type != 'file' %}
            &nbsp;<small> - {{ option.name }}: {{ option.value }}{% if option.price %} (Price: {{ option.price }}){% endif %}</small>
        {% else %}
            &nbsp;<small> - {{ option.name }}: <a href="{{ option.href }}">{{ option.value }}</a></small>
        {% endif %}
    {% endfor %}
</td>
It doesn't work.

Does anyone know how I can modify the admin panel to display the price of the options for products in an order? I'm using OpenCart 3.0.3.3 and any guidance on the necessary code changes or settings would be greatly appreciated.

Thank you!

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

Post by ADD Creative » Wed Nov 13, 2024 12:29 am

Are you changing the correct part of the controller? You might want to change the info instead of the getForm.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: No registered users and 55 guests