diff --git a/b2bpayments.php b/b2bpayments.php index 8279f8d..8537a70 100644 --- a/b2bpayments.php +++ b/b2bpayments.php @@ -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) diff --git a/views/templates/hook/mpc.tpl b/views/templates/hook/mpc.tpl index 42229bd..43d7676 100644 --- a/views/templates/hook/mpc.tpl +++ b/views/templates/hook/mpc.tpl @@ -1,6 +1,11 @@ -{if $mpc} -
-MPC: -{$mpc} -
+{if isset($mpc_new) && $mpc_new > 0} +
+ MPC: + + {if isset($mpc_old) && $mpc_old > $mpc_new} + {$mpc_old} + {/if} + + {$mpc_new} +
{/if} \ No newline at end of file