147 lines
9.0 KiB
PHP
147 lines
9.0 KiB
PHP
<?php
|
|
use_helper('stPrice');
|
|
/**
|
|
* @var AllegroApiShippingRate $allegro_api_shipping_rate
|
|
*/
|
|
?>
|
|
|
|
|
|
<div id="allegro-deliveries" class="bs-mt-1">
|
|
<div class="visibility-toggle">
|
|
<?php echo st_get_admin_button('default', __('Pokaż wszystkie'), '#', array('class' => 'show-all', 'size' => 'small')) ?>
|
|
<?php echo st_get_admin_button('default', __('Pokaż tylko zaznaczone'), '#', array('class' => 'show-only-selected bs-d-none bs-ms-0', 'size' => 'small')) ?>
|
|
</div>
|
|
<?php $errorId = 0 ?>
|
|
<?php foreach ($deliveryGroups as $group => $types): ?>
|
|
<?php foreach ($types as $type => $deliveryMethods): $index = 0 ?>
|
|
<div class="allegro-delivery-group bs-d-none" style="margin-top: 15px;">
|
|
<b><?php echo __($group) ?> - <?php echo $type == 'IN_ADVANCE' ? __('Płatność z góry') : __('Płatność przy odbiorze') ?></b>
|
|
<?php st_admin_table_start(array(
|
|
array('label' => __('Aktywna')),
|
|
array('label' => __('Metoda dostawy'), 'width' => '80%', 'align' => 'left'),
|
|
array('label' => __('Pierwsza sztuka')),
|
|
array('label' => __('Maks. w paczce')),
|
|
array('label' => __('Kolejna sztuka')),
|
|
), array('class' => 'allegro-delivery-table')) ?>
|
|
<tbody>
|
|
<?php foreach ($deliveryMethods as $method):
|
|
$rate = $allegro_api_shipping_rate->getRate($method->id);
|
|
$constrains = $method->shippingRatesConstraints;
|
|
$namespace = $name.'['.$method->id.']';
|
|
$index++;
|
|
|
|
?>
|
|
<tr>
|
|
<td><?php echo st_admin_checkbox_tag($namespace.'[active]', 1, null !== $rate, array('class' => 'active')) ?></td>
|
|
<td <?php if ($rate && $sf_request->hasError('rates['.$errorId.'].deliveryMethod.id')): ?>class="form-error tooltip text-left" title="<?php echo htmlspecialchars($sf_request->getError('rates['.$errorId.'].deliveryMethod.id')) ?>"<?php else: ?>class="text-left"<?php endif ?>>
|
|
<?php echo $method->name ?>
|
|
<?php if ($rate && $sf_request->hasError('rates['.$errorId.'].deliveryMethod.id')): ?>
|
|
<?php echo st_admin_get_icon('error') ?>
|
|
<?php endif ?>
|
|
</td>
|
|
<td <?php if ($rate && $sf_request->hasError('rates['.$errorId.'].firstItemPrice.amount')): ?>class="form-error tooltip" title="<?php echo htmlspecialchars($sf_request->getError('rates['.$errorId.'].firstItemPrice.amount')) ?>"<?php endif ?>>
|
|
<?php echo input_tag($namespace.'[first_item_rate][amount]', stCurrency::formatPrice($rate ? $rate['first_item_rate']['amount'] : $constrains->firstItemRate->min), array(
|
|
'style' => 'width: 60px',
|
|
'maxlength' => 10,
|
|
'disabled' => !$rate,
|
|
'class' => 'price',
|
|
'data-format' => 'decimal',
|
|
'data-format-min-value' => $constrains->firstItemRate->min,
|
|
'data-format-max-value' => $constrains->firstItemRate->max,
|
|
)) ?>
|
|
<?php echo input_hidden_tag($namespace.'[first_item_rate][currency]', $rate ? $rate['next_item_rate']['currency'] : 'PLN', array('class' => 'hidden', 'disabled' => !$rate)) ?>
|
|
<?php if ($rate && $sf_request->hasError('rates['.$errorId.'].firstItemPrice.amount')): ?>
|
|
<?php echo st_admin_get_icon('error') ?>
|
|
<?php endif ?>
|
|
</td>
|
|
<td <?php if ($rate && $sf_request->hasError('rates['.$errorId.'].maxQuantityPerPackage')): ?>class="form-error tooltip" title="<?php echo htmlspecialchars($sf_request->getError('rates['.$errorId.'].maxQuantityPerPackage')) ?>"<?php endif ?>>
|
|
<?php echo input_tag($namespace.'[max_quantity_per_package]', $rate ? $rate['max_quantity_per_package'] : 1, array(
|
|
'style' => 'width: 60px',
|
|
'maxlength' => 10,
|
|
'disabled' => !$rate,
|
|
'class' => 'price',
|
|
'data-format' => 'integer',
|
|
'data-format-min-value' => 1,
|
|
'data-format-max-value' => $constrains->maxQuantityPerPackage->max,
|
|
)) ?>
|
|
<?php if ($rate && $sf_request->hasError('rates['.$errorId.'].maxQuantityPerPackage')): ?>
|
|
<?php echo st_admin_get_icon('error') ?>
|
|
<?php endif ?>
|
|
</td>
|
|
<td <?php if ($rate && $sf_request->hasError('rates['.$errorId.'].nextItemPrice.amount')): ?>class="form-error tooltip" title="<?php echo htmlspecialchars($sf_request->getError('rates['.$errorId.'].nextItemPrice.amount')) ?>"<?php endif ?>>
|
|
<?php echo input_tag($namespace.'[next_item_rate][amount]', stCurrency::formatPrice($rate ? $rate['next_item_rate']['amount'] : $constrains->nextItemRate->min), array(
|
|
'style' => 'width: 60px; vertical-align: middle',
|
|
'maxlength' => 10,
|
|
'disabled' => !$rate,
|
|
'class' => 'price',
|
|
'data-format' => 'decimal',
|
|
'data-format-min-value' => $constrains->nextItemRate->min,
|
|
'data-format-max-value' => $constrains->nextItemRate->max,
|
|
)) ?>
|
|
<?php echo input_hidden_tag($namespace.'[next_item_rate][currency]', $rate ? $rate['next_item_rate']['currency'] : 'PLN', array('class' => 'hidden', 'disabled' => !$rate)) ?>
|
|
<?php if ($rate && $sf_request->hasError('rates['.$errorId.'].nextItemPrice.amount')): ?>
|
|
<?php echo st_admin_get_icon('error') ?>
|
|
<?php endif ?>
|
|
</td>
|
|
</tr>
|
|
<?php if (null !== $rate) $errorId++ ?>
|
|
<?php endforeach ?>
|
|
</tbody>
|
|
<?php st_admin_table_end() ?>
|
|
</div>
|
|
<?php endforeach ?>
|
|
<?php endforeach ?>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function($) {
|
|
$(document).ready(function() {
|
|
var allegroDeliveries = $('#allegro-deliveries');
|
|
|
|
allegroDeliveries.find('.active').change(function() {
|
|
let checkbox = $(this);
|
|
let tr = checkbox.closest('tr');
|
|
|
|
tr.find('.price,.hidden').prop('disabled', !checkbox.prop('checked'));
|
|
});
|
|
|
|
allegroDeliveries.find('.visibility-toggle').on('click', 'a', function() {
|
|
let link = $(this);
|
|
|
|
if (link.hasClass('show-all')) {
|
|
link.closest('div').find('.show-only-selected').removeClass('bs-d-none');
|
|
link.addClass('bs-d-none');
|
|
let group = allegroDeliveries.find('.allegro-delivery-group').removeClass('bs-d-none');
|
|
allegroDeliveries.find('.allegro-delivery-table tbody tr').removeClass('bs-d-none');
|
|
} else {
|
|
link.closest('div').find('.show-all').removeClass('bs-d-none');
|
|
link.addClass('bs-d-none');
|
|
showChecked();
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
function showChecked () {
|
|
let trs = $('#allegro-deliveries table tbody tr');
|
|
|
|
$('.allegro-delivery-group').addClass('bs-d-none');
|
|
|
|
trs.each(function() {
|
|
let tr = $(this);
|
|
let checked = tr.find('[type="checkbox"]').prop("checked");
|
|
|
|
if (checked) {
|
|
tr.removeClass('bs-d-none');
|
|
tr.closest('.allegro-delivery-group').removeClass('bs-d-none');
|
|
} else {
|
|
tr.addClass('bs-d-none');
|
|
}
|
|
});
|
|
}
|
|
|
|
showChecked();
|
|
});
|
|
});
|
|
</script>
|