Skip to content

Instantly share code, notes, and snippets.

@0test
Last active February 2, 2021 10:58
Show Gist options
  • Save 0test/ae3a377d3a5daf661090e906df1ce6dd to your computer and use it in GitHub Desktop.
Save 0test/ae3a377d3a5daf661090e906df1ce6dd to your computer and use it in GitHub Desktop.
Commerce - view one order
<tr class="orders_history_one">
<td>[+position+]</td>
<td></span><a href="[~[+product_id+]~]" target="_blank">[+title+]</a></td>
<td style="text-align:center;"><span class="showmobile">Опции</span>[+options+]</td>
<td style="text-align:center;"><span class="showmobile">Количество</span>[+count+]</td>
<td style="text-align:center;"><span class="showmobile">Цена</span>[[PriceFormat? &price=`[+price+]` &convert=`1`]]</td>
<td style="text-align: right; white-space: nowrap;"><span class="showmobile">Стоимость</span>[[PriceFormat? &price=`[+total+]` &convert=`1`]]</td>
</tr>
<?php
/**
* order_one
*
* Вывод данных одного заказа
*
[!order_one?
&OrderTpl=`order_one_tpl`
&ProductsTpl=`order_body_tpl`
&SubProductsTpl=`order_footer_tpl`
&dateFormat=`%d.%m.%Y %H:%M`
&dateSource=`created_at`
!]
**/
include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLTemplate.class.php');
$DLTemplate = DLTemplate::getInstance($modx);
$t1 = $modx->getFullTableName('commerce_orders');
$t2 = $modx->getFullTableName('commerce_order_products');
$t3 = $modx->getFullTableName('commerce_order_statuses');
$t4 = $modx->getFullTableName('site_tmplvar_contentvalues');
$t5 = $modx->getFullTableName('web_users');
$t6 = $modx->getFullTableName('web_user_attributes');
$uid = $modx->getLoginUserID('web');
$id_order = $_GET['id'];
$imgid = "13"; // id TV изображения
if(!empty($id_order)) {
// Сведения о заказе
$sql = 'SELECT o.id,o.customer_id,o.name,o.phone,o.email,o.amount,o.fields,o.status_id,o.created_at,o.updated_at,s.title as s_title,u.username, wu.fullname as fullname, wu.city as city, wu.street as street, wu.state as state, wu.fax as fax, wu.zip as zip , o.hash FROM '.$t1.' as o
LEFT JOIN '.$t3.' as s
ON s.id = o.status_id
LEFT JOIN '.$t5.' as u
ON u.id = o.customer_id
LEFT JOIN '.$t6.' as wu
ON wu.internalKey = u.id
WHERE o.id = '.$id_order.' AND u.id = '.$uid.'
GROUP BY o.created_at desc
LIMIT 0,1';
$res = $modx->db->query($sql);
$out='';
while($row = $modx->db->getRow($res)){
//['payment_delivery']['fields']['payment_link']
//var_dump(json_decode($row['fields']));
$row['delivery']= json_decode($row['fields']) -> delivery_method_title;
$row['payment']= json_decode($row['fields']) -> payment_method_title;
$row['state']= json_decode($row['fields']) -> state;
$row['city']= json_decode($row['fields']) -> city;
$row['street']= json_decode($row['fields']) -> street;
$row['message']= json_decode($row['fields']) -> message;
$out = $DLTemplate->parseChunk($OrderTpl, $row);
}
// Сведения о товаре
$sql2 = 'SELECT p.product_id,p.title,p.price,p.count,p.options,p.meta,p.position,t.value as image FROM '.$t2.' as p
LEFT JOIN '.$t4.' as t
ON t.contentid = p.product_id
WHERE p.order_id = '.$id_order.' AND t.tmplvarid = '.$imgid.'
GROUP BY p.position asc';
$res2 = $modx->db->query($sql2);
$out2='';
while($row = $modx->db->getRow($res2)){
$row['options'] = json_decode($row['options'])->char;
$row['total'] = $row['price']*$row['count'];
$out2 .= $DLTemplate->parseChunk($ProductsTpl, $row);
}
// Сведения о скидках и наценках
$sql3 = 'SELECT p.product_id,p.title,p.price,p.count,p.options,p.meta,p.position,t.value FROM '.$t2.' as p
LEFT JOIN '.$t4.' as t
ON t.contentid = p.product_id
WHERE p.order_id = '.$id_order.' AND p.product_id is NULL
GROUP BY p.position asc';
$res3 = $modx->db->query($sql3);
$out3='';
while($row = $modx->db->getRow($res3)){
$out3 .= $DLTemplate->parseChunk($SubProductsTpl, $row);
}
// Установка плейсхолдеров в основной чанк
$modx->setPlaceholder('products', $out2);
$modx->setPlaceholder('subproducts', $out3);
return $out;
}
<div class="row">
<div class="col-6">
<div class="sectionHeader panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Сведения о заказе</h4>
</div>
<div class="sectionBody">
<table class="table data group-fields">
<tbody>
<tr>
<td>Номер заказа:</td>
<td><strong>#[+id+]</strong></td>
</tr>
<tr>
<td>Дата и время создания:</td>
<td>[+created_at+]</td>
</tr>
<tr>
<td>Статус:</td>
<td>[+s_title+]</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Данные покупателя</h4>
</div>
<div class="sectionBody">
<table class="table data group-fields">
<tbody>
<tr>
<td>Имя:</td>
<td>[+fullname+]</td>
</tr>
<tr>
<td>Телефон:</td>
<td>[+phone+]</td>
</tr>
<tr>
<td>Email:</td>
<td><a href="mailto:[+email+]">[+email+]</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Адрес доставки</h4>
</div>
<div class="sectionBody">
<table class="table data group-fields">
<tbody>
<tr>
<td>Город: </td>
<td>[+city+]</td>
</tr>
<tr>
<td>Индекс: </td>
<td>[+zip+]</td>
</tr>
<tr>
<td>Улица: </td>
<td>[+street+]</td>
</tr>
<tr>
<td>Дом: </td>
<td>[+fax+]</td>
</tr>
<tr>
<td>Кв: </td>
<td>[+state+]</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Способ оплаты и доставки</h4>
</div>
<div class="sectionBody orders_history">
<table class="table data group-fields">
<tbody>
<tr>
<td>К оплате:</td>
<td><strong>[[PriceFormat? &price=`[+amount+]` &convert=`1`]]</strong></td>
</tr>
<tr>
<td>Способ доставки:</td>
<td>[+delivery+]</td>
</tr>
<tr>
<td>Способ оплаты:</td>
<td>[+payment+] </td>
[[if? &is=`[+payment+]:=:Оплата картой` &then=`<tr><td>Оплата:</td><td><a target="_blank" href="https://slavbazar.ru/commerce/payorder?hash=[+hash+]" class="button">Оплатить заказ</a></td></tr>`]]
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="table-responsive orders_history col-12">
<div class="orders_history_maintable">
<table class="table data orders_history_one_mobilestyle">
<thead>
<tr>
<td style="width: 1%;">#</td>
<td>Название</td>
<td>Опции</td>
<td>Кол-во</td>
<td>Цена</td>
<td style="text-align: right; white-space: nowrap;">Всего</td>
</tr>
</thead>
<tbody>
[+products+]
</tbody>
</table>
</div>
<table class="table data ">
<thead>
<tr>
<td>Название</td>
<td style="text-align: right; white-space: nowrap;">Цена</td>
</tr>
</thead>
<tbody>
[+subproducts+]
<tr class="orders_history_one">
<td>Итого к оплате</td>
<td style="text-align: right; white-space: nowrap;">[[PriceFormat? &price=`[+amount+]` &convert=`1`]]</td>
</tr>
</tbody>
</table>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment