For MPC beside Current price display also Old price if discounted

This commit is contained in:
Mihael
2026-01-30 14:21:44 +01:00
parent 4101d4df6f
commit 3c1d969711
2 changed files with 62 additions and 12 deletions

View File

@@ -394,23 +394,68 @@ class B2BPayments extends PaymentModule implements PrestaShop\PrestaShop\Core\Mo
$id_product_attribute = (int)$embeddedProductAttributes['id_product_attribute'] ?? null;
$id_product = (int)$embeddedProductAttributes['id_product'];
$this->smarty->assign(['mpc' => $this->context->getCurrentLocale()->formatPrice(
$this->calculateMPC($id_product, $id_product_attribute),
$this->context->currency->iso_code
)]);
$prices = $this->calculateMPC($id_product, $id_product_attribute);
$this->smarty->assign([
'mpc_old' => $this->context->getCurrentLocale()->formatPrice($prices['old_price'], $this->context->currency->iso_code),
'mpc_new' => $this->context->getCurrentLocale()->formatPrice($prices['new_price'], $this->context->currency->iso_code)
]);
return $this->fetch('module:b2bpayments/views/templates/hook/mpc.tpl');
}
public function calculateMPC(int $id_product, ?int $id_product_attribute): float
public function calculateMPC(int $id_product, ?int $id_product_attribute): array
{
$originalCustomer = Context::getContext()->customer;
$guestContext = Context::getContext();
$guestContext->customer = new Customer();
$specific_price_output = null;
$regularPrice = Product::getPriceStatic($id_product, true, $id_product_attribute, 2, null, false, true, 1, false, null, null, null, $specific_price_output, true, true, $guestContext);
// Price with reduction
$priceWithReduction = Product::getPriceStatic(
$id_product,
true,
$id_product_attribute,
2,
null,
false,
true,
1,
false,
null,
null,
null,
$specific_price_output,
true,
true,
$guestContext
);
// Price without reduction
$priceWithoutReduction = Product::getPriceStatic(
$id_product,
true,
$id_product_attribute,
2,
null,
false,
false, // don't use reduction
1,
false,
null,
null,
null,
$specific_price_output,
true,
true,
$guestContext
);
Context::getContext()->customer = $originalCustomer;
return $regularPrice;
return [
'old_price' => $priceWithoutReduction,
'new_price' => $priceWithReduction,
];
}
public function hookActionEmailSendBefore($params)

View File

@@ -1,6 +1,11 @@
{if $mpc}
{if isset($mpc_new) && $mpc_new > 0}
<div class="b2c-price-block mpcrender">
<span class="b2c-price-label">MPC:</span>
<span class="b2c-price">{$mpc}</span>
{if isset($mpc_old) && $mpc_old > $mpc_new}
<span class="price price--regular">{$mpc_old}</span>
{/if}
<span class="b2c-price">{$mpc_new}</span>
</div>
{/if}