For MPC beside Current price display also Old price if discounted
This commit is contained in:
@@ -394,23 +394,68 @@ class B2BPayments extends PaymentModule implements PrestaShop\PrestaShop\Core\Mo
|
|||||||
|
|
||||||
$id_product_attribute = (int)$embeddedProductAttributes['id_product_attribute'] ?? null;
|
$id_product_attribute = (int)$embeddedProductAttributes['id_product_attribute'] ?? null;
|
||||||
$id_product = (int)$embeddedProductAttributes['id_product'];
|
$id_product = (int)$embeddedProductAttributes['id_product'];
|
||||||
$this->smarty->assign(['mpc' => $this->context->getCurrentLocale()->formatPrice(
|
$prices = $this->calculateMPC($id_product, $id_product_attribute);
|
||||||
$this->calculateMPC($id_product, $id_product_attribute),
|
$this->smarty->assign([
|
||||||
$this->context->currency->iso_code
|
'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');
|
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;
|
$originalCustomer = Context::getContext()->customer;
|
||||||
$guestContext = Context::getContext();
|
$guestContext = Context::getContext();
|
||||||
$guestContext->customer = new Customer();
|
$guestContext->customer = new Customer();
|
||||||
$specific_price_output = null;
|
$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;
|
Context::getContext()->customer = $originalCustomer;
|
||||||
return $regularPrice;
|
|
||||||
|
return [
|
||||||
|
'old_price' => $priceWithoutReduction,
|
||||||
|
'new_price' => $priceWithReduction,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookActionEmailSendBefore($params)
|
public function hookActionEmailSendBefore($params)
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
{if $mpc}
|
{if isset($mpc_new) && $mpc_new > 0}
|
||||||
<div class="b2c-price-block mpcrender">
|
<div class="b2c-price-block mpcrender">
|
||||||
<span class="b2c-price-label">MPC:</span>
|
<span class="b2c-price-label">MPC:</span>
|
||||||
<span class="b2c-price">{$mpc}</span>
|
|
||||||
</div>
|
{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}
|
{/if}
|
||||||
Reference in New Issue
Block a user