Skip to content

Commit

Permalink
Add barcode to order info view (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion authored Nov 28, 2023
1 parent 85ab4a2 commit 74e2b58
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## V1.1.0

- Show shipping barcode in admin order view

## V1.0.1

- Fix orders list error when no orders exist
Expand Down
49 changes: 46 additions & 3 deletions admin/controller/module/parcelpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public function install(): void
'sort_order' => 1
]);

$this->model_setting_event->addEvent([
'code' => 'parcelpro_add_barcode_order_info',
'description' => '',
'trigger' => 'admin/view/sale/order_info/before',
'action' => 'extension/parcelpro/module/parcelpro.addBarcode',
'status' => 1,
'sort_order' => 1
]);

$this->model_setting_event->addEvent([
'code' => 'parcelpro_submit_order_by_status',
'description' => '',
Expand Down Expand Up @@ -74,10 +83,10 @@ public function uninstall()
$this->model_setting_event->deleteEventByCode('parcelpro_add_pickup_address_order_info');
$this->model_setting_event->deleteEventByCode('parcelpro_add_buttons_order_list');
$this->model_setting_event->deleteEventByCode('parcelpro_add_buttons_order');
$this->model_setting_event->deleteEventByCode('parcelpro_add_barcode_order_info');
$this->model_setting_event->deleteEventByCode('parcelpro_submit_order_by_status');
}


public function index()
{
$this->checkdb();
Expand Down Expand Up @@ -292,7 +301,6 @@ private function checkdb()
}
}

////
// event handler for admin/view/sale/order_list/before
public function addParcelButtons(&$route, &$data, &$template_code = null)
{
Expand Down Expand Up @@ -539,13 +547,48 @@ public function addPickupInfo(&$route, &$data, &$template_code = null)
}
}

// event handler for admin/view/sale/order_info/before
public function addBarcode($route, &$data, &$template_code = null)
{
$this->language->load('extension/parcelpro/sale/pp_order');
$order_id = $data['order_id'];

$barcodes = $this->getBarcodes([$order_id]);
if (isset($barcodes[$order_id])) {
$data['su_barcode'] = $barcodes[$order_id];

$template = new TemplateBuffer();
$template_buffer = $template->getTemplateBuffer($route, $template_code);

$template_buffer = str_replace(
'<div id="payment-method" class="col-md">',
'
{% if su_barcode %}
<div id="su-barcode" class="col-md">
<div class="form-control border rounded-start">
<div class="lead">
<strong>' . $this->language->get('column_barcode') . '</strong>
<br/>
<span id="su-barcode-value">{{ su_barcode }}</span>
</div>
</div>
</div>
{% endif %}
<div id="payment-method" class="col-md">
',
$template_buffer
);

$template_code = $template_buffer;
}
}

public function getBarcodes($order_ids = [])
{
if (empty($order_ids)) {
return [];
}

// TODO: This errors when no orders exist.
$order_query = $this->db->query("SELECT order_id, su_barcode FROM " . DB_PREFIX . "order WHERE order_id IN (" . implode(',', $order_ids) . ")");

return array_column($order_query->rows, 'su_barcode', 'order_id');
Expand Down
2 changes: 1 addition & 1 deletion admin/language/dutch/sale/pp_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Contact: [email protected]
//==============================================================================

$version = '1.0.1';
$version = '1.1.0';

// Heading
$_['heading_title'] = 'Parcel Pro';
Expand Down
2 changes: 1 addition & 1 deletion admin/language/dutch/shipping/parcel_pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Contact: [email protected]
//==============================================================================

$version = '1.0.1';
$version = '1.1.0';

// Heading
$_['heading_title'] = 'Parcel Pro';
Expand Down
2 changes: 1 addition & 1 deletion admin/language/en-gb/sale/pp_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Contact: [email protected]
//==============================================================================

$version = '1.0.1';
$version = '1.1.0';

// Heading
$_['heading_title'] = 'Parcel Pro';
Expand Down
2 changes: 1 addition & 1 deletion admin/language/en-gb/shipping/parcel_pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Contact: [email protected]
//==============================================================================

$version = '1.0.1';
$version = '1.1.0';

// Heading
$_['heading_title'] = 'Parcel Pro';
Expand Down
2 changes: 1 addition & 1 deletion admin/model/sale/parcelproorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Opencart\Admin\Model\Extension\ParcelPro\Sale;

//==============================================================================
// Parel Pro Shipping v1.0.1
// Parel Pro Shipping
//
// Company: Parcel Pro
// Contact: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion install.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Parcel Pro",
"code": "parcelpro",
"license": "GPL",
"version": "1.0.1",
"version": "1.1.0",
"author": "Parcel Pro",
"link": "https://www.parcelpro.nl/"
}

0 comments on commit 74e2b58

Please sign in to comment.