How to display {$product.availability_message} on Prestashop order confirmation?

140 Views Asked by At

I have an issue on PS 1.7; I'm trying to display {$product.availability_message} (shipping delay message) depending on stock on cart and order confirmation. It works well on cart but doesn't display on order-confirmation (order-confirmation-table.tpl). Any idea to make this work ?

Here is my code :

                {if (isset($product.quantity_all_versions) && $product.quantity_all_versions < 0)}
                                            <div>
                                            <span class="red icon--pulsing"></span>
                                            <span class="msg">{$product.availability_message}</span>
                                            </div>

            {else}
                                               <div>
                                               <span class="icon--pulsing"></span> 
                                               <span class="msg">Available</span>
                                               </div>
             {/if}
2

There are 2 best solutions below

0
Filip Albert On BEST ANSWER

Krystian Podemski's answer is absolutely correct. I used the same approach before. However I used different product's properties than you and I was not able to reproduce it using the quantity_all_versions and availability_message properties. I used quantity_available and available_later properties instead.

Anyway you have to create a new file PaymentModule.php in \override\classes\ folder.

There you have to create a new class PaymentModule with the function validateOrder.

use PrestaShop\PrestaShop\Adapter\MailTemplate\MailPartialTemplateRenderer;
use PrestaShop\PrestaShop\Adapter\StockManager;

abstract class PaymentModule extends PaymentModuleCore
{
   public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
   {
      /* copy the content of this function from /classes/PaymentModule.php */
   }
}

Then find the array $product_var_tpl and add the properties you need. In my case:

$product_var_tpl = [
   'id_product' => $product['id_product'],
   'id_product_attribute' => $product['id_product_attribute'],
   'reference' => $product['reference'],
   'name' => $product['name'] . (!empty($product['attributes']) ? ' - ' . $product['attributes'] : ''),
   'price' => Tools::getContextLocale($this->context)->formatPrice($product_price * $product['quantity'], $this->context->currency->iso_code),
   'quantity' => $product['quantity'],
   'quantity_available' => (int)$product['quantity_available'] - (int)$product['quantity'], //This one
   'available_later' => $product['available_later'], //This one
   'customization' => [],
];

Then you can display the available_later message in your /themes/<your theme>/templates/checkout/_partials/order-confirmation-table.tpl like this:

{if $product.product_quantity_in_stock - $product.product_quantity < 0}
   {if !empty($product.available_later)}
      {$product.available_later}
   {/if}
{else}
   {l s='Available' d='Shop.Theme.YourTheme'}
{/if}
1
Krystian Podemski On

You'd need to override PaymentModule::validateOrder.

In this part of the code: https://github.com/PrestaShop/PrestaShop/blob/1.7.8.x/classes/PaymentModule.php#L434

There's an array of products.