Чи можна ось так зібрати ocmod, але треба перевірити
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Quantity Based Cart Discount</name>
<code>quantity_based_cart_discount</code>
<version>1.0</version>
<author>niger</author>
<link>https://www.example.com</link>
<file path="catalog/model/checkout/cart.php">
<operation>
<search position="after"><![CDATA[
$products = $this->getProducts();
]]></search>
<add><![CDATA[
$total_quantity = 0;
foreach ($products as $product) {
$total_quantity += $product['quantity'];
}
if ($total_quantity >= 4) {
$discount_quantity_percentage = 0.30;
} elseif ($total_quantity == 3) {
$discount_quantity_percentage = 0.25;
} elseif ($total_quantity == 2) {
$discount_quantity_percentage = 0.15;
} elseif ($total_quantity == 1) {
$discount_quantity_percentage = 0.05;
} else {
$discount_quantity_percentage = 0;
}
if ($discount_percentage > 0) {
$total = $total - ($total * $discount_quantity_percentage);
$total_data[] = array(
'code' => 'quantity_discount',
'title' => 'Знижка за кількість товарів (' . ($discount_quantity_percentage * 100) . '%)',
'text' => '-' . $this->currency->format($this->tax->calculate($total * $discount_quantity_percentage, 0, $this->config->get('config_tax'))),
'value' => $total * $discount_quantity_percentage,
'sort_order' => 1
);
}
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/cart.twig">
<operation>
<search position="before"><![CDATA[
</tbody>
]]></search>
<add><![CDATA[
{% if quantity_discount %}
<tr>
<td colspan="4" class="text-right"><strong>Знижка за кількість товарів</strong></td>
<td class="text-right">-{{ quantity_discount }}</td>
</tr>
{% endif %}
]]></add>
</operation>
</file>
<file path="catalog/view/theme/default/template/checkout/confirm.twig">
<operation>
<search position="before"><![CDATA[
</tbody>
]]></search>
<add><![CDATA[
{% if quantity_discount %}
<tr>
<td colspan="4" class="text-right"><strong>Знижка за кількість товарів</strong></td>
<td class="text-right" style="color: red;">-{{ quantity_discount }}</td>
</tr>
{% endif %}
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation>
<search position="after"><![CDATA[
$data['products'] = array();
]]></search>
<add><![CDATA[
$data['quantity_discount'] = '';
if (isset($total_data)) {
foreach ($total_data as $total_line) {
if ($total_line['code'] == 'quantity_discount') {
$data['quantity_discount'] = $total_line['text'];
}
}
}
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/confirm.php">
<operation>
<search position="after"><![CDATA[
$data['totals'] = array();
]]></search>
<add><![CDATA[
$data['quantity_discount'] = '';
if (isset($totals)) {
foreach ($totals as $total_line) {
if ($total_line['code'] == 'quantity_discount') {
$data['quantity_discount'] = $total_line['text'];
}
}
}
]]></add>
</operation>
</file>
</modification>