Jump to content

How to check if combination selected in the order is not the default


Dissolved Fractals

Recommended Posts

Hi,

I am trying to modify the invoice template that prints out pdf to know if the order has selected anything other than the default combination. If it is not the default combination, it will do some html/css modifications. Otherwise, leave as is. My two questions are:

1. What is the variable to check if the combination selected in the order is the default or not

2. The product title + the combination can be retrieved using { $order_detail.product_name }, how do I retrieve them separately so I can do modifications on the combination part alone?

 

Additional question: Since the only way for me to check the changes is viewing the pdf file, is there a way for me to view it in html format for quick testing?

 

help.png

Edited by Dissolved Fractals
typo (see edit history)
Link to comment
Share on other sites

In order to do this you need to overwrite the file

classes/pdf/HTMLTemplateInvoice.php

And inside public function getContent()

Add this

foreach ($order_details as &$order_detail) {
$product = new Product($order_detail['product_id'], false, Context::getContext()->language->id, Context::getContext()->shop->id);
$has_combinations= $product->hasCombinations();
$id_default_attribute = (int) Product::getDefaultAttribute($order_detail['product_id'], 0, true);
$order_detail['is_default_attribute'] = ($has_combinations && (int)$order_detail['product_attribute_id'] == (int)$id_default_attribute) ? true : false;
 }

Then in 

/pdf/invoice.product-tab.tpl

You can use the variable and or statement

{if $order_detail.is_default_attribute} ........ {/if}

 

  • Like 1
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...