Invoice pdf showing custom field of product type

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278126

-- HikaShop version -- : 32

Hi,
have made a custom field of the product type: product_metri2
With calcbuilder extension I put the m2 of the product in this field (which is calculated by user input of length and width).
This m2 field is showing on the checkout but I can't get it to show on the invoice, using the invoice PDF plugin.
I am using:
$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
echo '<br/>m2: '.$productData->product_metri2;


Other product fields do show on the invoice using the same as above.
Hope you can tell me what I am doing wrong?
Thanks a lot!

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 6 months ago #278140

Hi,

That code is correct if you want to display the value of a custom field of the type "product" for your product.
So the problem is elsewhere.
Can you provide a screenshot of your custom field settings ?

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278191

Here is the screenshot.
Thanks!

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 6 months ago #278205

Hi,

The column name of your custom field is "metri2" and not "product_metri2".
Thus, your code should be:

$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
echo '<br/>m2: '.$productData->metri2;

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278368

Hi Nicolas,
thanks for your answer, but that is not working.
I also have another product field on the invoice like this:
$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
echo '<br/>prezzo a m2: € ' .number_format($productData->product_sort_price,2,',','.');

and this is showing, but when I take out the 'product' bit, it is no longer showing.

Same with the other code for the custom field metri2, it is not showing on the invoice.

Hope you have another idea what might be causing this?

Thanks a lot for your help!

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 6 months ago #278374

Hi,

"product_sort_price" is the column name in the database so it's normal that it works for this field.
If you want your custom code with product_metri2 to work, then you should delete your custom product field and recreate it with the column name "product_metri2".

I don't see any other reason than the column name being wrong in your code.
But it's easy to check... Do a var_dump of $productData and you'll see all the variables available for your product. You'll see that you have "metri2" and not "product_metri2" since that's the column name of your custom field.

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278412

Thanks! You are totally right, sorry for my stupidity, could have checked that (but I am not a programmer and get to solutions by copying ...).

Now I tried with another custom product field (additional information field) and that field is showing correctly on the invoice.
I really do not understand why metri2 is not showing.
It comes from a calculation and is displayed on the checkout without any problems, so the guys/girls from Calcbuilder say it should display on invoice unless there is some restriction in the template ...

Hope there is a solution!

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 6 months ago #278441

Hi,

I don't see why calcbuilder would use a custom product field.
Calcbuilder is, as far as I understand, normally used with custom item fields, not custom product fields. And it doesn't require any code customization to display custom fields on the invoice, whether they are custom item fields or custom product fields, just setting the display settings of the custom field properly.
So I'm thinking that there is a problem with the custom field itself not being of the good type or along these lines.
Now, it could also be that the template has view overrides preventing you from seeing the custom fields. Again, it's easy to check. Switch to the default template of Joomla and see if you get the custom fields. If yes, then it comes from the template view overrides. If no, then it's probably a setting issue.

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278517

Hi,
thanks for your elaborate reply.
Now I have found out that the metri2 column in the Hikashop order-product table remains empty (I tried to show this value in the invoice but nothing is showing). Guess this is where the problem comes from?
The template can't be the problem because I am looking at the invoice pdf (your plugin).
It looks like somehow the metri2 is stored somewhere (because it is shown in checkout) but after confirming the order, it is not passed on to the order-product table. Could this be the case and if so, is it possible to adjust this or does it require a lot of work?
Thanks again!

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278530

Calcbuilder is looking at it again right now, in case I can not get a solution, I will let you know, but for now you can leave it!
Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 6 months ago #278520

Hi,

When you create a custom product field, the column is added in the hikashop_product table not in hikashop_order_product.
If you have a column "metri2" in hikashop_order_product, then it means that either you added a custom item field with that name, or that calcbuilder added it itself.

When you create a custom item field, HikaShop creates two columns:
- the one in hikashop_order_product
- the one in hikashop_cart_product
When you add a product to the cart with a custom item field value, that value is added to the column of the custom item field in hikashop_cart_product by the add to cart process.
Then, when you create the order at the end of the checkout, HikaShop takes the value from there and set together with the rest of the product data necessary in the custom field column in hikashop_order_product.
So if the column is empty in hikashop_order_product, the first thing to check is whether the column is empty in hikashop_cart_product before finsihing the checkout.
If yes, then the problem is at the step when the product is added to the cart.
If no, then the problem is at creation of the order at the end of the checkout.
If the problem is with the add to cart, the next question is how is the product added to the cart ? By Calcbuilder ? How do they do ?
If the problem is at the end of the checkout, then is the metri2 a custom item field or was it added to the database without a custom field ? If it's added to the database without a custom field, then the system will dismiss it as being a potential hack (with the customer injecting data somehow to the product data). If it's added with a custom field, then the settings of that custom field should be check as there must be something preventing it from being taken into account.

The following user(s) said Thank You: Veli

Please Log in or Create an account to join the conversation.

  • Posts: 42
  • Thank you received: 0
  • Hikashop Business
6 years 6 months ago #278763

Thanks a lot for the very detailed explanation.
In the end I have made an 'item' custom field and got that to work (at first it did not work, but CalcBuilder helped me with settings, so in case anybody has a similar problem, just set everything to 'Display: YES' and then it will work (in case of CalcBuilder calculated item fields).
Thanks a lot!!!

Please Log in or Create an account to join the conversation.

Time to create page: 0.076 seconds
Powered by Kunena Forum