Skip to content

Commit

Permalink
PES-2174 Global fix for Jm3 VM3 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrakor committed Jul 15, 2024
1 parent 13b01c4 commit 95c9c51
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

class JToolbarButtonPacketaJs extends \JToolbarButton
{
protected $_name = 'PacketaPrintLabel';

/**
* @return string
*/
public function fetchButton()
{
return sprintf('
<div class="btn-wrapper">
<button class="btn btn-small" id="toolbar-packetaPrintLabel" type="button">
<span class="icon-print" aria-hidden="true"></span>
%s
</button>
</div>',
\JText::_('PLG_VMSHIPMENT_PACKETERY_PRINT_LABEL'));
}

/**
* @return string
*/
public function fetchId()
{
return $this->_parent->getName() . '-packeta-print-label';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function renderPrintLabelForm(Order $order = null)
'order' => $order,
'defaultLabelFormat' => $this->getDefaultLabelFormat($labelFormatType),
'labelFormatType' => $labelFormatType,
'jm3class' => \plgVmShipmentZasilkovna::isJoomla3() ? 'jm3' : '',
]);

$this->renderer->setTemplate(self::TEMPLATES_DIR . DS . 'order_print_label_form.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* @var \VirtueMartModelZasilkovna\Order\Order $order
* @var string $defaultLabelFormat
* @var string $labelFormatType
* @var string $jm3class
*/

defined('_JEXEC') or die;

$token = \JHtml::_('form.token');
?>
<div id="packeteryPrintLabelModal">
<div id="packeteryPrintLabelModal" class="<?php echo $jm3class; ?>">
<form action="index.php?option=com_virtuemart&view=zasilkovna&task=printLabels" method="post" id="packeteryPrintLabelForm">
<div class="form-container">
<input type="hidden" name="virtuemart_order_id" value="<?php echo htmlentities($order->getVirtuemartOrderId()); ?>">
Expand Down Expand Up @@ -51,14 +52,14 @@
<div class="uk-inline">
<a href="#" title="<?php echo JText::_('PLG_VMSHIPMENT_PACKETERY_PRINT'); ?>"
onclick="submitPrintLabel(event);"
class="uk-button uk-button-small uk-button-primary md-bg-white">
<span class="uk-icon" uk-icon="icon: printer; ratio: 1"></span>
class="uk-button uk-button-small uk-button-primary md-bg-white btn btn-small">
<span class="uk-icon icon-nofloat icon-print" uk-icon="icon: printer; ratio: 1"></span>
&nbsp;<?php echo JText::_('PLG_VMSHIPMENT_PACKETERY_PRINT'); ?>
</a>
<a href="#" title="<?php echo JText::_('PLG_VMSHIPMENT_PACKETERY_CANCEL'); ?>"
onclick="cancelPacketeryPrintLabel(event);"
class="uk-button uk-button-small uk-button-default md-bg-white">
<span class="icon-nofloat vmicon vmicon-16-remove"></span>
class="btn btn-small uk-button uk-button-small uk-button-default md-bg-white ">
<span class="icon-nofloat vmicon-16-remove"></span>
&nbsp;<?php echo JText::_('PLG_VMSHIPMENT_PACKETERY_CANCEL'); ?>
</a>
</div>
Expand Down
23 changes: 23 additions & 0 deletions media/media/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,26 @@ a#toolbar-packetaPrintLabel:focus > span {
.autosubmit_order_status_select {
min-width: 200px;
}

#packeteryPrintLabelModal.jm3 {
margin-top: -80px;
}

#packeteryPrintLabelModal.jm3 .uk-card-title {
font-weight: 600;
}

#packeteryPrintLabelModal.jm3 .uk-table td.key {
min-width: 80px;
width: 80px;
}

.jm3 #print_type_chzn,
.jm3 #print_type_chzn .chzn-drop,
.jm3 #print_type_chzn .chzn-drop .chzn-search input {
width: 100%!important;
}

.jm3 .uk-card-footer .uk-inline {
text-align: center;
}
48 changes: 47 additions & 1 deletion zasilkovna.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ($className) {

require_once VMPATH_ADMIN . '/fields/vmzasilkovnacountries.php';
require_once VMPATH_ADMIN . '/fields/vmzasilkovnahdcarriers.php';
require_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/models/zasilkovna_src/JToolbarButtonPacketaJs.php';

class plgVmShipmentZasilkovna extends vmPSPlugin
{
Expand Down Expand Up @@ -958,7 +959,12 @@ public function plgVmOnShowOrderBEShipment($virtuemart_order_id, $virtuemart_shi
$order = $this->orderRepository->getOrderByVmOrderId($virtuemart_order_id);

if ($order) {
$this->addPacketaToolbarButtons($order);
// if Joomla version is 3 or lower, we must use old toolbar buttons
if (self::isJoomla3()) {
$this->addPacketaToolbarButtonsJm3($order);
} else {
$this->addPacketaToolbarButtons($order);
}
}

return $this->orderDetail->renderToString($order);
Expand Down Expand Up @@ -1239,6 +1245,39 @@ private function addPacketaToolbarButtons(\VirtueMartModelZasilkovna\Order\Order
$items[] = $lastButton;
$toolbar->setItems($items);
}

private function addPacketaToolbarButtonsJm3(\VirtueMartModelZasilkovna\Order\Order $order)
{
$toolbar = JToolbar::getInstance('toolbar');
$path = JPATH_ADMINISTRATOR . '/components/com_virtuemart/models/zasilkovna_src/';
$toolbar->addButtonPath($path);

$reflectionClass = new ReflectionClass($toolbar);
$barProperty = $reflectionClass->getProperty('_bar');
$barProperty->setAccessible(true);
$bar = $barProperty->getValue($toolbar); // Get the current _bar array
$lastButton = array_pop($bar); // lastButton is Help button
$barProperty->setValue($toolbar, $bar); // Set the modified array back if necessary

$toolbar->appendButton('Separator', 'separator');
if ($order->hasPacketId()) {
$packetaButton = new JToolbarButtonPacketaJs('packetaPrintLabel');
$toolbar->appendButton('PacketaJs', $packetaButton);

} else {
JToolbarHelper::link(
'index.php?option=com_virtuemart&view=zasilkovna&task=submitPacket&virtuemart_order_id=' . $order->getVirtuemartOrderId(),
JText::_('PLG_VMSHIPMENT_PACKETERY_SUBMIT_TO_PACKETA'),
'envelope'
);
}
$toolbar->appendButton('Separator', 'separator');

$bar = $barProperty->getValue($toolbar);
$bar[] = $lastButton; // Add the Help button back
$barProperty->setValue($toolbar, $bar);
}

/**
* @param TableOrders &$data
* @param string $old_order_status
Expand Down Expand Up @@ -1274,4 +1313,11 @@ private function shouldAutosubmit($vmPaymentMethodId, $vmOrderStatusCode)
return (array_key_exists($vmPaymentMethodId, $autosubmitOrderStatuses) && $autosubmitOrderStatuses[$vmPaymentMethodId] === $vmOrderStatusCode);
}

/**
* @return bool
*/
public static function isJoomla3()
{
return version_compare(JVERSION, '4.0.0', 'lt');
}
}

0 comments on commit 95c9c51

Please sign in to comment.