This commit is contained in:
Roman Pyrih
2025-06-24 13:47:45 +02:00
parent db61ed2ec3
commit ebed09c00b
2 changed files with 77 additions and 61 deletions

View File

@@ -416,6 +416,8 @@ class PdProductAttributesList extends Module
$sql = 'SELECT pa.`id_product_attribute`, pa.`id_product`, pa.`reference`, pa.`ean13`, pa.`mpn`, pas.`weight` as weight_impact, p.`weight` as weight_base, pa.`minimal_quantity`,
ag.`id_attribute_group`, ag.`is_color_group`, agl.`public_name` AS group_name, al.`name` AS attribute_name, al.`name` AS attribute_name_html,
a.`id_attribute`, a.`color`
m.`id_manufacturer`, m.`name` AS manufacturer_name
FROM `'._DB_PREFIX_.'product_attribute` pa
INNER JOIN `'._DB_PREFIX_.'product_attribute_shop` pas ON (pas.id_product_attribute = pa.id_product_attribute AND pas.id_shop = '.(int)$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
@@ -424,6 +426,7 @@ class PdProductAttributesList extends Module
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = '.(int)$id_product.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
WHERE pa.`id_product` = '.(int)$id_product.'
ORDER BY pa.`id_product_attribute`';
@@ -431,6 +434,7 @@ class PdProductAttributesList extends Module
$results = Db::getInstance()->ExecuteS($sql);
$return = array();
$product = new Product($id_product, false, $id_lang, $id_shop);
$manufacturer = new Manufacturer($product->id_manufacturer, $id_lang);
$context = Context::getContext();
$specific_price_output = null;
$only_in_stock = Configuration::get('PD_PAL_ONLY_IN_STOCK');
@@ -554,6 +558,8 @@ class PdProductAttributesList extends Module
$r['id_product_attribute']
);
$return[$r['id_product_attribute']]['available_date'] = $product->available_date;
$return[$r['id_product_attribute']]['id_manufacturer'] = $manufacturer->id;
$return[$r['id_product_attribute']]['manufacturer_name'] = $manufacturer->name;
}
@@ -677,6 +683,8 @@ class PdProductAttributesList extends Module
),
'quantity' => StockAvailable::getQuantityAvailableByProduct($id_product, 0, $id_shop),
'available_date' => $product->available_date,
'id_manufacturer' => $manufacturer->id,
'manufacturer_name' => $manufacturer->name,
];
}

View File

@@ -4,11 +4,13 @@
{if $block_heading}
<h3 class="idTabHrefShort page-product-heading">{l s='Select product combination' mod='pdproductattributeslist'}</h3>
{/if}
<table id="pdproductattributeslist_table" class="2 table table-striped table-bordered table-labeled tablesorter" width="100%">
<table id="pdproductattributeslist_table" class="2 table table-striped table-bordered table-labeled tablesorter"
width="100%">
<thead>
<tr>
<th class="product_image sorter-false filter-false">{l s='Image' mod='pdproductattributeslist'}</th>
<th class="product_infos sorter-false filter-false">{l s='Product informations' mod='pdproductattributeslist'}</th>
<th class="product_infos sorter-false filter-false">{l s='Product informations' mod='pdproductattributeslist'}
</th>
{if $show_prices}
<th class="product_price">{l s='Price (tax incl.)' mod='pdproductattributeslist'}</th>
<th class="product_price">{l s='Price (tax excl.)' mod='pdproductattributeslist'}</th>
@@ -27,8 +29,10 @@
{foreach from=$combination.images item=$img}
<a href="{$img.large_default}" rel="group_{$combination.id_product_attribute}" class="{if ($img@index > 0)}hidden {/if}fancybox">
<img class="img img-fluid img-responsive" src="{$img.home_default}" alt="{$combination.attribute_name}" title="{$combination.attribute_name}" />
<a href="{$img.large_default}" rel="group_{$combination.id_product_attribute}"
class="{if ($img@index > 0)}hidden {/if}fancybox">
<img class="img img-fluid img-responsive" src="{$img.home_default}" alt="{$combination.attribute_name}"
title="{$combination.attribute_name}" />
</a>
{/foreach}
@@ -72,12 +76,13 @@
{/if}
<td data-column="{l s='Quantity on stock' mod='pdproductattributeslist'}" class="option_price _price">
<b>{if $combination.quantity <= 10 }{$combination.quantity}{else}>10{/if}</b> {l s='pcs' mod='pdproductattributeslist'}
<b>{if $combination.quantity <= 10 }{$combination.quantity}{else}>10{/if}</b>
{l s='pcs' mod='pdproductattributeslist'}
{if $combination.quantity == 0}
<br/>
<span class="available_data">{$combination.available_date}</span>
{/if}
{if $combination.quantity == 0}
<br />
<span class="available_data">{$combination.available_date}</span>
{/if}
</td>
@@ -86,9 +91,12 @@
</td>
{if !$is_catalog}
<td data-id-product="{$combination.id_product|intval}" data-id-product-attribute="{$combination.id_product_attribute|intval}" data-column="{l s='Select quantity' mod='pdproductattributeslist'}" class="option_gty">
<td data-id-product="{$combination.id_product|intval}"
data-id-product-attribute="{$combination.id_product_attribute|intval}"
data-column="{l s='Select quantity' mod='pdproductattributeslist'}" class="option_gty">
<div class="row extra-small-gutters product-quantity">
<input type="number" name="qty" inputmode="numeric" pattern="[0-9]*" class="quantity input-group form-control" min="0" value="0" alert_max="{$combination.quantity}" />
<input type="number" name="qty" inputmode="numeric" pattern="[0-9]*"
class="quantity input-group form-control" min="0" value="0" alert_max="{$combination.quantity}" />
</div>
</td>
{/if}
@@ -99,68 +107,68 @@
</tbody>
</table>
<div class="footer_actions">
<button class="btn btn-lg btn-primary add-to-cart-pdproductattributeslist pull-right" type="button">
{l s='Add selected to cart' mod='pdproductattributeslist'}
</button>
{* {if !in_array($combination.id_manufacturer, [5, 9, 13])} *}
<button class="btn btn-lg btn-primary add-to-cart-pdproductattributeslist pull-right" type="button">
{l s='Add selected to cart' mod='pdproductattributeslist'}
</button>
{* {/if} *}
</div>
</div>
{/if}
{literal}
<!-- wklej tuż przed zamknięciem </body> lub w zewnętrznym pliku JS załadowanym po tabeli -->
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('td.option_gty').forEach(td => {
const input = td.querySelector('input.quantity');
if (!input) return;
<!-- wklej tuż przed zamknięciem </body> lub w zewnętrznym pliku JS załadowanym po tabeli -->
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('td.option_gty').forEach(td => {
const input = td.querySelector('input.quantity');
if (!input) return;
const max = parseInt(input.getAttribute('alert_max'), 10) || 0;
const max = parseInt(input.getAttribute('alert_max'), 10) || 0;
// funkcja tworząca/usuń alert
function checkQty() {
const val = parseInt(input.value, 10) || 0;
const existing = td.querySelector('.alert-max-exceeded');
// funkcja tworząca/usuń alert
function checkQty() {
const val = parseInt(input.value, 10) || 0;
const existing = td.querySelector('.alert-max-exceeded');
const _lang = document.querySelector('html').getAttribute('lang');
const _lang = document.querySelector('html').getAttribute('lang');
if (val > max) {
if (!existing) {
const msg = document.createElement('div');
msg.className = 'alert-max-exceeded text-danger';
msg.style.marginTop = '4px';
msg.style.fontSize = '0.9em';
if(_lang == 'pl') {
msg.innerHTML = 'Przekroczono stan,<br>braki trafią do back order.';
if (val > max) {
if (!existing) {
const msg = document.createElement('div');
msg.className = 'alert-max-exceeded text-danger';
msg.style.marginTop = '4px';
msg.style.fontSize = '0.9em';
if (_lang == 'pl') {
msg.innerHTML = 'Przekroczono stan,<br>braki trafią do back order.';
} else {
msg.innerHTML = 'Stock exceeded,<br>shortages will go to back order.';
}
td.querySelector('.product-quantity')
.insertAdjacentElement('afterend', msg);
}
} else {
msg.innerHTML = 'Stock exceeded,<br>shortages will go to back order.';
if (existing) existing.remove();
}
td.querySelector('.product-quantity')
.insertAdjacentElement('afterend', msg);
}
} else {
if (existing) existing.remove();
}
}
// od razu sprawdź raz przy starcie
checkQty();
// łapiemy ręczne wpisywanie
input.addEventListener('input', checkQty);
// i wszelkie inne zmiany przez polling w tle
(function monitor(prevValue = input.value) {
const curr = input.value;
if (curr !== prevValue) {
// od razu sprawdź raz przy starcie
checkQty();
prevValue = curr;
}
requestAnimationFrame(() => monitor(prevValue));
})();
});
});
</script>
// łapiemy ręczne wpisywanie
input.addEventListener('input', checkQty);
// i wszelkie inne zmiany przez polling w tle
(function monitor(prevValue = input.value) {
const curr = input.value;
if (curr !== prevValue) {
checkQty();
prevValue = curr;
}
requestAnimationFrame(() => monitor(prevValue));
})();
});
});
</script>
{/literal}