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

Accessing Product GTIN in invoice_items.php

Started by Lapskaus, January 29, 2015, 13:59:26 PM

Previous topic - Next topic

Lapskaus

Hey,

i did write a little bit of code to create a barcodeimage from the entered GTIN from each product. I'm saving those on the server and i want to show them in the <table> of the confirmation mail.
Here my problem :
Im only able to access the product_SKU. Is there a way to add the product_gtin to the $item? And how would i differenciate between the admin and shopper mail ? I dont want to send the Barcodes to the clients, just to the admin so his employees have easy access to the the products in his warehouse.

AH

In

administrator/components/com_virtuemart/models/orders.php

Add the gtin to the select statement at around line 200


// Get the order items
$q = 'SELECT virtuemart_order_item_id, product_quantity, order_item_name,
    order_item_sku, i.virtuemart_product_id, product_item_price,
    product_final_price, product_basePriceWithTax, product_discountedPriceWithoutTax, product_priceWithoutTax, product_subtotal_with_tax, product_subtotal_discount, product_tax, product_attribute, order_status, p.product_available_date, p.product_availability,
    intnotes, virtuemart_category_id,p.product_gtin



Then create yourself a new invoice_items view that is loaded only for admin purposes

Copy

components/com_virtuemart/views/invoice/tmpl/invoice_items.php


To

templates/YOURTEMPLATE/html/com_virtuemart/invoice/your_new_invoice_items.php

And to get it to display


<?php echo $item->product_gtin ?>


Regards
A

Joomla 3.10.11
php 8.0

Lapskaus

#2
Thanks so far. Works very well, beside the fact that i still dont know exactly how to split the views so that the shopper gets the one with SKU and the Admin gets the one with GTIN - Images shown. As far as i can tell the mail.html.php is  loading the templates which show up in the mail so the mail i sloading the pricelist which is loading the items. Im pretty sure im able to load different invoice_items_admin.php eg just by changing echo $this->loadTemplate('items'); to echo $this->loadTemplate('items_admin');. Where exactly is the mail sent ? Do i have to create a mail_html_a.php and mail_html_b.php and a to client and b to admin or can i check within the invoice_items where the mail will be sent to ?

[EDIT] Btw i just noticed, i got "send TOS with mail" checked in the config but the mails are sent without the TOS , i only get them added to the printview in the backend.

GJC Web Design

mails send from FE helpers/shopfunctionsf.php
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Lapskaus

I could use a little bit of help, im currently trying to split the mails which are rendered in the
(~line 450 in shopfunctionsf.php)

static public function renderMail ($viewName, $recipient, $vars = array(), $controllerName = NULL, $noVendorMail = FALSE,$useDefault=true) {

if(!class_exists( 'VirtueMartControllerVirtuemart' )) require(VMPATH_SITE.DS.'controllers'.DS.'virtuemart.php');

$controller = new VirtueMartControllerVirtuemart();
// refering to http://forum.virtuemart.net/index.php?topic=96318.msg317277#msg317277
$controller->addViewPath( VMPATH_SITE.DS.'views' );

$view = $controller->getView( $viewName, 'html' );
if(!$controllerName) $controllerName = $viewName;
$controllerClassName = 'VirtueMartController'.ucfirst( $controllerName );
if(!class_exists( $controllerClassName )) require(VMPATH_SITE.DS.'controllers'.DS.$controllerName.'.php');

//refering to http://forum.virtuemart.net/index.php?topic=96318.msg317277#msg317277
$view->addTemplatePath( VMPATH_SITE.'/views/'.$viewName.'/tmpl' );

if(!class_exists('VmTemplate')) require(VMPATH_SITE.DS.'helpers'.DS.'vmtemplate.php');
$template = VmTemplate::loadVmTemplateStyle();
VmTemplate::setTemplate($template);
if($template){
if(is_array($template) and isset($template['template'])){
$view->addTemplatePath( VMPATH_ROOT.DS.'templates'.DS.$template['template'].DS.'html'.DS.'com_virtuemart'.DS.$viewName );
} else {
$view->addTemplatePath( VMPATH_ROOT.DS.'templates'.DS.$template.DS.'html'.DS.'com_virtuemart'.DS.$viewName );
}
}

foreach( $vars as $key => $val ) {
$view->$key = $val;
}

$user = FALSE;
if(isset($vars['orderDetails'])){

//If the vRequest is there, the update is done by the order list view BE and so the checkbox does override the defaults.
//$name = 'orders['.$order['details']['BT']->virtuemart_order_id.'][customer_notified]';
//$customer_notified = vRequest::getVar($name,-1);
if(!$useDefault and isset($vars['newOrderData']['customer_notified']) and $vars['newOrderData']['customer_notified']==1 ){
$user = self::sendVmMail( $view, $recipient, $noVendorMail );
vmdebug('renderMail by overwrite');
} else {
$orderstatusForShopperEmail = VmConfig::get('email_os_s',array('U','C','S','R','X'));
if(!is_array($orderstatusForShopperEmail)) $orderstatusForShopperEmail = array($orderstatusForShopperEmail);
if ( in_array((string) $vars['orderDetails']['details']['BT']->order_status,$orderstatusForShopperEmail) ){
$user = self::sendVmMail( $view, $recipient, $noVendorMail );
vmdebug('renderMail by default');
} else{
$user = -1;
}
}
} else {
$user = self::sendVmMail( $view, $recipient, $noVendorMail );
}

if(isset($view->doVendor) && !$noVendorMail) {
if(isset($vars['orderDetails'])){
$order = $vars['orderDetails'];
$orderstatusForVendorEmail = VmConfig::get('email_os_v',array('U','C','R','X'));
if(!is_array($orderstatusForVendorEmail)) $orderstatusForVendorEmail = array($orderstatusForVendorEmail);
if ( in_array((string)$order['details']['BT']->order_status,$orderstatusForVendorEmail)){
self::sendVmMail( $view, $view->vendorEmail, TRUE );
}else{
$user = -1;
}
} else {
self::sendVmMail( $view, $view->vendorEmail, TRUE );
}

}

return $user;

}


To be exact i dont know where the mail_html.php is called/referred to, to be used as mail layout and where i have to edit in the changed version of my invoice_items.php depending on the recipient. Btw: Do i simply have to check if the $recipient is = vendor mail ?

GJC Web Design

just try it... what's the worst that could happen?

assume template called is this->  $view->addTemplatePath( VMPATH_SITE.'/views/'.$viewName.'/tmpl' );
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

Lapskaus, you dont need to touch the function renderMail,

You need ONLY a layout override!
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sirius

#7
Hello all,

I'm actually with J3.4.1 and VM3.0.7
so if those fields are implemented by default on products in admin (as I can see both gtin and mpn) so why can't we call them in the products templates like Hutson told it at the end of his post, or can we already, under 3.0.8 or next one ?

I do not see any sql call for this in the product.php so, I suppose it's not ok at this time

We really need:
<?php echo $item->product_gtin ?>
<?php echo $item->product_mpn ?>


Could you please explain the state of this part Milbo
Thanks
J3.10.12 | PHP 7.4.33 + APC + memcached + Opcode
VM Prod : 3.8.6 | VM Test : 4.0.12.10777