Jump to content
Soberman

Отобразить вес заказа в order info

Recommended Posts

Здравствуйте.

Как можно отобразить вес заказа вот в этом месте?

https://take.ms/o1Mq6

 

 

Share this post


Link to post
Share on other sites

В модели заказов добавить функцию получения веса заказа (admin/model/sale/order.php)

В контроллере заказов добавить в исходящий массив данные (admin/controller/sale/order.php)

В шаблоне заказа использовать переменную (admin/view/template/sale/order_info.tpl)

 

Share this post


Link to post
Share on other sites

admin\model\sale\order.php

public function getOrderWeight($order_id) {

$query = $this->db->query("SELECT SUM(p.weight * op.quantity) AS weight FROM " . DB_PREFIX . "order_product op LEFT JOIN " . DB_PREFIX . "product p ON op.product_id = p.product_id WHERE op.order_id = '" . (int)$order_id . "'");

if ($query->row['weight']) {
$weight = $query->row['weight'];
} else {
$weight = 0;
}

return $weight;
}

 

admin\controller\sale\order.php

$data['weight'] = $this->model_sale_order->getOrderWeight($this->request->get['order_id']);

 

admin\view\template\sale\order_info.tpl

<?php echo $weight; ?>

 

  • +1 2

Share this post


Link to post
Share on other sites
3 часа назад, ocdroid сказал:

SELECT SUM(p.weight * op.quantity) AS weight

 

будет работать только если формат веса у всех товаров в магазине одинаков

при разных - будет ерунда

  • +1 2

Share this post


Link to post
Share on other sites

@AlexDW А если функция будет такой, более универсально?

public function getOrderWeight($order_id) {
$weight=0;
$query = $this->db->query("SELECT p.weight, op.quantity, p.weight_class_id 
    FROM " . DB_PREFIX . "order_product op 
    LEFT JOIN " . DB_PREFIX . "product p ON (op.product_id = p.product_id) 
    WHERE op.order_id = '" . (int)$order_id . "'");	  				
    foreach ($query->rows as $row) {
    $weight += $this->weight->convert($row['weight'] * $row['quantity'], $row['weight_class_id'], 1); }
    return $weight;
    } 

 

  • +1 2

Share this post


Link to post
Share on other sites
Posted (edited)

Ого сколько придумали)) Спасибо, буду пробовать.

Edited by Soberman

Share this post


Link to post
Share on other sites
10 часов назад, ocdroid сказал:

admin\controller\sale\order.php


$data['weight'] = $this->model_sale_order->getOrderWeight($this->request->get['order_id']);

А в ккое место кода это вставить? 

Share this post


Link to post
Share on other sites

примерно туда где и собираются данные о заказе

ищите например $data['shipping_method'] = $order_info['shipping_method'];

Share this post


Link to post
Share on other sites
2 часа назад, PaulKravchenko сказал:

примерно туда где и собираются данные о заказе

ищите например $data['shipping_method'] = $order_info['shipping_method'];

Куда бы ни воткнул (два места есть с такой строкой) , после сброса модификаторов при попытке входа в заказы выдает ошибку на строку кода чуть ниже

 

Спойлер

Parse error: syntax error, unexpected ''weight'' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /var/www/a61635/data/www/aromadoma.ru/system/storage/modification/admin/controller/sale/order.php on line 958

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.