Jump to content

Mail template with available_now / available_later labels


ComGrafPL

Recommended Posts

Hello, 

I need to add available_now / available_later labels to order confirm and new order mail templates.

Prestashop 8.2

Saw the guide for 1.7 but is far from 8.2 and doesn't work on 8+.

Thanks. 

Link to comment
Share on other sites

Hi. It's not that simple.

order_conf
You need to add a parameter to the email template that displays the product list and is located in ./mails/_partials/order_conf_product_list.tpl and ./mails/_partials/order_conf_product_list.txt.
Next, you need to override the ./classes/PaymentModule.php file and add the parameter to $product_var_tpl (approx. on line 440)

new_order (ps_emailalerts)
You need to add the parameter in ./modules/ps_emailalerts/ps_emailalerts.php (approx. on line 459)

Link to comment
Share on other sites

Thanks for the detailed breakdown, that's helpful. Just to clarify, when adding the parameter to $product_var_tpl in PaymentModule.php, are we pulling the availability directly from the product object? And for the ps_emailalerts part, should we also be overriding the module to keep things upgrade-safe, or is it safe enough to edit directly in this case?

Link to comment
Share on other sites

3 hours ago, ps8modules said:

Hi. It's not that simple.

order_conf
You need to add a parameter to the email template that displays the product list and is located in ./mails/_partials/order_conf_product_list.tpl and ./mails/_partials/order_conf_product_list.txt.
Next, you need to override the ./classes/PaymentModule.php file and add the parameter to $product_var_tpl (approx. on line 440)

new_order (ps_emailalerts)
You need to add the parameter in ./modules/ps_emailalerts/ps_emailalerts.php (approx. on line 459)

Truly not that simple. I will keep trying. Thanks for the tip.

Link to comment
Share on other sites

Hi.

Availability parameter is not available in PaymentModule.php (Not tested!!!)

obrazek.thumb.png.014b7c44c7bdfbde96869302c255d321.png

updated (added in green box):

obrazek.thumb.png.fa5ddd8db54ba64f9b71611f7353adc9.png

 

                $productAvailableQuantity = StockAvailable::getQuantityAvailableByProduct(
                    (int) $product['id_product'],
                    (int) $product['id_product_attribute'],
                    (int) $order->id_shop
                );

                $productInfo = new Product((int) $product['id_product'], false, $order->id_lang);
                $productAvailableNow = $productInfo->available_now;
                $productAvailableLater = $productInfo->available_later;
                $returnAvailabilityText = '';

                if ($productAvailableQuantity > 0) {
                    if ($productAvailableNow) {
                        $returnAvailabilityText = $productAvailableNow;
                    } else {
                        $returnAvailabilityText = $this->trans('Available now', [], 'Emails.Subject', $order->id_lang);
                    } 
                } else {
                    $availableDate = Product::getAvailableDate((int) $product['id_product'], $product['id_product_attribute']);
                    if ($productAvailableLater) {
                        if ($availableDate) {
                            $returnAvailabilityText = $productAvailableLater. '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $productAvailableLater;
                        }
                    } else {
                        if ($availableDate) {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang). '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang);
                        }
                    }    
                }

                $product_var_tpl = [
                    'id_product' => $product['id_product'],
                    'id_product_attribute' => $product['id_product_attribute'],
                    'reference' => $product['reference'],
                    'name' => $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : ''),
                    'price' => Tools::getContextLocale($this->context)->formatPrice($product_price * $product['quantity'], $this->context->currency->iso_code),
                    'quantity' => $product['quantity'],
                    'availability' => $returnAvailabilityText,
                    'customization' => [],
                ];

 

and in the TPL email template (order_conf_product_list.tpl):

obrazek.png.3754fb110d7df182e27924d8c84a807a.png

 

updated (added in green box):

obrazek.png.08e5f645b799a0074413d7c6b1ad0834.png

	<td style="border:1px solid #D6D4D4;">
		<table class="table">
			<tr>
				<td width="5">&nbsp;</td>
				<td align="right">
					<font size="2" face="Open-sans, sans-serif" color="#555454">
						{$product['quantity']}
						{if isset($product['availability']) && $product['availability']}
						<br>{$product['availability'] nofilter}
						{/if}
					</font>
				</td>
				<td width="5">&nbsp;</td>
			</tr>
		</table>
	</td>

You can do the same with the ps_emailalerts module 😉

Edited by ps8modules (see edit history)
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

  • 2 weeks later...
On 6/12/2025 at 10:55 AM, ps8modules said:

Hi.

Availability parameter is not available in PaymentModule.php (Not tested!!!)

obrazek.thumb.png.014b7c44c7bdfbde96869302c255d321.png

updated (added in green box):

obrazek.thumb.png.fa5ddd8db54ba64f9b71611f7353adc9.png

 

                $productAvailableQuantity = StockAvailable::getQuantityAvailableByProduct(
                    (int) $product['id_product'],
                    (int) $product['id_product_attribute'],
                    (int) $order->id_shop
                );

                $productInfo = new Product((int) $product['id_product'], false, $order->id_lang);
                $productAvailableNow = $productInfo->available_now;
                $productAvailableLater = $productInfo->available_later;
                $returnAvailabilityText = '';

                if ($productAvailableQuantity > 0) {
                    if ($productAvailableNow) {
                        $returnAvailabilityText = $productAvailableNow;
                    } else {
                        $returnAvailabilityText = $this->trans('Available now', [], 'Emails.Subject', $order->id_lang);
                    } 
                } else {
                    $availableDate = Product::getAvailableDate((int) $product['id_product'], $product['id_product_attribute']);
                    if ($productAvailableLater) {
                        if ($availableDate) {
                            $returnAvailabilityText = $productAvailableLater. '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $productAvailableLater;
                        }
                    } else {
                        if ($availableDate) {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang). '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang);
                        }
                    }    
                }

                $product_var_tpl = [
                    'id_product' => $product['id_product'],
                    'id_product_attribute' => $product['id_product_attribute'],
                    'reference' => $product['reference'],
                    'name' => $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : ''),
                    'price' => Tools::getContextLocale($this->context)->formatPrice($product_price * $product['quantity'], $this->context->currency->iso_code),
                    'quantity' => $product['quantity'],
                    'availability' => $returnAvailabilityText,
                    'customization' => [],
                ];

 

and in the TPL email template (order_conf_product_list.tpl):

obrazek.png.3754fb110d7df182e27924d8c84a807a.png

 

updated (added in green box):

obrazek.png.08e5f645b799a0074413d7c6b1ad0834.png

	<td style="border:1px solid #D6D4D4;">
		<table class="table">
			<tr>
				<td width="5">&nbsp;</td>
				<td align="right">
					<font size="2" face="Open-sans, sans-serif" color="#555454">
						{$product['quantity']}
						{if isset($product['availability']) && $product['availability']}
						<br>{$product['availability'] nofilter}
						{/if}
					</font>
				</td>
				<td width="5">&nbsp;</td>
			</tr>
		</table>
	</td>

You can do the same with the ps_emailalerts module 😉

Any chances for step by step how to implement this on 8.1?

Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)
On 6/12/2025 at 10:55 AM, ps8modules said:

Hi.

Availability parameter is not available in PaymentModule.php (Not tested!!!)

obrazek.thumb.png.014b7c44c7bdfbde96869302c255d321.png

updated (added in green box):

obrazek.thumb.png.fa5ddd8db54ba64f9b71611f7353adc9.png

 

                $productAvailableQuantity = StockAvailable::getQuantityAvailableByProduct(
                    (int) $product['id_product'],
                    (int) $product['id_product_attribute'],
                    (int) $order->id_shop
                );

                $productInfo = new Product((int) $product['id_product'], false, $order->id_lang);
                $productAvailableNow = $productInfo->available_now;
                $productAvailableLater = $productInfo->available_later;
                $returnAvailabilityText = '';

                if ($productAvailableQuantity > 0) {
                    if ($productAvailableNow) {
                        $returnAvailabilityText = $productAvailableNow;
                    } else {
                        $returnAvailabilityText = $this->trans('Available now', [], 'Emails.Subject', $order->id_lang);
                    } 
                } else {
                    $availableDate = Product::getAvailableDate((int) $product['id_product'], $product['id_product_attribute']);
                    if ($productAvailableLater) {
                        if ($availableDate) {
                            $returnAvailabilityText = $productAvailableLater. '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $productAvailableLater;
                        }
                    } else {
                        if ($availableDate) {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang). '('.Tools::displayDate($availableDate, null, false).')';
                        } else {
                            $returnAvailabilityText = $this->trans('Available later', [], 'Emails.Subject', $order->id_lang);
                        }
                    }    
                }

                $product_var_tpl = [
                    'id_product' => $product['id_product'],
                    'id_product_attribute' => $product['id_product_attribute'],
                    'reference' => $product['reference'],
                    'name' => $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : ''),
                    'price' => Tools::getContextLocale($this->context)->formatPrice($product_price * $product['quantity'], $this->context->currency->iso_code),
                    'quantity' => $product['quantity'],
                    'availability' => $returnAvailabilityText,
                    'customization' => [],
                ];

 

and in the TPL email template (order_conf_product_list.tpl):

obrazek.png.3754fb110d7df182e27924d8c84a807a.png

 

updated (added in green box):

obrazek.png.08e5f645b799a0074413d7c6b1ad0834.png

	<td style="border:1px solid #D6D4D4;">
		<table class="table">
			<tr>
				<td width="5">&nbsp;</td>
				<td align="right">
					<font size="2" face="Open-sans, sans-serif" color="#555454">
						{$product['quantity']}
						{if isset($product['availability']) && $product['availability']}
						<br>{$product['availability'] nofilter}
						{/if}
					</font>
				</td>
				<td width="5">&nbsp;</td>
			</tr>
		</table>
	</td>

You can do the same with the ps_emailalerts module 😉

Working great on order conf. How to make it in mail alerts where we dont have tpl. only txt / html.

i.e:

{shop_url}

Gratulacje!

Nowe zamówienie w {shop_name} zostało złożone przez klienta: {firstname} {lastname} ({email})

Szczegóły zamówienia

Zamówienie: {order_name} Złożone w {date}

Płatność: {payment}

Indeks	Produkt	Cena jednostkowa	Ilość	Cena końcowa   {items}
Produkty	{total_products}
Rabaty	{total_discounts}
Pakowanie prezentowe	{total_wrapping}
Wysyłka	{total_shipping}
Z podatkiem	{total_tax_paid}
Zapłacono w sumie	{total_paid}

Przewoźnik

Przewoźnik: {carrier}

Płatność: {payment}

Adres dostawy

{delivery_block_html}

Adres do faktury

{invoice_block_html}

Wiadomość klienta:

{message}

[{shop_name}]({shop_url})

Powered by [PrestaShop](https://www.prestashop-project.org/)

 

Edited by ComGrafPL (see edit history)
Link to comment
Share on other sites

Hi.

You need to override the ps_mailalerts module. If you look into it, you will see how it creates a table directly in the function. This module is updated and if you put instructions here, it may be invalid in a week. I would rather prepare some free module that will insert availability.

  • Like 1
Link to comment
Share on other sites

9 hours ago, ps8modules said:

Hi.

You need to override the ps_mailalerts module. If you look into it, you will see how it creates a table directly in the function. This module is updated and if you put instructions here, it may be invalid in a week. I would rather prepare some free module that will insert availability.

thanks. for now i have made a conf. mail copy.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...