News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Product URL field in Delivery Note PDF

Started by raydekker, October 27, 2017, 03:47:39 AM

Previous topic - Next topic

raydekker

Good day,

I'm struggling with the following:
Whenever someone places an order I want to be able to click on the "Print View - Delivery Note" in VM > Orders and I want it to show me the product URL used for for example manufacturers URL.
I found I had to create an override html/com_virtuemart/invoice/invoice_items.php, this works fine, and I've added the required column, that's all good.

The problem seems to be that I can't get the right variable to display the Product URL field.
On my website to test it works with: "echo $this->product->product_url", this displays the URL field perfectly.

However in the delivery note PDF view this doesn't seem to work.
I can get any other field to display, for example the price "$item->product_basePriceWithTax".

I've got a feeling it's got to do with "$this" and "$item" but I've been playing around and the following does not work:
$this->product->product_url
$item->product->product_url
$item->product_url

I hope this makes sense :)
Ah, the original file is components/com_virtuemart/views/invoice/tmpl/invoice_items.php

Thanks!

VM 3.2.4
Joomla 3.7.5

Studio 42

You don't have direct url, you need to create it
$product_link = JURI::root().'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $item->virtuemart_category_id .
'&virtuemart_product_id=' . $item->virtuemart_product_id . '&Itemid=' . $menuItemID;

Should be already in invoice_items.php file

raydekker

Sorry I was away over the weekend.
No this is not what I mean, indeed this ($product_link) is already in there.

What I am after is the URL field in the product.
So not the product URL as in link but the URL field that you can fill out when creating a product (near product alias and MPN...)

Studio 42

I check code, this is set in JOOLAROOT\administrator\components\com_virtuemart\models\orders.php
In function getorder(
$product = $pModel->getProduct($item->virtuemart_product_id);
         
You should dump the var at different point, to check where this are removed, i have not found a code removing this but you have code.
foreach ( $pvar as $k => $v) {
if (!isset($item->$k) and isset($product->$k) and '_' != substr($k, 0, 1)) {
$item->$k = $v;
}

checking if some value exist in the order, to prevent that some order item value get loosed on parsing the values

raydekker

Thank you very much for the quick reply but i don't know what to do yet and what function to write in the invoice_items.php file...
Please see attached image for the URL field i want to show on my deliverynote pdf (at the moment it displays 0 as I'm using the wtong variable: $item?product_url which dorsnt exist).
So i want to create or just call that variable... so that for this product it displays:ray/test.html.

Studio 42

What is the final need ?
You can use a customfield text and write the HTML code(or use a plugin to render it in order only).
Else you have to get the full product in your case.
$productModel = VmModel::getModel('product'); //should be inserted before the $item foreach loop

and in your $item loop ;
$p = $productModel->getProduct($item->virtuemart_product_id);
echo $p->product_url ;


raydekker

The reason i need this:
I want to create a "delivery note" PDF that echoes the product URL field per product. These URLs ate my wholesalers links so i can just click on them and order easily instead of looking up the products manually on the manufacturers website.

So in the URL field i type something like "https://manufacturer.com/product1.php"

As said before, I've created the column already that only shows up in "deliverynote" PDF (invoice_items.php). But now I've got "echo $item...) and this i would like to have changed to the right cide to display that URL field I'm talking about :)

So where exactly do i paste that item loop? Instead of echo...something?

Thanks so much for your help, i feel like we're almost there :)

Best regards, ray

Studio 42


raydekker

No not yet i don't t know what code to write instead of the "echo $item..." i have at the moment...

So where do i insert the code you mentioned before?? And that loop?
And do i still have to "echo something"?

Sorry for my stupid question.
Thanks!!

Studio 42

You write the URL in the product in back-end.
create an override html/com_virtuemart/invoice/invoice_items.php ni your template
Add at the begin of file line after
defined ('_JEXEC') or die
insert
$productModel = VmModel::getModel('product'); //should be inserted before the $item foreach loop
line after
foreach($this->orderDetails['items'] as $item) {
Add
$p = $productModel->getProduct($item->virtuemart_product_id);

And replace
$product_link = JURI::root().'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $item->virtuemart_category_id .
'&virtuemart_product_id=' . $item->virtuemart_product_id . '&Itemid=' . $menuItemID;

with
$product_link = $p->product_url
if you want change original link.
Or echo it at the right place in the foreach loop
echo '<a href="'.$p->product_url.'">more info</a>';


raydekker

Studio 42! You guys are absolute champions!!

I got as far as creating an override and modifying the layout but thanks for the detailed explanation!
It works as a charm, please see screenshot of what my delivery note looks like now :)
Now I also understand what you mean with the "loop", which is the foreach... section. So for each product it loops through these fields.

As you see I've also added a thumbnail of the product and the weight.
This makes it easy for the person getting the products ready. Now I can just email this pdf to that person and done ;) almost :P

I'm so happy with this,
However the only change I would like to make is the product name in another language.
In my case it regards Dutch products, so it can be confusing if someone sees my English product name in here...
Is there a way, code, to display the dutch or other language product name???
So my sites main language is English, I like it that way and the 2nd language is Dutch.
But the product gets printed in English by this line:
<a href="<?php echo $product_link?>"><?php echo $item->order_item_name?></a>

If there was only a way to change echo $item->order_item_name to for example echo $item->order_item_name?lang=nl

Thanks again Studio 42!!

Studio 42

I don't really know if it's possible. Joomla and virtuemart check for current user language.

raydekker

Thanks again! That was the best hint ever ;)
I've just changed my admin panel language ONLY for my user: admin.
This generated the deliverynote PDF product names in Dutch!

Cheers!!